Mask a spatial layer by a polygon

drt_mask(layer, aoi)

Arguments

layer

spatial object to crop by the polygon.

aoi

spatial object, polygon to mask to.

Value

A masked sf.

Examples

# Example data aoi <- sf::st_read(system.file("example.gpkg", package="drtplanr"), layer = "aoi")
#> Reading layer `aoi' from data source `/home/runner/work/_temp/Library/drtplanr/example.gpkg' using driver `GPKG' #> Simple feature collection with 1 feature and 6 fields #> geometry type: POLYGON #> dimension: XY #> bbox: xmin: 7.4947 ymin: 47.0366 xmax: 7.5359 ymax: 47.0599 #> geographic CRS: WGS 84
pop <- sf::st_read(system.file("example.gpkg", package="drtplanr"), layer = "pop")
#> Reading layer `pop' from data source `/home/runner/work/_temp/Library/drtplanr/example.gpkg' using driver `GPKG' #> Simple feature collection with 150 features and 4 fields #> geometry type: POINT #> dimension: XY #> bbox: xmin: 7.496534 ymin: 47.04012 xmax: 7.524167 ymax: 47.0581 #> geographic CRS: WGS 84
drt_mask(pop, aoi)
#> Simple feature collection with 150 features and 4 fields #> geometry type: POINT #> dimension: XY #> bbox: xmin: 7.496534 ymin: 47.04012 xmax: 7.524167 ymax: 47.0581 #> geographic CRS: WGS 84 #> First 10 features: #> id statent statpop n geom #> 1 113236 0 6 6 POINT (7.496534 47.04822) #> 2 113489 3 18 21 POINT (7.497848 47.04642) #> 3 113491 0 27 27 POINT (7.49785 47.04821) #> 4 113748 3 41 44 POINT (7.499165 47.04731) #> 5 113749 0 62 62 POINT (7.499166 47.04821) #> 6 113750 3 41 44 POINT (7.499167 47.04911) #> 7 113751 3 39 42 POINT (7.499168 47.05001) #> 8 113752 3 11 14 POINT (7.499169 47.05091) #> 9 113754 0 30 30 POINT (7.499172 47.05361) #> 10 113755 0 3 3 POINT (7.499173 47.05451)