shapefile_operations | R Documentation |
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.
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)
shp1 |
An |
shp2 |
An |
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 in shp1
that are fully within shp2
.
shapefile_outside()
: Filters features in shp1
that are outside or do not overlap shp2
.
shapefile_overlaps()
: Filters features in shp1
that overlap with shp2
.
shapefile_touches()
: Filters features in shp1
that touch the boundary of shp2
.
shapefile_crosses()
: Filters features in shp1
that cross through shp2
.
shapefile_intersection()
: Computes the geometric intersection of shp1
and shp2
.
shapefile_difference()
: Computes the geometric difference of shp1
minus shp2
.
shapefile_union()
: Computes the geometric union of shp1
and shp2
.
A filtered sf
object or the result of the geometric operation.
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.