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.
Function | Syntax |
---|---|
Python | segments(linestring, num |
SQL | ST |
Scala | segments(linestring, num |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for segments.
Examples
from geoanalytics_fabric.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)
+------------------------------------------------------------------+
|segments |
+------------------------------------------------------------------+
|[{"paths":[[[0,0],[1,0],[2,0]]]}, {"paths":[[[2,0],[3,0],[4,0]]]}]|
+------------------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |