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.
Function | Syntax |
---|---|
Python | cast(geometry, geometry |
SQL | ST |
Scala | cast(geometry, geometry |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for cast.
Examples
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
root
|-- point: point (nullable = true)
root
|-- point: geometry (nullable = true)
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |