These functions perform various spatial operations on two shapefiles, including determining which geometries fall within, outside, touch, cross, overlap, or intersect another geometry. They also include functions for geometric operations such as intersection, difference, and union.
Usage
shapefile_within(shp1, shp2)
shapefile_outside(shp1, shp2)
shapefile_overlaps(shp1, shp2)
shapefile_touches(shp1, shp2)
shapefile_crosses(shp1, shp2)
shapefile_intersection(shp1, shp2)
shapefile_difference(shp1, shp2)
shapefile_union(shp1, shp2)Details
All functions ensure that the coordinate reference systems (CRS) of both shapefiles are the same before performing operations. If the CRSs are different, shp2 will be transformed to match the CRS of shp1.
shapefile_within(): Filters features inshp1that are fully withinshp2.shapefile_outside(): Filters features inshp1that are outside or do not overlapshp2.shapefile_overlaps(): Filters features inshp1that overlap withshp2.shapefile_touches(): Filters features inshp1that touch the boundary ofshp2.shapefile_crosses(): Filters features inshp1that cross throughshp2.shapefile_intersection(): Computes the geometric intersection ofshp1andshp2.shapefile_difference(): Computes the geometric difference ofshp1minusshp2.shapefile_union(): Computes the geometric union ofshp1andshp2.
Examples
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
shp1 <- shapefile_input(paste0(image_pliman(), "/shp1.rds"))
shp2 <- shapefile_input(paste0(image_pliman(), "/shp2.rds"))
shapefile_view(shp1) + shapefile_view(shp1)
# Apply operations
shapefile_within(shp1, shp2)
shapefile_outside(shp1, shp2)
shapefile_overlaps(shp1, shp2)
shapefile_touches(shp1, shp2)
shapefile_crosses(shp1, shp2)
shapefile_intersection(shp1, shp2)
shapefile_difference(shp1, shp2)
shapefile_union(shp1, shp2)
}
