Description Usage Arguments Value Examples
Spatial join; join information of a shape to the points that it contains
1 | spatial.join.locs(points, shapes, targetcolumn, column.names)
|
points |
a SpatialPointsDataFrame. Projection cannot be unknown. |
shapes |
a SpatialPolygonsDataFrame. Projection cannot be unknown. |
targetcolumn |
a character string vector with the names of the columns in shapes which need to be joined to points. |
column.names |
a character string vector with the column names that will be given to the joined columns added to points. |
It returns the points spdf with the new columns joined to the data.frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | pts = cbind(1.5:5.5, 1.5:5.5)
dimnames(pts)[[1]] = letters[1:5]
df = data.frame(a = 1:5)
row.names(df) = letters[5:1]
points <- SpatialPointsDataFrame(pts, df, match.ID = TRUE)
grd <- GridTopology(c(1,1), c(1,1), c(10,10))
polys <- as(grd, "SpatialPolygons")
centroids <- coordinates(polys)
x <- centroids[,1]
y <- centroids[,2]
z <- 1.4 + 0.1*x + 0.2*y + 0.002*x*x
pols <- SpatialPolygonsDataFrame(polys,
data=data.frame(x=x, y=y, z=z, row.names=row.names(polys)))
result <- spatial.join.locs(points, pols)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.