ST_Centerline

ST_Centerline takes a polygon column and returns a line column that represents the centerline of each input polygon. The purpose of this function is to create centerlines from hydrographic polygons for use at larger scales.

FunctionSyntax
Pythoncenterline(polygon)
SQLST_Centerline(polygon)
Scalacenterline(polygon)

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

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
from geoanalytics.sql import functions as ST

data = [
    ("POLYGON ((-115.87996315955866 37.493007249483064, -116.20955300330856 36.792410506881424, -115.7481272220587 36.333552263814276, -116.1216623783086 35.550836720474244, -115.66023659705871 34.97673809803499, -115.59431862830874 33.92587561185498, -115.19881081580886 35.0127383040925, -115.59431862830874 35.56871167950533, -115.3086740970588 36.492696164870054, -115.7481272220587 36.880339665745446, -115.87996315955866 37.493007249483064))", ),
    ("POLYGON ((-113.8804514408092 37.02081593720533, -113.00154519080942 36.9506101853256, -112.36433815955958 36.86276192128377, -111.66121315955978 36.61624917109116, -110.91414284705998 36.73960450810167, -110.87019753456 36.12085373842121, -111.26570534705989 35.586582651595315, -110.18904519081018 34.2170880405633, -110.80427956580999 35.729406796929375, -110.36482644081012 36.12085373842121, -110.67244362831003 37.10848197802594, -111.6172678470598 36.96816769705664, -112.64998269080951 37.21354742555541, -113.8804514408092 37.02081593720533))", )
]

df = spark.createDataFrame(data, ["wkt"])\
          .select(ST.geom_from_text("wkt").alias("geometry"))

df = df.withColumn("centerline",ST.centerline("geometry"))

ax = df.st.plot("geometry", facecolor="none", edgecolor="red")
df.st.plot("centerline", ax=ax, facecolor="none", edgecolor="blue")
Plotting example for ST_Centerline
Plotted result for ST_Centerline.

Scala Example

Scala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import com.esri.geoanalytics.sql.{functions => ST}
import org.apache.spark.sql.{functions => F}

case class PolygonRow(wkt: String)
val data = Seq(PolygonRow("POLYGON ((-115.87996315955866 37.493007249483064, -116.20955300330856 36.792410506881424, -115.7481272220587 36.333552263814276, -116.1216623783086 35.550836720474244, -115.66023659705871 34.97673809803499, -115.59431862830874 33.92587561185498, -115.19881081580886 35.0127383040925, -115.59431862830874 35.56871167950533, -115.3086740970588 36.492696164870054, -115.7481272220587 36.880339665745446, -115.87996315955866 37.493007249483064))"),
               PolygonRow("POLYGON ((-113.8804514408092 37.02081593720533, -113.00154519080942 36.9506101853256, -112.36433815955958 36.86276192128377, -111.66121315955978 36.61624917109116, -110.91414284705998 36.73960450810167, -110.87019753456 36.12085373842121, -111.26570534705989 35.586582651595315, -110.18904519081018 34.2170880405633, -110.80427956580999 35.729406796929375, -110.36482644081012 36.12085373842121, -110.67244362831003 37.10848197802594, -111.6172678470598 36.96816769705664, -112.64998269080951 37.21354742555541, -113.8804514408092 37.02081593720533))"))

val df = spark.createDataFrame(data)
              .select(ST.geomFromText($"wkt").alias("geometry"))
              .withColumn("centerline", ST.centerline($"geometry"))
              .withColumn("centerline_length",F.round(ST.length($"centerline"),3))

df.select("centerline", "centerline_length").show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
+--------------------+-----------------+
|          centerline|centerline_length|
+--------------------+-----------------+
|{"paths":[[[-115....|            3.374|
|{"paths":[[[-110....|            5.403|
+--------------------+-----------------+

Version table

ReleaseNotes

1.2.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.