ST_Z can work as a getter or a setter, depending on the inputs.
Getter: ST_Z takes a point column and returns a double column containing the z-coordinates of the input points. If a
point does not have a z-coordinate the function returns Na
.
Setter: ST_Z takes a point column and a numeric value or column and returns a point column containing the input points with the z-coordinates set to the numeric value.
Function | Syntax |
---|---|
Python | z(point, new |
SQL | ST |
Scala | z(point, value) |
For more details, go to the GeoAnalytics Engine API reference for z.
This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.
Examples
Getter
from geoanalytics.sql import functions as ST
data = [
('{"x": -0.126,"y": 51.504,"z": 11253}',),
('{"x": -0.126,"y": 51.504}',)
]
df = spark.createDataFrame(data, ["esri_json"]) \
.withColumn("point", ST.point_from_esri_json("esri_json"))
df.select(ST.z("point").alias("get_z")).show()
+-------+
| get_z|
+-------+
|11253.0|
| NaN|
+-------+
Setter
from geoanalytics.sql import functions as ST
data = [
('{"x": -0.126,"y": 51.504,"z": 11253}', 12000),
('{"x": -0.126,"y": 51.504}', 10000)
]
df = spark.createDataFrame(data, ["esri_json", "new_value"]) \
.withColumn("point", ST.point_from_esri_json("esri_json"))
df.select(ST.z("point", "new_value").alias("set_z")).show(truncate=False)
+---------------------------------+
|set_z |
+---------------------------------+
|{"x":-0.126,"y":51.504,"z":12000}|
|{"x":-0.126,"y":51.504,"z":10000}|
+---------------------------------+
Version table
Release | Notes |
---|---|
1.0.0 | Python and SQL functions introduced |
1.5.0 | Scala function introduced |