TRK_Length

TRK_Length takes a track column and returns a float column representing the length of each input track. The result is returned in the units specified by output_unit. When output_unit is None, the result is in the units of the input track's spatial reference if it's projected; otherwise, the result is in meters.

Planar distance calculations are used if the input tracks have a projected spatial reference or no spatial reference. Chordal distance calculations are used if the input tracks have a geographic spatial reference. 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.

FunctionSyntax
Pythonlength(track, output_unit=None)
SQLTRK_Length(track, output_unit)
Scalalength(track, outputUnit)

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

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from geoanalytics.tracks import functions as TRK
from geoanalytics.sql import functions as ST
from pyspark.sql import functions as F

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))

df.select(F.round(TRK.length("track", "miles"), 3).alias("length")).show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+------+
|length|
+------+
|33.947|
|16.507|
|10.947|
+------+

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.