as_esri_geometry {arcgisutils} | R Documentation |
Create Esri geometry objects
Description
These functions convert R objects to Esri json representations. There are three types of representations. These are, from smallest to largest, a geometry object, a feature and a feature set.
Usage
as_esri_geometry(x, crs = 4326, ..., call = rlang::caller_env())
as_esri_features(x, ..., call = rlang::caller_env())
as_esri_featureset(x, ...)
as_geometry(x, crs, ...)
as_features(x, ..., call = rlang::caller_env())
as_featureset(x, ...)
Arguments
x |
an sf or sfc class object |
crs |
the coordinate reference system of the FeatureSet. Must be interpretable by |
... |
additional arguments passed on to methods. |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be For more information about error calls, see Including function calls in error messages. |
Details
The _esri_
infix indicates that the input object will be converted directly into
the Esri JSON representation. If there is no _esri_
infix, the object will be
converted into the appropriate list structure requiring only
jsonify::to_json(x, unbox = TRUE)
to convert to Esri JSON.
-
as_esri_geometry()
converts ansfg
object to a geometry object -
as_esri_features()
converts ansfc
orsf
object to a list of features -
as_esri_featureset()
converts ansf
,sfc
, ordata.frame
to a feature set object
Geometry object contain the coordinates for a geometry. Features are geometries that
have associated attributes with them. This would be similar to a row in an sf object.
FeatureSets are a list of features that have additional metadata fields such as
spatialReference
, geomtryType
, and fields
. FeatureSets correspond to an
sf
object.
Geometry objects are defined for 5 different types. These are:
Point:
esriGeometryPoint
Multipoint:
esriGeometryMultipoint
Polyline:
esriGeometryPolyline
note that polyline encompasses both LINESTRING and MULTILINESTRING
Polygon:
esriGeometryPolygon
note that polygon encompasses both POLYGON and MULTIPOLYGON
Envelope:
esriGeometryEnvelope
envelopes correspond with bounding boxes but can have a Z dimension
Field handling:
Vectors that inherit
Date
orPOSIXt
are converted into milliseconds since the Unix epoch in UTC timezone usingdate_to_ms()
.-
factor
s are converted to character vectors usingas.character()
to match the behavior ininfer_esri_type()
which defines type mapping for Esri field types and R vector classes.
Value
a json Esri geometry object
Examples
library(sf)
as_esri_geometry(st_point(c(0, 1, 3, 4)))
as_esri_geometry(st_multipoint(x = matrix(runif(4), ncol = 2)))
as_esri_geometry(st_linestring(x = matrix(runif(2), ncol = 2)))
as_esri_geometry(st_linestring(x = matrix(runif(2), ncol = 2)))
# polygon
m <- matrix(
c(0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 2, 2, 1, 2, 3, 1, 3, 2, 0, 0, 0),
ncol = 3,
byrow = TRUE
)
as_esri_geometry(st_polygon(list(m)))