Skip to content

ST_Densify

ST_Densify takes a geometry column and a numeric max_segment_length value and returns a geometry column. This function adds vertices along linestrings or polygons such that every segment within the geometry is no longer than max_segment_length, using planar distance calculation.

The max_segment_length can be specified with or without a unit. When specified with a unit, the max_segment_length can be defined using ST_CreateDistance or with a tuple containing a number and a unit string (e.g., (10, "kilometers")). When specified without a unit, the max_segment_length can be a single value or a numeric column that is greater than zero, and it is assumed to be in the same units as the input geometry. For example, if your input geometry is in a spatial reference that uses meters, and max_segment_length is specified without a unit, the max_segment_length value is in meters.

To densify geometry using geodesic distance calculation, use ST_GeodesicDensify.

FunctionSyntax
Pythondensify(geometry, max_segment_length)
SQLST_Densify(geometry, max_segment_length)
Scaladensify(geometry, maxSegmentLength)

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

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7

from geoanalytics.sql import functions as ST

df = spark.createDataFrame([("LINESTRING (0 0, 10 0)",)], ['wkt']) \
        .withColumn("line", ST.line_from_text("wkt"))

df.select(ST.densify("line", 2.5).alias("densified")).show(truncate = False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+------------------------------------------------+
|densified                                       |
+------------------------------------------------+
|{"paths":[[[0,0],[2.5,0],[5,0],[7.5,0],[10,0]]]}|
+------------------------------------------------+

Version table

ReleaseNotes

1.1.0

Python and SQL functions introduced

1.5.0

Scala function introduced

1.6.0

max_segment_length parameter accepts values specified with units

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