TRK_Before

TRK_Before takes a track column and an offset and returns a track. The result is the subset of the input track that is between the track start and the offset distance or offset duration.

An offset column can be created with ST_CreateDistance or ST_CreateDuration. You can also define an offset with a tuple containing a number and a unit string (e.g., (10, "kilometers") or (5, "minutes")).

For example, if you use a distance offset of 2 miles, the result track will be the subset of the input track that is no further than 2 miles along the input track's length from its start. Similarly, if you use a duration offset of 10 minutes, the result track will be the subset of the input track that is no longer than 10 minutes from its start time.

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.

FunctionSyntax
Pythonbefore(track, offset)
SQLTRK_Before(track, offset)
Scalabefore(track, offset)

For more details, go to the GeoAnalytics Engine API reference for before.

Python and SQL Examples

PythonPythonSQL
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from geoanalytics.sql import functions as ST
from geoanalytics.tracks import functions as TRK

data = [
    ("LINESTRING M (-117.27 34.05 1633455010, -117.22 33.91 1633456062, -116.96 33.64 1633457132)",),
    ("LINESTRING M (-116.89 33.96 1633575895, -116.71 34.01 1633576982, -116.66 34.08 1633577061)",),
    ("LINESTRING M (-116.24 33.88 1633575234, -116.33 34.02 1633576336)",)
]

df = spark.createDataFrame(data, ["wkt"]).withColumn("track", ST.line_from_text("wkt", srid=4326)) \
                                         .withColumn("10_minutes", TRK.query("track", (10, "minutes"))) \
                                         .withColumn("start_point", ST.start_point("track")) \
                                         .withColumn("end_point", ST.end_point("track"))

result = df.withColumn("before", TRK.before("track", (10, "minutes")))

ax = result.st.plot("track", edgecolor="lightgrey",  linewidths=10, zorder=0, figsize=(15, 8))
result.st.plot("start_point", ax=ax, s=75, facecolor="green", zorder=2)
result.st.plot("end_point", ax=ax, s=75, facecolor="red", zorder=2)
result.st.plot("10_minutes", ax=ax, s=75, facecolor="black", marker="x", zorder=2)
result.st.plot("before", ax=ax, edgecolor="greenyellow", linewidths=3, zorder=1)
ax.legend(['Input track','Input track start','Input track end','10 minutes along input track','Result track'],
          loc='lower right', fontsize='x-large')
Plotted example for TRK_Before
Plotted result for TRK_Before.

Scala Example

Scala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import com.esri.geoanalytics.sql.{functions => ST}
import com.esri.geoanalytics.sql.{trackFunctions => TRK}
import org.apache.spark.sql.{functions => F}

case class lineRow(lineWkt: String)
val data = Seq(lineRow("LINESTRING M (-117.27 34.05 1633455010, -117.22 33.91 1633456062, -116.96 33.64 1633457132)"),
               lineRow("LINESTRING M (-116.89 33.96 1633575895, -116.71 34.01 1633576982, -116.66 34.08 1633577061)"),
               lineRow("LINESTRING M (-116.24 33.88 1633575234, -116.33 34.02 1633576336)"))

val df = spark.createDataFrame(data)
              .withColumn("track", ST.lineFromText($"lineWkt", F.lit(4326)))
              .withColumn("before", TRK.before($"track",  F.lit(struct(F.lit(10), F.lit("minutes")))))

df.select("before").show(truncate = false)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+--------------------------------------------------------------------------------------------------------------+
|before                                                                                                        |
+--------------------------------------------------------------------------------------------------------------+
|{"hasM":true,"paths":[[[-117.27,34.05,1.63345501e9],[-117.24148288973383,33.97015209125475,1.63345561e9]]]}   |
|{"hasM":true,"paths":[[[-116.89,33.96,1.633575895e9],[-116.79064397424102,33.987598896044155,1.633576495e9]]]}|
|{"hasM":true,"paths":[[[-116.24,33.88,1.633575234e9],[-116.28900181488203,33.95622504537205,1.633575834e9]]]} |
+--------------------------------------------------------------------------------------------------------------+

Version table

ReleaseNotes

1.4.0

Python and SQL functions introduced

1.5.0

Scala function introduced

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