ST_Generalize

ST_Generalize takes a linestring or polygon geometry column and a numeric tolerance and returns a geometry column. This function generalizes the input linestring or polygon geometry using the Douglas-Peucker algorithm with the specified tolerance. The result is the input geometry generalized to include only a subset of the original geometry's vertices. Point and multipoint geometry types are not supported as input.

FunctionSyntax
Pythongeneralize(geometry, tolerance)
SQLST_Generalize(geometry, tolerance)
Scalageneralize(geometry, tolerance)

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

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
17
18
19
20
from geoanalytics.sql import functions as ST, Point

data = [
    (Point(-25,0), 0.5),
    (Point(0,0), 1.0),
    (Point(25,0), 5.0)
]

df = spark.createDataFrame(data, ["point", "tolerance"])

df_buffer = df.withColumn("buffer", ST.buffer("point", 10))
axes = df_buffer.st.plot(geometry="buffer", cmap_values="tolerance", is_categorical=True, \
                         legend=True, aspect = "equal")
axes.set_title("Polygon inputs")

result = df_buffer.select(ST.generalize("buffer", "tolerance"), "tolerance")
axes = result.st.plot( cmap_values="tolerance", is_categorical=True, legend=True, aspect = "equal")
axes.set_title("Generalized polygons with varying tolerances");
Plotting example for ST_Generalize
Plotting example for ST_Generalize
Plotted result for ST_Generalize.

Scala examples

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

case class PointRow(point: Point, tolerance: Double)

val data = Seq(PointRow(Point(-25, 0), 0.5),
               PointRow(Point(0, 0), 1.0),
               PointRow(Point(25, 0), 5.0))

val df = spark.createDataFrame(data)
              .withColumn("buffer", ST.buffer($"point", 10))
              .select(ST.generalize($"buffer", $"tolerance").alias("generalize"))
              .withColumn("generalized_polygon_area", F.round(ST.area($"generalize"),3))

df.show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+--------------------+------------------------+
|          generalize|generalized_polygon_area|
+--------------------+------------------------+
|{"rings":[[[-15,0...|                 306.147|
|{"rings":[[[10,0]...|                 282.843|
|{"rings":[[[35,0]...|                   200.0|
+--------------------+------------------------+

Version table

ReleaseNotes

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