ST_LineInterpolatePoint takes a linestring column and a number between 0 and 1 and returns a point column. The output column
represents the location along the input linestring at the fractional distance specified, where 0 returns the first point
in the line and 1 returns the last point in the line. This function always returns null
for multipart linestrings and
other geometries. 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_interpolate_point.
Python and SQL Examples
from geoanalytics.sql import functions as ST
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("line_interpolate_point", ST.line_interpolate_point("linestring", 0.25))
ax = df.st.plot("linestring", edgecolor="lightgrey", zorder=0, linewidths=10, figsize=(15, 8))
df.st.plot("line_interpolate_point", ax=ax, facecolor="red", s=75, zorder=1)
ax.legend(['Input linestring','Point 25% along linestring'], loc='lower right', fontsize='x-large')

Scala Example
Scala
import com.esri.geoanalytics.sql.{functions => ST}
import org.apache.spark.sql.{functions => F}
case class lineRow(lineWkt: String)
val data = Seq(lineRow("LINESTRING (-117.27 34.05, -117.22 33.91, -116.96 33.64)"),
lineRow("LINESTRING (-116.89 33.96, -116.71 34.01, -116.66 34.08)"),
lineRow("LINESTRING (-116.24 33.88, -116.33 34.02)"))
val df = spark.createDataFrame(data)
.withColumn("linestring", ST.lineFromText($"lineWkt", F.lit(4326)))
.withColumn("line_interpolate_point", ST.lineInterpolatePoint($"linestring", F.lit(0.25)))
df.select("line_interpolate_point").show(truncate = false)
Result
+------------------------------------------------+
|line_interpolate_point |
+------------------------------------------------+
|{"x":-117.22598247991357,"y":33.92675094375801} |
|{"x":-116.82427876385185,"y":33.97825589893004} |
|{"x":-116.26249999999999,"y":33.915000000000006}|
+------------------------------------------------+
Version table
Release | Notes |
---|---|
1.6.0 | Python, SQL, and Scala functions introduced |