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 for Microsoft Fabric API reference for generalize.

Python and SQL Examples

PythonPythonSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

from geoanalytics_fabric.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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

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
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-beta

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.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close