Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gclip

Crops spatial object x to the bounding box of spatial object (or matrix) b


Description

This function is a cross between the spatial subsetting funtions such as sp::over(), rgeos::gIntersects() etc, and the cropping functions of raster::crop() and rgeos::gIntersection(). The output is the subset of spatial object a with an outline described by a square bounding box. The utility of such a function is illustrated in the following question: https://gis.stackexchange.com/questions/46954/clip-spatial-object-to-bounding-box-in-r/.

Usage

gclip(shp, bb)

Arguments

shp

The spatial object a to be cropped

bb

the bounding box or spatial object that will be used to crop shp

See Also

Examples

## Not run: 
cb <- sf::st_buffer(cents_sf[8, ], dist = 0.012)
plot(cents_sf$geometry)
plot(cb, add = TRUE)
clipped <- gclip(cents_sf, cb)
plot(clipped, add = TRUE)
clipped$avslope # gclip also returns the data attribute
points(clipped)
points(cents[cb, ], col = "red") # note difference
gclip(cents_sf, cb)

## End(Not run)

stplanr

Sustainable Transport Planning

v0.8.2
MIT + file LICENSE
Authors
Robin Lovelace [aut, cre] (<https://orcid.org/0000-0001-5679-6536>), Richard Ellison [aut], Malcolm Morgan [aut] (<https://orcid.org/0000-0002-9488-9183>), Barry Rowlingson [ctb], Nick Bearman [ctb], Nikolai Berkoff [ctb], Scott Chamberlain [rev] (Scott reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/10), Mark Padgham [ctb], Andrea Gilardi [ctb] (<https://orcid.org/0000-0002-9424-7439>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.