Convert an object to an extent

Given an sf or sfc object create a list that represents the extent of the object. The result of this function can be parsed directly into json using jsonify::to_json(x, unbox = TRUE) or included into a list as the extent component that will be eventually converted into json using the above function.

Usage

as_extent(x, crs = sf::st_crs(x), call = rlang::caller_env())

Arguments

x

an sf or sfc object

crs

the CRS of the object. Must be parsable by sf::st_crs()

call

The execution environment of a currently running function, e.g. call = caller_env(). The corresponding function call is retrieved and mentioned in error messages as the source of the error.

You only need to supply call when throwing a condition from a helper function which wouldn't be relevant to mention in the message.

Can also be NULL or a defused function call to respectively not display any call or hard-code a code to display.

For more information about error calls, see Including function calls in error messages.

Value

An extent json object. Use jsonify::to_json(x, unbox = TRUE) to convert to json.

Examples

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
as_extent(nc)
#> $xmin
#> [1] -84.32385
#> 
#> $ymin
#> [1] 33.88199
#> 
#> $xmax
#> [1] -75.45698
#> 
#> $ymax
#> [1] 36.58965
#> 
#> $spatialReference
#> $spatialReference$wkid
#> [1] 4267
#> 
#> 

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close