TRK_DurationWithin takes a track column and a geometry column and returns a float column. The geometry type can be
linestring or polygon. The float column contains the duration of the track that intersects the linestring or
polygon. The result is returned in the units specified by output
. The default is seconds
. If the track crosses
the geometry multiple times, the function returns the total duration traveled within the geometry.
If the track and geometry columns are in different spatial references, the function automatically transforms the geometry into the spatial reference of the track. For more information see Coordinate systems and transformations.
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.
Function | Syntax |
---|---|
Python | duration |
SQL | TRK |
Scala | duration |
For more details, go to the GeoAnalytics Engine API reference for duration_within.
Examples
from geoanalytics.sql import functions as ST
from geoanalytics.tracks import functions as TRK
from pyspark.sql import functions as F
data = [(1, "LINESTRING M (-117.27 34.05 1633455010, -117.22 33.91 1633456062, -116.96 33.64 1633457132)",
"POLYGON((-117.22 33.91, -117.22 33.75, -117.05 33.91, -117.22 33.91))"),
(2, "LINESTRING M (-116.89 33.96 1633575895, -116.71 34.01 1633576982, -116.66 34.08 1633577061)",
"POLYGON((-116.80 34.05, -116.62 34.05, -116.72 33.98, -116.80 33.98, -116.80 34.05))"),
(3, "LINESTRING M (-116.24 33.88 1633575234, -116.33 34.02 1633576336)",
"POLYGON((-116.38 34.05, -116.20 34.05, -116.20 33.85, -116.38 33.85,-116.38 34.05))"),]
df = spark.createDataFrame(data, ["id", "trk_wkt", "poly_wkt"]) \
.withColumn("track", ST.line_from_text("trk_wkt", 4326)) \
.withColumn("polygon", ST.poly_from_text("poly_wkt", 4326))
df.select("id", F.round(TRK.duration_within("track", "polygon", "minutes"), 1).alias("duration_within")).show()
+---+---------------+
| id|duration_within|
+---+---------------+
| 1| 5.5|
| 2| 9.8|
| 3| 18.4|
+---+---------------+
Version table
Release | Notes |
---|---|
1.5.0 | Python, SQL, and Scala functions introduced |