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

bbox2SP

Converts a bounding box into a SpatialPolygons object.


Description

Converts a bounding box into a SpatialPolygons object.

Usage

bbox2SP(n,s,w,e,bbox=NA,proj4string=CRS("+init=epsg:4326"))

Arguments

n

the top north latitude

s

the bottom south latitude

w

the most western longitude

e

the most eastern longitude

bbox

a bounding box 2 x 2 matrix as produced by bbox

proj4string

a coordinate reference system as defined in CRS

Details

This function converts a set of coordinates limiting a bounding box into a SpatialPolygons. It can be used for instance to clip a subset of a larger spatial object (e.g. using gIntersection)

Value

An object of SpatialPolygons class.

Examples

library(sp)
run <- FALSE
if (require(rgdal, quietly=TRUE)) run <- TRUE
if (run) {
cities <- readOGR(dsn=system.file("vectors", package = "rgdal")[1], layer="cities")
n<-75
s<-30
w<--40
e<-32
myPoly<-bbox2SP(n,s,e,w)
}
if (run) {
plot(cities)
plot(myPoly,border="red",add=TRUE)
}
if (run) {
bb<-bbox(cities)
myPoly<-bbox2SP(bbox=bb,proj4string=CRS(proj4string(cities)))
plot(myPoly,add=TRUE,border="blue")
}

rgeos

Interface to Geometry Engine - Open Source ('GEOS')

v0.5-5
GPL (>= 2)
Authors
Roger Bivand [cre, aut] (<https://orcid.org/0000-0003-2392-6140>), Colin Rundel [aut], Edzer Pebesma [ctb], Rainer Stuetz [ctb], Karl Ove Hufthammer [ctb], Patrick Giraudoux [ctb], Martin Davis [cph, ctb], Sandro Santilli [cph, ctb]
Initial release
2020-09-01

We don't support your browser anymore

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