ST_GeomFromGeoJSON takes a string column and returns a geometry column.
The input string column must contain the GeoJSON representation of
geometries. You can optionally specify a spatial reference for the result geometry column.
The sr
parameter value must be a valid SRID or WKT string.
Any spatial reference ID defined in the input GeoJSON 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_PointFromGeoJSON, ST_LineFromGeoJSON, ST_MPointFromGeoJSON, or ST_PolyFromGeoJSON).
Function | Syntax |
---|---|
Python | geom |
SQL | ST |
Scala | geom |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for geom_from_geojson.
Examples
from geoanalytics_fabric.sql import functions as ST
point_geojson = '{"type": "Point","coordinates": [-7472618.18,5189924.02]}'
line_geojson = '{"type": "LineString","coordinates": [[-7489594.84,5178779.67],[-7474281.07,5176558.51],[-7465977.43,5179778.83]]}'
df = spark.createDataFrame([(point_geojson,),(line_geojson,)],["geojson"])
df.select(ST.geom_from_geojson("geojson", sr=8857).alias("geom_from_geojson")).show(truncate=False)
+----------------------------------------------------------------------------------------+
|geom_from_geojson |
+----------------------------------------------------------------------------------------+
|{"x":-7472618.18,"y":5189924.02} |
|{"paths":[[[-7489594.84,5178779.67],[-7474281.07,5176558.51],[-7465977.43,5179778.83]]]}|
+----------------------------------------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |