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 Engine, 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 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.
Function | Syntax |
---|---|
Python | lcss(track1, track2, search |
SQL | TRK |
Scala | lcss(track1, track2, search |
For more details, go to the GeoAnalytics Engine API reference for lcss.
Examples
from geoanalytics.tracks import functions as TRK
from geoanalytics.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()
+----+
|lcss|
+----+
| 4.0|
| 3.0|
+----+
Version table
Release | Notes |
---|---|
1.4.0 | Python and SQL functions introduced |
1.5.0 | Scala function introduced |