Skip to content
Prev 21918 / 29559 Next

Generate a vector of names of intersecting polgons

Steven, I believe you can use something like the below

library(raster)
# example data (p, d)
p <- shapefile(system.file("external/lux.shp", package="raster"))
r <- raster(p)
values(r) <- 1:ncell(r)
d <- as(r, 'SpatialPolygonsDataFrame')

# approach 1
x <- intersect(p, d)

# approach 2
y <- union(p,d)
y <- y[!is.na(y$ID_1), ])

The approach to take depends on the case (does B fall entirely within A?)
On Mon, Oct 27, 2014 at 5:43 PM, Steven Ranney <steven.ranney at gmail.com> wrote: