ST_GeodesicDensify

ST_GeodesicDensify takes a geometry column and a numeric max_segment_length value and returns a geometry column. This function adds vertices along linestrings or polygons to create densified approximations of geodesic segments with each segment being no longer than max_segment_length.

The max_segment_length can be specified with or without a unit. When specified without 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 in meters.

This function is more accurate but less performant than ST_Densify and requires that a spatial reference is set on the input geometry column. To learn more about the difference between planar and geodesic calculations, see Coordinate systems and transformations.

FunctionSyntax
Pythongeodesic_densify(geometry, max_segment_length)
SQLST_GeodesicDensify(geometry, max_segment_length)
ScalageodesicDensify(geometry, maxSegmentLength)

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

Examples

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

from geoanalytics.sql import functions as ST

LINE_WKT = 'LINESTRING (117.61983168124925 34.061452833142205, 117.43262450694835 34.198818997647145)'

df = spark.createDataFrame([(LINE_WKT,)], ['wkt']) \
        .withColumn("line", ST.line_from_text("wkt", 4326))

df.select(ST.geodesic_densify("line", 10000).alias("geodesic_densified")).show(truncate = False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|geodesic_densified                                                                                                                                                          |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|{"paths":[[[117.61983168124925,34.061452833142205],[117.55749656079557,34.10727359287857],[117.49509421655945,34.153062343775964],[117.43262450694834,34.198818997647145]]]}|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

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 with specified units

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