ST_SRText can work as a getter or a setter, depending on the inputs.
Getter: ST_SRText takes a geometry column and returns the spatial reference of the column as a string in Well-Known Text (WKT) format. If the spatial reference of the input geometry column has not been set, the function returns an empty string.
Setter: ST_SRText takes a geometry column and a spatial reference string in Well-Known Text (WKT) format and returns the input geometry column with its spatial reference set to the string value. This does not affect the geometry data in the column. To transform your geometry data from one spatial reference to another, use ST_Transform.
Function | Syntax |
---|---|
Python | sr |
SQL | ST |
Scala | sr |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for sr_text.
Examples
Setter
from geoanalytics_fabric.sql import functions as ST, Point
wkt_4326 = ('GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",'
'SPHEROID["WGS_1984",6378137.0,298.257223563]],'
'PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]')
df = spark.createDataFrame([(Point(-178, -17),)], ["point"])
df.withColumn("sr_text", ST.sr_text("point")).show()
df.select(ST.sr_text("point", wkt_4326).alias("point"))\
.withColumn("sr_text", ST.sr_text("point")).show(truncate=False)
+------------------+-------+
| point|sr_text|
+------------------+-------+
|{"x":-178,"y":-17}| |
+------------------+-------+
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
|point |sr_text |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
|{"x":-178,"y":-17}|GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]|
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
Getter
from geoanalytics_fabric.sql import functions as ST
df = spark.createDataFrame([("POINT (-2533858.73 8107527.81)",)], ["wkt"])\
.select(ST.point_from_text("wkt", sr=54008).alias("geometry"))
df.select(ST.sr_text("geometry").alias("sr_text")).show(truncate=False)
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|sr_text |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|PROJCS["World_Sinusoidal",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Sinusoidal"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],UNIT["Meter",1.0]]|
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |