TRK_Aggr_CreateTrack operates on a grouped DataFrame and creates tracks using the points in each group, where each point represents an entity's observed location at an instant. The output tracks are linestrings that represent the shortest path between each observation. Each vertex in the linestring has a timestamp (stored as the M-value) and the vertices are ordered sequentially.
Tracks are usually created after grouping points by one or more fields that uniquely identify each entity. For example, to create tracks that represent individual taxi trips, you might group point observations of taxis by a trip ID field. To create tracks that represent entire taxi shifts, you might group by both a driver ID field and a date field. You can group your DataFrame using DataFrame.groupBy() or with a GROUP BY clause in a SQL statement.
Track M-values represent an instant in time and are stored in units of seconds from epoch. M-values in the input points will be ignored and not included in the result linestring. Z-values will be included as Z-values in the result linestring.
For more information on using tracks in GeoAnalytics Engine, see the core concept topic on tracks.
Function | Syntax |
---|---|
Python | aggr |
SQL | TRK |
For more details, go to the GeoAnalytics Engine API reference for aggr_create_track.
Examples
from geoanalytics.tracks import functions as TRK
from geoanalytics.sql import functions as ST
from pyspark.sql import functions as F
data = [
("POINT (-117.22 33.91)", 1, "2021-10-05 10:31:02"),
("POINT (-117.27 34.05)", 1, "2021-10-05 10:30:10"),
("POINT (-116.96 33.64)", 1, "2021-10-05 10:32:12"),
("POINT (-116.66 33.71)", 1, "2021-10-05 10:33:26"),
("POINT (-116.89 33.96)", 2, "2021-10-06 20:04:55"),
("POINT (-116.71 34.01)", 2, "2021-10-06 20:06:22"),
("POINT (-117.05 34.22)", 2, "2021-10-06 20:08:39"),
("POINT (-116.66 34.08)", 2, "2021-10-06 20:07:41")
]
df = spark.createDataFrame(data, ["wkt", "id", "datetime_str"]) \
.withColumn("point", ST.point_from_text("wkt", srid=4326)) \
.withColumn("timestamp", F.to_timestamp("datetime_str"))
agg_df = df.groupBy("id").agg(TRK.aggr_create_track("point", "timestamp").alias("track"))
ax = df.st.plot("point", facecolor="none", edgecolor="red", figsize=(15, 8))
agg_df.st.plot("track", ax=ax, facecolor="none", edgecolor="blue")
Version table
Release | Notes |
---|---|
1.4.0 | Function introduced |