ST_BinCenter takes a bin column and returns a point column. The point column represents the center point 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_center.
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_center", ST.bin_center(ST.square_bin("polygon", 2)))
ax = df.st.plot("polygon", facecolor="none", edgecolor="red")
df.st.plot("bin_center", 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_center", ST.binCenter(ST.squareBin($"polygon", 2)))
df.select("bin_center").show(truncate = false)
Result
+---------------+
|bin_center |
+---------------+
|{"x":5,"y":5} |
|{"x":31,"y":7} |
|{"x":25,"y":31}|
+---------------+
Version table
Release | Notes |
---|---|
1.0.0-beta | Python, SQL, and Scala functions introduced |