Skip to content

ST_Segmentize

ST_Segmentize takes a linestring column and a numeric column or value representing maximum segment length and returns an array column. This function creates an array of linestrings from the input linestring by breaking the input linestring into segments that are shorter than or equal to the maximum length specified.

The max_segment_length can be specified with or without a unit. When specified with a unit, the max_segment_length can be defined using ST_CreateDistance or with a tuple containing a number and a unit string (e.g., (10, "kilometers")). When specified without a unit, the max_segment_length can be a single value or a numeric column, and it is assumed to be in the same units as the input geometry.

FunctionSyntax
Pythonsegmentize(linestring, max_segment_length=2)
SQLST_Segmentize(linestring, max_segment_length)
Scalasegmentize(linestring, maxSegmentLength)

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

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.segmentize("linestring", max_segment_length=2).alias("segmentize")).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+------------------------------------------------------------------+
|segmentize                                                        |
+------------------------------------------------------------------+
|[{"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

1.6.0

max_segment_length parameter accepts values with specified units

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