ST_SquareBin

ST_SquareBin takes a geometry column and a numeric bin size and returns a bin column. The output column contains a single square bin for 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. The centroid of the input geometry is guaranteed to intersect with the bin returned but is not necessarily coincident with the bin center. Use ST_BinGeometry to obtain the geometry of each result bin.

This function can also be called with a long column representing the ID of the bin (see ST_BinId). The bin ID will be cast to a bin column.

FunctionSyntax
Pythonsquare_bin(geometry, bin_size)
SQLST_SquareBin(geometry, bin_size)
ScalasquareBin(geometry, binSize)

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

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
# Example of square_bin with a geometry column as input
from geoanalytics_fabric.sql import functions as ST, Polygon

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

df = spark.createDataFrame(data,["polygon"]) \
          .withColumn("square_bin", ST.square_bin("polygon", 5)) \
          .withColumn("bin_geometry", ST.bin_geometry("square_bin"))
df.select("square_bin").show()

ax = df.st.plot("polygon", facecolor="none", edgecolor="red")
df.st.plot("bin_geometry", ax=ax, facecolor="none", edgecolor="blue")
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+---------------+
|     square_bin|
+---------------+
|          bin#0|
|bin#25769803777|
|bin#21474836486|
+---------------+
Plotting example for ST_SquareBin
Plotted result for ST_SquareBin with a geometry column as input.
PythonPythonSQL
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
# Example of square_bin with a long column as input
from geoanalytics_fabric.sql import functions as ST

data = [(0,), (25769803777,), (21474836486,)]
df = spark.createDataFrame(data, ["bin_id"]) \
          .withColumn("square_bin", ST.square_bin("bin_id", 5)) \
          .withColumn("bin_geometry", ST.bin_geometry("square_bin"))

ax = df.st.plot("bin_geometry", facecolor="none", edgecolor="blue")
Plotting example for ST_SquareBin with a long column as input
Plotted result for ST_SquareBin with a long column as input.

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))),
               PolygonRow(Polygon(Point(20, 30), Point(25, 35), Point(30, 30))))

val df = spark.createDataFrame(data)
             .withColumn("square_bin", ST.squareBin($"polygon", 5))

df.select("square_bin").show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+---------------+
|     square_bin|
+---------------+
|          bin#0|
|bin#25769803777|
|bin#21474836486|
+---------------+
Scala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
import com.esri.geoanalytics.sql.{functions => ST}

case class BinID(binID: String)
val data = Seq(BinID("0"),
               BinID("25769803777"),
               BinID("21474836486"))

val df = spark.createDataFrame(data)
             .withColumn("square_bin", ST.squareBin($"binID", 5))

df.select("square_bin").show()
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
+---------------+
|     square_bin|
+---------------+
|          bin#0|
|bin#25769803777|
|bin#21474836486|
+---------------+

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.