Learn R Programming

tmaptools (version 1.0)

crop_shape: Crop shape object

Description

Crop a shape object (from class Spatial-class, Raster, or sf). A shape file x is cropped, either by the bounding box of another shape y, or by y itself if it is a SpatialPolygons object and polygon=TRUE.

Usage

crop_shape(x, y, polygon = FALSE, ...)

Arguments

x
shape object, i.e. an object from class Spatial-class, Raster, or sf.
y
bounding box (2 by 2 matrix), an extent, or a shape object from which the bounding box is extracted (unless polygon is TRUE and x is a SpatialPolygons object).
polygon
should x be cropped by the polygon defined by y. If FALSE (default), x is cropped by the bounding box of x. Polygon cropping only works when x is a spatial object and y is a SpatialPolygons object.
...
arguments passed on to crop

Value

cropped shape, in the same class as x

See Also

bb

Examples

Run this code
## Not run: 
# if (require(tmap)) {
#     data(Europe, land, metro)
# 
#     land_europe <- crop_shape(land, Europe)
# 
#     qtm(land_europe, raster="trees", style="natural")
# 
#     metro_europe <- crop_shape(metro, Europe, polygon = TRUE)
# 
#     qtm(Europe) +
#     tm_shape(metro_europe) +
#     	tm_bubbles("pop2010", col="red", title.size="European cities") +
#     	tm_legend(frame=TRUE)
# }
# ## End(Not run)

Run the code above in your browser using DataLab