ST_Buffer

ST_Buffer takes a geometry column and a numeric distance value and returns a polygon column. The resulting buffer polygons represent the area that is less than or equal to the specified planar distance from each input geometry.

The distance can be specified with or without a unit.

When specified with a unit, the distance 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 distance can be specified as a single value or a numeric column, 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, without specifying the distance unit, the distance value is in meters.

To create a buffer polygon using geodesic distance calculations use ST_GeodesicBuffer.

FunctionSyntax
Pythonbuffer(geometry, distance)
SQLST_Buffer(geometry, distance)
Scalabuffer(geometry, distance)

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

This function implements the OpenGIS Simple Features Implementation Specification for SQL 1.2.1.

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

from geoanalytics.sql import functions as ST

data = [
    ("POINT (10 30)",),
    ("MULTIPOINT (0 0, 5 5, 0 5)", ),
    ("LINESTRING (15 15, 10 15, 12 2)", ),
    ("POLYGON ((20 30, 18 28, 22 35, 40 20))", )
]

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

df = df.withColumn("buffer", ST.buffer("geometry", 2))

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

Scala Example

Scala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

import com.esri.geoanalytics.sql.{functions => ST}
import org.apache.spark.sql.{functions => F}

case class GeometryRow(wkt: String)
val data = Seq(GeometryRow("POINT (10 30)"),
               GeometryRow("MULTIPOINT (0 0, 5 5, 0 5)"),
               GeometryRow("LINESTRING (15 15, 10 15, 12 2)"),
               GeometryRow("POLYGON ((20 30, 18 28, 22 35, 40 20))"))

val df = spark.createDataFrame(data)
              .select(ST.geomFromText($"wkt").alias("geometry"))
              .withColumn("buffer", ST.buffer($"geometry", 2))
              .withColumn("buffer_area", F.round(ST.area($"buffer"), 3))


df.select("buffer", "buffer_area").show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
+--------------------+-----------+
|              buffer|buffer_area|
+--------------------+-----------+
|{"rings":[[[12,30...|     12.557|
|{"rings":[[[2,0],...|     37.672|
|{"rings":[[[12,0]...|     83.951|
|{"rings":[[[40,18...|    188.535|
+--------------------+-----------+

Version table

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

1.6.0

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