gclip: Crops spatial object x to the bounding box of spatial object...

Description Usage Arguments Examples

View source: R/geo-functions.R

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: http://gis.stackexchange.com/questions/46954/clip-spatial-object-to-bounding-box-in-r/.

Usage

1
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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(cents)
cb <- rgeos::gBuffer(cents[8, ], width = 0.012, byid = TRUE)
plot(cents)
plot(cb, add = TRUE)
clipped <- gclip(cents, 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)

stplanr documentation built on Oct. 20, 2018, 5:05 p.m.