ST_BinCenter

ST_BinCenter takes a bin column and returns a point column. The point column represents the center point of each bin.

FunctionSyntax
Pythonbin_center(bin)
SQLST_BinCenter(bin)
ScalabinCenter(bin)

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

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
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")
Plotting example for ST_BinCenter
Plotted result for ST_BinCenter.

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)
              .withColumn("bin_center", ST.binCenter(ST.squareBin($"polygon", 2)))

df.select("bin_center").show(truncate = false)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+---------------+
|bin_center     |
+---------------+
|{"x":5,"y":5}  |
|{"x":31,"y":7} |
|{"x":25,"y":31}|
+---------------+

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.