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

clip_shapefile(
  x,
  limits = NULL,
  proj4.limits = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0",
  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.

proj4.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 gSimplify function.

tol

Numerical tolerance value to be used for simplification. See gSimplify.

return.boundary

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

Details

The function uses the 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.