ST_BinGeometry takes a bin column and returns a polygon column. The polygon column represents the geometry of each bin.
Function | Syntax |
---|---|
Python | bin |
SQL | ST |
Scala | bin |
For more details, go to the GeoAnalytics for Microsoft Fabric API reference for bin_geometry.
Python and SQL Examples
from geoanalytics_fabric.sql import functions as ST, Polygon
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"])\
.withColumn("bin_geometry", ST.bin_geometry(ST.hex_bin("polygon", 5)))
ax = df.st.plot("polygon", facecolor="none", edgecolor="red")
df.st.plot("bin_geometry", ax=ax, facecolor="none", edgecolor="blue")
Scala Example
Scala
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)
.withColumn("bin_geometry", ST.binGeometry(ST.hexBin($"polygon", 5)))
df.select("bin_geometry").show(truncate = false)
Result
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|bin_geometry |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|{"rings":[[[5.773502691896258,0],[2.886751345948129,0],[1.4433756729740645,2.5],[2.886751345948129,5],[5.773502691896258,5],[7.216878364870323,2.5],[5.773502691896258,0]]]} |
|{"rings":[[[31.75426480542942,5],[28.86751345948129,5],[27.424137786507224,7.5],[28.86751345948129,10],[31.75426480542942,10],[33.197640478403486,7.5],[31.75426480542942,5]]]} |
|{"rings":[[[27.424137786507224,27.5],[24.537386440559096,27.5],[23.094010767585033,30],[24.537386440559096,32.5],[27.424137786507224,32.5],[28.867513459481287,30],[27.424137786507224,27.5]]]}|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |