ST_Segments

ST_Segments takes a linestring column and returns an array column. The function creates an array of linestrings by splitting the input linestring at a certain number of vertices using a moving window. By default the function will create segments with two points and the moving window will move one point at a time (step size of 1). You can optionally include a larger number of points in each linestring by specifying a numeric value greater than 2. You can also increase the step size by setting it to a value greater than 1. Setting the step size to one less than the number of points will always result in segments that touch but do not overlap.

FunctionSyntax
Pythonsegments(linestring, num_points=2, step_size=1)
SQLST_Segments(linestring, num_points, step_size)
Scalasegments(linestring, numPoints, stepSize)

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

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6

from geoanalytics.sql import functions as ST, Linestring

df = spark.createDataFrame([(Linestring([[[0, 0], [1, 0], [2, 0], [3, 0], [4, 0]]]),)],["linestring"])

df.select(ST.segments("linestring", 3, 2).alias("segments")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+------------------------------------------------------------------+
|segments                                                          |
+------------------------------------------------------------------+
|[{"paths":[[[0,0],[1,0],[2,0]]]}, {"paths":[[[2,0],[3,0],[4,0]]]}]|
+------------------------------------------------------------------+

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.