Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks Runtime 18.1 and above
Important
This feature is in Public Preview.
Returns the 2D projection of the input Geography or Geometry value.
The SRID value of the output Geography or Geometry value is equal to that of the input value.
The function returns None if the input is None.
For the corresponding Databricks SQL function, see st_force2d function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.st_force2d(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
A Geography or Geometry value. |
Notes
If the input has Z and/or M coordinates, these are dropped in the output.
If the input is already 2D, it is returned as is.
Examples
Drop the M coordinate from a point geography:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POINT M (1 2 3)',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_force2d(dbf.st_geogfromtext('wkt'))).alias('result')).collect()
[Row(result='SRID=4326;POINT(1 2)')]
Drop Z and M coordinates from a multipoint geography:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOINT ZM (EMPTY,0 0 10 20, 1 1 11 21)',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_force2d(dbf.st_geogfromtext('wkt'))).alias('result')).collect()
[Row(result='SRID=4326;MULTIPOINT(EMPTY,(0 0),(1 1))')]
Drop the Z coordinate from a polygon geography:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POLYGON Z ((0 0 2,1 0 3,0 1 4,0 0 5))',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_force2d(dbf.st_geogfromtext('wkt'))).alias('result')).collect()
[Row(result='SRID=4326;POLYGON((0 0,1 0,0 1,0 0))')]
Drop the Z coordinate from a point geometry:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POINT Z (1 2 3)',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_force2d(dbf.st_geomfromtext('wkt', 4326))).alias('result')).collect()
[Row(result='SRID=4326;POINT(1 2)')]
Drop Z and M coordinates from a linestring geometry:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('LINESTRING ZM (0 0 10 20, 1 1 11 21)',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_force2d(dbf.st_geomfromtext('wkt', 4326))).alias('result')).collect()
[Row(result='SRID=4326;LINESTRING(0 0,1 1)')]
Return the input 2D geometry as is:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POINT(1 2)',)], ['wkt'])
df.select(dbf.st_asewkt(dbf.st_force2d(dbf.st_geomfromtext('wkt', 4326))).alias('result')).collect()
[Row(result='SRID=4326;POINT(1 2)')]
Preserve the SRID of the input geography:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POINT(1 2)',)], ['wkt'])
df.select(dbf.st_srid(dbf.st_force2d(dbf.st_geogfromtext('wkt'))).alias('result')).collect()
[Row(result=4326)]
Preserve the SRID of the input geometry:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POINT(1 2)',)], ['wkt'])
df.select(dbf.st_srid(dbf.st_force2d(dbf.st_geomfromtext('wkt', 4326))).alias('result')).collect()
[Row(result=4326)]
Return None with an input of None:
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None,)], ['wkt'])
df.select(dbf.st_force2d(dbf.st_geogfromtext('wkt')).alias('result')).collect()
[Row(result=None)]