spex {spex}R Documentation

Polygon extent

Description

Create Spatial Polygons with projection metadata from a 'Spatial Extent'.

Usage

spex(x, crs, byid = FALSE, .id, ..., clipboard = FALSE)

## Default S3 method:
spex(x, crs = NULL, byid = FALSE, .id, ..., clipboard = FALSE)

## S3 method for class 'sf'
spex(x, crs, byid = FALSE, .id, ..., clipboard = FALSE)

## S3 method for class 'sfc'
spex(x, crs, byid = FALSE, .id, ..., clipboard = FALSE)

Arguments

x

any object with a Extent-class

crs

a projection string

byid

return a separate object for every input sub-object (not yet implemented)

.id

optional name for output attribute name

...

arguments for methods

clipboard

WIP this special-case allows x to be the result of the leafem clipboard copy process

Details

Called with no arguments will return the extent of the current 'par("usr")' setting.

Called with a matrix, list, or data frame it will create an extent from a two columned thing.

Called with clipboard = TRUE and x will be treated as the JSON-ic output of the clipboard copy from leafem (WIP). If x is missing, it will be attempted to be read from the clipboard. Clipboard read cannot work on RStudio Server, so we allow the text value to be passed in. I.e. spex(clipboard = TRUE) will read from the clipboard, spex(tx, clipboard = TRUE) will read from tx with value like '{"_southWest":{"lat":-1.307259612275665,"lng":23.411865234375},"_north...}"'.

This function is to replace a common pattern in spatial packages which is

In short, this pattern exists because there is no projection metadata stored with either sp's bbox or raster's Extent-class.

Value

'SpatialPolygonsDataFrame'

Warning

Please note that an extent converted to polygons consists of only four unique coordinates, and so this is not necessarily suited for projection transformations.

See Also

This pattern is displayed in the example code for cover.

Examples

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")

[Package spex version 0.7.1 Index]