ST_GeomFromEsriJSON

ST_GeomFromEsriJSON takes a string column and returns a geometry column. The input string column must contain the Esri JSON representation of geometries. You can optionally specify a spatial reference ID for the result geometry column. The sr parameter value must be a valid SRID or WKT string. Any spatial reference defined in the input Esri JSON strings will not be used.

This function should only be used when you don't know the geometry type represented by the input column or when the input column contains more than one geometry type. In other cases, use the function specific to the geometry type of your input data (i.e. ST_PointFromEsriJSON, ST_LineFromEsriJSON, ST_MPointFromEsriJSON, or ST_PolyFromEsriJSON).

FunctionSyntax
Pythongeom_from_esri_json(json_str,sr=None)
SQLST_GeomFromEsriJson(json_str,sr)
ScalageomFromEsriJson(json,sr)

For more details, go to the GeoAnalytics Engine API reference for geom_from_esri_json.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
from geoanalytics.sql import functions as ST

point_esri_json = '{"x": -10840835.32, "y": 3763957.91}'
line_esri_json = '{"paths": [[[-7489594.84, 5178779.67],[-7474281.07,5176558.51],[-7465977.43,5179778.83]]]}'

df = spark.createDataFrame([(point_esri_json,),(line_esri_json,)],["esri_json"])

df.select(ST.geom_from_esri_json("esri_json", sr=8857).alias("geom_from_esri_json")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+----------------------------------------------------------------------------------------+
|geom_from_esri_json                                                                     |
+----------------------------------------------------------------------------------------+
|{"x":-1.084083532e7,"y":3763957.91}                                                     |
|{"paths":[[[-7489594.84,5178779.67],[-7474281.07,5176558.51],[-7465977.43,5179778.83]]]}|
+----------------------------------------------------------------------------------------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

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