Skip to contents

Generate a rectangular polygon from extent

Usage

ext2poly(extent = NULL, output_class = c("sf", "terra"), crs = "EPSG:4326")

Arguments

extent

input extent. A numeric vector with xmin/xmax/ymin/ymax, sf::st_bbox or terra::ext outputs.

output_class

character(1). Class of the output polygon. One of "sf" or "terra"

crs

character(1). Coordinate reference system definition.

Value

sf or SpatVector object of a rectangular polygon.

Author

Insang Song

Examples

library(sf)
library(terra)
numext1 <- c(-100, -70, 30, 40)
names(numext1) <- c("xmin", "xmax", "ymin", "ymax")
ext2poly(numext1, "sf")
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -100 ymin: 30 xmax: -70 ymax: 40
#> Geodetic CRS:  WGS 84
#>                                x
#> 1 POLYGON ((-100 30, -70 30, ...
ext2poly(numext1, "terra")
#>  class       : SpatVector 
#>  geometry    : polygons 
#>  dimensions  : 1, 0  (geometries, attributes)
#>  extent      : -100, -70, 30, 40  (xmin, xmax, ymin, ymax)
#>  coord. ref. : lon/lat WGS 84 (EPSG:4326)