bbox2sf | R Documentation |
Convert a bounding box into a sf object.
bbox2sf(n,s,w,e,bbox=NA,crs=4326)
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 e.g. by |
crs |
the ID number of a coordinate reference system as defined in the EPSG system https://epsg.io/ (default 4326, WGS84) |
This function converts a set of coordinates limiting a bounding box into a an object of class "sfc_POLYGON" (see st_sfc
). It can be used for instance to clip a subset of a larger spatial object (e.g. using st_intersection
)
A simple feature geometry of class "sfc_POLYGON" with a coordinate reference system, see st_sfc
.
n<-79
s<--54
w<--166
e<-178
myPoly1<-bbox2sf(n,s,e,w)
plot(myPoly1)
# bbox as a 2 x 2 matrix as produced by sp:bbox
mybbox<-matrix(c(w,e,s,n),nrow=2,byrow=TRUE)
myPoly2<-bbox2sf(bbox=mybbox)
plot(myPoly2,border="red")
# bbox as produced by sf:st_bbox
if (require(sf)) {
myPoly3<-bbox2sf(bbox=st_bbox(myPoly2))
plot(myPoly3,border="blue")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.