ST_BinGeometry

ST_BinGeometry takes a bin column and returns a polygon column. The polygon column represents the geometry of each bin.

FunctionSyntax
Pythonbin_geometry(bin)
SQLST_BinGeometry(bin)
ScalabinGeometry(bin)

For more details, go to the GeoAnalytics Engine API reference for bin_geometry.

Python and SQL Examples

PythonPythonSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14

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

Scala Example

Scala
1
2
3
4
5
6
7
8
9
10
11
12
13

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
1
2
3
4
5
6
7
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|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

ReleaseNotes

1.0.0

Python and SQL functions introduced

1.5.0

Scala function introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close