Clips an area from a larger shapefile provided in sf or sp formats.
Usage
clip_shapefile(
x,
limits,
proj.limits = 4326,
simplify = FALSE,
tol = 60,
return.boundary = FALSE,
extra.validate = FALSE
)Arguments
- x
Original shapefile to be clipped as a an sf or
sppolygons object. Required. Must containCRSinformation.- limits
The constraining area used to clip
x. Required. Either a numeric vector of length 4 or a spatial object from the sf or sp packages. The first element of the numeric vector defines the minimum longitude, second element the maximum longitude, third element the minimum latitude and fourth element the maximum latitude of the bounding box. If a spatial object, it must containCRSinformation. See details.- proj.limits
The
CRSprojection attributes forlimits. Hence format accepted byst_crswill suffice but integers are the easiest. Defaults to decimal degrees.- simplify
Should the
xgeometry be simplified before clipping? Useful to make the function faster for large shape files. Usesst_simplifyfunction.- tol
Numerical tolerance value to be used for simplification. See
?sf::st_simplfy.- return.boundary
Logical. If
TRUEreturns the clip boundary together with the shapefile.- extra.validate
Logical indicating whether
xshould be run through extra validation. Slows down the function but is necessary in some cases involving anti-meridian.
Value
Clipped spatial object. If return.boundary = TRUE, a list containing the shapefile together with the clip boundary.
Details
The function uses the st_intersection function to clip smaller polygons from larger ones. The clip area is constrained by either a numeric vector or a spatial object in the limits argument. Defining limits by a sf object gives greater freedom for the clip area as the area does not have to be rectangular.
See also
Other create shapefiles:
geonorge_bathymetry(),
raster_bathymetry(),
vector_bathymetry()