ST_PointN

ST_PointN takes a geometry column and an integer and returns a point column. The output column represents the nth point in the input geometry, where 0 is the first point. If the nth point does not exist the function returns null. This function always returns null for multipart linestrings and multipart polygons.

FunctionSyntax
Pythonpoint_n(geometry, n)
SQLST_PointN(geometry, n)
ScalapointN(geometry, n)

For more details, go to the GeoAnalytics Engine API reference for point_n.

This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

from geoanalytics.sql import functions as ST

data = [
    ("POINT (10 30)",),
    ("MULTIPOINT (0 0, 5 5, 0 5)", ),
    ("LINESTRING (15 15, 10 15, 12 2)", ),
    ("POLYGON ((20 30, 18 28, 22 35, 40 20))", ),
    ("MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))", )
]

df = spark.createDataFrame(data, ["wkt"])\
          .select(ST.geom_from_text("wkt").alias("geometry"))

df.select(ST.point_n("geometry", 2).alias("point_n")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
+---------------+
|        point_n|
+---------------+
|           NULL|
|  {"x":0,"y":5}|
| {"x":12,"y":2}|
|{"x":22,"y":35}|
|           NULL|
+---------------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.