Clips an area from a larger shape file (SpatialPolygons).
clip_shapefile(
x,
limits,
proj.limits = convert_crs(4326),
simplify = FALSE,
tol = 60,
return.boundary = FALSE
)
Clipped SpatialPolygons
object. If return.boundary = TRUE
, a list containing the shapefile together with the clip boundary.
Original shape file to be clipped as a an sp or sf polygons object. Required. Must contain CRS
information.
The constraining area used to clip x
. Required. Either a numeric vector of length 4 or a SpatialPolygons object. 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. The SpatialPolygons object must contain CRS
information. See details.
The CRS
projection attributes for limits
as character string (will be passed to CRS
). Use the PROJ6 format. Defaults to decimal degrees (see Usage).
Should the x
geometry be simplified before clipping? Useful to make the function faster for large shape files. Uses rgeos::gSimplify
function.
Numerical tolerance value to be used for simplification. See ?rgeos::gSimplify
.
logical. If TRUE
returns the clip boundary together with the shapefile
Mikko Vihtakari with a solution from Simon O'Hanlon, Roger Bivand/SO community
The function uses the rgeos::gIntersection
function to clip smaller SpatialPolygons from larger ones. The clip area is constrained by either a numeric vector or SpatialPolygons object in the limits
argument. One of these arguments must be given. Defining limits
by a SpatialPolygons object gives greater freedom for the clip area as the area does not have to be rectangular.
Other create shapefiles:
geonorge_bathymetry()
,
raster_bathymetry()
,
vector_bathymetry()