Geometry accessors

st_asbinary

st_asbinary(col)

Translate a geometry into its Well-known Binary (WKB) representation.

Parameters:

col (Column: StringType, HexType, JSONType or InternalGeometryType) – Geometry column

Return type:

Column: BinaryType

Example:

df = spark.createDataFrame([{'wkt': 'POINT (30 10)'}])
df.select(st_asbinary('wkt').alias('wkb')).show()
+--------------------+
|                 wkb|
+--------------------+
|[01 01 00 00 00 0...|
+--------------------+

Note

Alias for st_aswkb.

st_asgeojson

st_asgeojson(col)

Translate a geometry into its GeoJSON representation.

Parameters:

col (Column: BinaryType, StringType, HexType or InternalGeometryType) – Geometry column

Return type:

Column: JSONType

Example:

df = spark.createDataFrame([{'wkt': 'POINT (30 10)'}])
df.select(st_asgeojson('wkt').cast('string').alias('json')).show(truncate=False)
+------------------------------------------------------------------------------------------------+
|json                                                                                            |
+------------------------------------------------------------------------------------------------+
|{{"type":"Point","coordinates":[30,10],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}|
+------------------------------------------------------------------------------------------------+

st_astext

st_astext(col)

Translate a geometry into its Well-known Text (WKT) representation.

Parameters:

col (Column: BinaryType, HexType, JSONType or InternalGeometryType) – Geometry column

Return type:

Column: StringType

Example:

df = spark.createDataFrame([{'lon': 30., 'lat': 10.}])
df.select(st_astext(st_point('lon', 'lat')).alias('wkt')).show()
+-------------+
|          wkt|
+-------------+
|POINT (30 10)|
+-------------+

Note

Alias for st_aswkt.

st_aswkb

st_aswkb(col)

Translate a geometry into its Well-known Binary (WKB) representation.

Parameters:

col (Column: StringType, HexType, JSONType or InternalGeometryType) – Geometry column

Return type:

Column: BinaryType

Example:

df = spark.createDataFrame([{'wkt': 'POINT (30 10)'}])
df.select(st_aswkb('wkt').alias('wkb')).show()
+--------------------+
|                 wkb|
+--------------------+
|[01 01 00 00 00 0...|
+--------------------+

Note

Alias for st_asbinary.

st_aswkt

st_aswkt(col)

Translate a geometry into its Well-known Text (WKT) representation.

Parameters:

col (Column: BinaryType, HexType, JSONType or InternalGeometryType) – Geometry column

Return type:

Column: StringType

Example:

df = spark.createDataFrame([{'lon': 30., 'lat': 10.}])
df.select(st_aswkt(st_point('lon', 'lat')).alias('wkt')).show()
+-------------+
|          wkt|
+-------------+
|POINT (30 10)|
+-------------+

Note

Alias for st_astext.