Skip to content

ST_LineLocatePoint

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.

FunctionSyntax
Pythonline_locate_point(linestring, point)
SQLST_LineLocatePoint(linestring, point)
ScalalineLocatePoint(linestring, point)

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

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.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
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+-----------------+
|line_locate_point|
+-----------------+
|            0.284|
|            0.685|
|              1.0|
+-----------------+

Version table

ReleaseNotes

1.6.0

Python, SQL, and Scala functions introduced

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