ST_GeomFromBinary takes a binary column and returns a geometry column. The input binary column must contain the
well-known binary (WKB)
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.
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_PointFromBinary, ST_LineFromBinary, ST_MPointFromBinary, or ST_PolyFromBinary).
Function | Syntax |
---|---|
Python | geom |
SQL | ST |
Scala | geom |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for geom_from_binary.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1
Examples
from geoanalytics_fabric.sql import functions as ST
line_binary= bytearray(b'\x01\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00D@\x00\x00\x00\x00\x00\x00D@')
polygon_binary = bytearray(b'\x01\x03\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x00D@\x00\x00\x00\x00\x00\x00D@\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x00D@\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x00>@\x00\x00\x00\x00\x00\x00$@')
df = spark.createDataFrame([(polygon_binary,), (line_binary,)], ["wkb"])
df.select(ST.geom_from_binary("wkb", sr=4326).alias("geom_from_binary")).show(truncate=False)
+-----------------------------------------------------+
|geom_from_binary |
+-----------------------------------------------------+
|{"rings":[[[30,10],[10,20],[20,40],[40,40],[30,10]]]}|
|{"paths":[[[30,10],[10,30],[40,40]]]} |
+-----------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |