ST_Cast

ST_Cast takes a geometry column and a string and returns a geometry column. The result column contains the input geometries cast to the geometry type specified by the string value. The string value can be 'point', 'multipoint', 'linestring', 'polygon', or 'geometry'. The function will return null when the input geometries cannot be cast to the specified type.

This function is commonly used to:

  • Cast from a specific geometry type to the generic geometry type when merging two geometry columns with different types.
  • Cast from the generic geometry type to a specific geometry type when using a function or tool that requires a specific geometry type as input.
FunctionSyntax
Pythoncast(geometry, geometry_type)
SQLST_Cast(geometry, geometry_type)
Scalacast(geometry, geometryType)

For more details, go to the GeoAnalytics for Microsoft Fabric API reference for cast.

Examples

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

df = spark.createDataFrame([(Point(10, 10),)], ["point"])

df.printSchema()

df.select(ST.cast("point", "geometry").alias("point")).printSchema()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
root
 |-- point: point (nullable = true)

root
 |-- point: geometry (nullable = true)

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.