Learn R Programming

ggOceanMaps (version 1.1)

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 = NULL,
  proj.limits = "+init=epsg:4326",
  simplify = FALSE,
  tol = 60,
  return.boundary = FALSE
)

Arguments

x

Original shape file to be clipped. Required. Must contain proj4string 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 proj4string information. See details.

proj.limits

The proj4string projection attributes for limits. 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

Value

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

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: raster_bathymetry(), vector_bathymetry()