ST_HexBins

ST_HexBins takes a geometry column and a numeric bin size and returns an array column. The result array contains hexagonal bins that cover the spatial extent of each record in the input column. The specified bin size determines the height of each bin and is in the same units as the input geometry. You can optionally specify a numeric value for padding, which conceptually applies a buffer of the specified distance to the input geometry before creating the hexagonal bins.

FunctionSyntax
Pythonhex_bins(geometry, bin_size, padding=0.0)
SQLST_HexBins(geometry, bin_size, padding)
ScalaST_HexBins(geometry, binSize, padding)

For more details, go to the GeoAnalytics for Microsoft Fabric API reference for hex_bins.

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
18
19
from geoanalytics_fabric.sql import functions as ST, Polygon
from pyspark.sql import functions as F

data = [
    (Polygon([[[0,0],[0,10],[10,10],[10,0],[0,0]]]),),
    (Polygon([[[20,0],[30,20],[40,0],[20,0]]]),),
    (Polygon([[[20,30],[25,35],[30,30],[20,30]]]),)
]

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

bins = df.select(ST.hex_bins("polygon", 5, 2).alias("bins"))

bin_geometries = bins.select(F.explode("bins").alias("bin")).select(ST.bin_geometry("bin"))

ax = df.st.plot("polygon", facecolor="none", edgecolor="red")
bin_geometries.st.plot(ax=ax, facecolor="none", edgecolor="blue")
Plotting example for ST_HexBins
Plotted result for ST_HexBins.

Scala example

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

case class PolygonRow(polygon: Polygon)
val data = Seq(PolygonRow(Polygon(Point(0, 0), Point(0, 10), Point(10, 10), Point(10, 0), Point(0, 0))),
               PolygonRow(Polygon(Point(20, 0), Point(30, 20), Point(40, 0), Point(20, 0))),
               PolygonRow(Polygon(Point(20, 30), Point(25, 35), Point(30, 30), Point(20, 30))))

val df = spark.createDataFrame(data)
              .select(ST.hexBins($"polygon", 5, 2).alias("bins"))

df.select("bins").show(5)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+--------------------+
|                bins|
+--------------------+
|[bin#12884901889,...|
|[bin#25769803776,...|
|[bin#34359738374,...|
+--------------------+

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.