Learn R Programming

ggOceanMaps (version 1.3.4)

clip_shapefile: Clip a shapefile (SpatialPolygon) using a bounding area

Description

Clips an area from a larger shape file (SpatialPolygons).

Usage

clip_shapefile(
  x,
  limits,
  proj.limits = convert_crs(4326),
  simplify = FALSE,
  tol = 60,
  return.boundary = FALSE
)

Value

Clipped SpatialPolygons object. If return.boundary = TRUE, a list containing the shapefile together with the clip boundary.

Arguments

x

Original shape file to be clipped as a an sp or sf polygons object. Required. Must contain CRS information.

limits

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.

proj.limits

The CRS projection attributes for limits as character string (will be passed to CRS). Use the PROJ6 format. Defaults to decimal degrees (see Usage).

simplify

Should the x geometry be simplified before clipping? Useful to make the function faster for large shape files. Uses rgeos::gSimplify function.

tol

Numerical tolerance value to be used for simplification. See ?rgeos::gSimplify.

return.boundary

logical. If TRUE returns the clip boundary together with the shapefile

Author

Mikko Vihtakari with a solution from Simon O'Hanlon, Roger Bivand/SO community

Details

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.

See Also

Other create shapefiles: geonorge_bathymetry(), raster_bathymetry(), vector_bathymetry()