Create Spatial Polygons with projection metadata from a 'Spatial Extent'.
1 2 3 4 5 6 7
any object with a
arguments for methods
return a separate object for every input sub-object (not yet implemented)
optional name for output attribute name
a projection string
This function is to replace a common pattern in the 'sp'-'raster' family which is
Extent, a bounding box in xmin,xmax,ymin,ymax but without projection metadata
coerce the Extent to
restore the 'CRS', the "coordinate reference system", i.e. projection metadata
elevate the object to be a
In short, this pattern exists because there is no projection metadata stored
with either sp”s
bbox or 'raster”s
||function to produce a fully fledged Spatial object extent|
Please note that an extent converted to polygons consists of only four unique coordinates, and so this is not necessarily suited for projection transformations.
Potentially Unwelcome Rant
Consider also that this is a common limitation, outside of R, where the "OGC standard" for serialized geometry in "well known text" (WKT) or "well known binary" (WKB) do not include projection metadata. Some GIS systems do provide serialized geometries that include this crucial metadata, and may we encourage this to become more common. Not only is "longitude / latitude" coordinates not always suitable, they are actually meaningless without knowing the _datum_ (the ellipsoid radii and orientation, often WGS84) and the units in use (usually 'degrees', but sometimes 'radians')
This pattern is displayed in the example code for
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
library(raster) data(lux) exlux <- spex(lux) plot(lux) plot(exlux, add = TRUE) ## put an extent and a CRS together spex(extent(0, 1, 0, 1), crs = "+proj=laea +ellps=WGS84") ## Not run: ## library(rgdal) ## p4 <- "+proj=laea +ellps=WGS84" ## plot(spTransform(lux, p4)) ## warning, this is just 4 coordinates ## plot(spTransform(exlux, p4), add = TRUE) ## End(Not run)
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.