ST_GeomFromBinary

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).

FunctionSyntax
Pythongeom_from_binary(wkb, sr=None)
SQLST_GeomFromBinary(wkb, sr)
ScalageomFromBinary(wkb, sr)

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

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
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)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+-----------------------------------------------------+
|geom_from_binary                                     |
+-----------------------------------------------------+
|{"rings":[[[30,10],[10,20],[20,40],[40,40],[30,10]]]}|
|{"paths":[[[30,10],[10,30],[40,40]]]}                |
+-----------------------------------------------------+

Version table

ReleaseNotes

1.0.0-beta

Python, SQL, and Scala functions introduced

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