TRK_LCSS

TRK_LCSS takes two track columns, a numeric search distance, and a numeric duration value and returns a double column. The output represents the size of the longest common subsequence between the two tracks.

Tracks are linestrings that represent the change in an entity's location over time. Each vertex in the linestring has a timestamp (stored as the M-value) and the vertices are ordered sequentially.

For more information on using tracks in GeoAnalytics for Microsoft Fabric, see the core concept topic on tracks.

TRK_LCSS considers the order of the track observations. A pair of track observations between the two tracks will be included in the common subsequence if these two observations are within the search distance and duration thresholds.

There are two types of LCSS, spatiotemporal (ST-LCSS) and spatial only (S-LCSS). ST-LCSS considers both search distance and duration filter criteria while S-LCSS considers distance filter criteria only.

The ST_CreateDistance and ST_CreateDuration functions can be used to define the search distance and search duration parameters. You can also define them with a tuple containing a number and a unit string (e.g., (10, "kilometers") or (5, "minutes")).

TRK_LCSS
Two tracks (orange and blue). If a pair of track observation meets the criteria (red circle), it will be considered part of the common subsequence. In this example, the longest common subsequence will consist of 5 pairs: (2,2), (3,3), (4,4), (7,6), (8,7). The TRK_LCSS result will be 5​.

TRK_LCSS does not take z-values into account. If the input tracks have z-values, they will be ignored in the LCSS calculation.

If the two geometry columns are in different spatial references, the function will automatically transform the second geometry into the spatial reference of the first.

ST_LCSS uses a planar method to calculate the distance when the tracks are in a projected coordinate system and a geodesic method when the tracks are in a geographic coordinate system. If one of the tracks has an unknown spatial reference, planar method will be used to calculate the LCSS result.

This function can be used to measure the similarity between two tracks. For more details, go to the core topic for similarity measures.

FunctionSyntax
Pythonlcss(track1, track2, search_distance, search_duration=None)
SQLTRK_LCSS(track1, track2, search_distance, search_duration)
Scalalcss(track1, track2, searchDistance, searchDuration)

For more details, go to the GeoAnalytics for Microsoft Fabric API reference for lcss.

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_fabric.tracks import functions as TRK
from geoanalytics_fabric.sql import functions as ST

data = [
    ("LINESTRING M (10 10 1715194800, 10 35 1715198400, 10 65 1715202000, 10 85 1715208000)", "LINESTRING M (10 11 1715195400, 10 36 1715199600, 10 66 1715203800, 10 86 1715210400)"),
    ("LINESTRING M (-117.27 34.05 1715198400, -117.22 33.91 1715202000, -116.96 33.64 1715208000)", "LINESTRING M (-116.89 33.96 1715199600, -116.71 34.01 1715203800, -116.66 34.08 1715210400)")
]

df = spark.createDataFrame(data, ["line1_wkt", "line2_wkt"]) \
          .withColumn("track1", ST.line_from_text("line1_wkt", 4326)) \
          .withColumn("track2", ST.line_from_text("line2_wkt", 4326))

df.select(TRK.lcss('track1', 'track2', ST.create_distance(70, 'miles'), ST.create_duration(5, 'hours')).alias('lcss')).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+----+
|lcss|
+----+
| 4.0|
| 3.0|
+----+

Version table

ReleaseNotes

1.0.0-beta

Python, SQL, and Scala functions introduced

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