ST_LineLocatePoint takes a linestring column and a point column and returns a float column. The output column represents
the fractional distance along the linestring where it intersects the point. If the point does not
intersect the linestring, the function returns null
. This function always returns null
for multipart linestrings.
This function uses planar distance calculations.
Function | Syntax |
---|---|
Python | line |
SQL | ST |
Scala | line |
For more details, go to the GeoAnalytics Engine API reference for line_locate_point.
Examples
from geoanalytics.sql import functions as ST
from pyspark.sql import functions as F
data = [
("LINESTRING (-117.27 34.05, -117.22 33.91, -116.96 33.64)",),
("LINESTRING (-116.89 33.96, -116.71 34.01, -116.66 34.08)",),
("LINESTRING (-116.24 33.88, -116.33 34.02)",)
]
df = spark.createDataFrame(data, ["line_wkt",]) \
.withColumn("linestring", ST.line_from_text("line_wkt", srid=4326)) \
.withColumn("point", ST.point_n("linestring", 1)) \
.withColumn("line_locate_point", ST.line_locate_point("linestring", "point"))
df.select(F.round("line_locate_point", 3).alias("line_locate_point")).show()
Result
+-----------------+
|line_locate_point|
+-----------------+
| 0.284|
| 0.685|
| 1.0|
+-----------------+
Version table
Release | Notes |
---|---|
1.6.0 | Python, SQL, and Scala functions introduced |