TRK_Between

TRK_Between takes a track column and two offsets and returns a track. The result is the subset of the input track that comes between the two offset distances or offset durations. You can also use one offset distance and one 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 start distance offset of 2 miles and an end distance offset of 6 miles, the result track will be the subset of the input track that is between 2 and 6 miles along the input track's length from its start.

Similarly, if you use a start duration offset of 10 minutes and an end duration offset of 15 minutes, the result track will be the subset of the input track that is between 10 and 15 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
Pythonbetween(track, start_offset, end_offset)
SQLTRK_Between(track, start_offset, end_offset)
Scalabetween(track, startOffset, endOffset)

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

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
26
27
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("5_minutes", TRK.query("track", (5, "minutes"))) \
                                         .withColumn("15_minutes", TRK.query("track", (15, "minutes"))) \
                                         .withColumn("start_point", ST.start_point("track")) \
                                         .withColumn("end_point", ST.end_point("track"))

result = df.withColumn("between", TRK.between("track", (5, "minutes"), (15, "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("5_minutes", ax=ax, s=75, facecolor="black", marker="x", zorder=2)
result.st.plot("15_minutes", ax=ax, s=75, facecolor="black", marker="X", zorder=2)
result.st.plot("between", ax=ax, edgecolor="greenyellow", linewidths=3, zorder=1)
ax.legend(['Input track','Input track start','Input track end','5 minutes along input track',
           '15 minutes along input track','Result track'], loc='lower right', fontsize='x-large')
Plotted example for TRK_Between
Plotted result for TRK_Between.

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
17
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("between", TRK.between($"track",  F.lit(struct(F.lit(5), F.lit("minutes"))), F.lit(struct(F.lit(15), F.lit("minutes")))))

df.select("between").show(truncate = false)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+-------------------------------------------------------------------------------------------------------------------------------------+
|between                                                                                                                              |
+-------------------------------------------------------------------------------------------------------------------------------------+
|{"hasM":true,"paths":[[[-117.25574144486691,34.01007604562737,1.63345531e9],[-117.22722433460076,33.93022813688213,1.63345591e9]]]}  |
|{"hasM":true,"paths":[[[-116.84032198712052,33.97379944802208,1.633576195e9],[-116.74096596136154,34.00139834406624,1.633576795e9]]]}|
|{"hasM":true,"paths":[[[-116.26450090744102,33.91811252268603,1.633575534e9],[-116.31350272232305,33.99433756805808,1.633576134e9]]]}|
+-------------------------------------------------------------------------------------------------------------------------------------+

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.