ST_GeohashBin

ST_GeohashBin takes a geometry column and a numeric precision and returns a bin column. The output column contains a single Geohash bin for each record in the input column. Geohash encodes a geographic location into a short string of letters and digits. It is a hierarchical spatial data structure which subdivides space into buckets of grid shape. The specified precision determines the size of each Geohash bin.

When the input is a multipoint, linestring, or polygon geometry, ST_GeohashBin may choose a different bin than the bin chosen by other Geohash implementations.

ST_GeohashBin requires the spatial reference to be set to World Geodetic System 1984 (EPSG:4326). If the input geometry is in a different spatial reference, the function automatically transforms the geometry into World Geodetic System 1984. To learn more about spatial references, see Coordinate systems and transformations.

ST_BinGeometry can be used to obtain the geometry of the result bin. You can also use the function ST_BinId to get the id of the result bin.

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

FunctionSyntax
Pythongeohash_bin(geometry, precision)
SQLST_GeohashBin(geometry, precision)
PythongeohashBin(geometry, precision)

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

Python and SQL Examples

PythonPythonSQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

from geoanalytics_fabric.sql import functions as ST

data = [
    ('POINT (1 1)',),
    ('LINESTRING (0 0, 0 0.4, 0 0.8, 0 1)',),
    ("POLYGON ((0.5 0.5, 0.5 0.8, 0.8 0.8, 0.8 0.5, 0.5 0.5))", )
]

df = spark.createDataFrame(data, ["wkt"])\
          .withColumn("geometry", ST.geom_from_text("wkt", srid=4326))\
          .withColumn("geohash_bin", ST.geohash_bin("geometry", 5)) \
          .withColumn("bin_geometry", ST.bin_geometry("geohash_bin")) \
          .withColumn("bin_id", ST.bin_id("geohash_bin"))
df.select("bin_id").show()

ax = df.st.plot("geometry", facecolor="none", edgecolor="red")
df.st.plot("bin_geometry", ax=ax, facecolor="none", edgecolor="blue")
Result
1
2
3
4
5
6
7
+------+
|bin_id|
+------+
| s00tw|
| s004b|
| s007w|
+------+
Plotting example for ST_GeohashBin
Plotted result for ST_GeohashBin with a geometry column.
PythonPythonSQL
1
2
3
4
5
6
7
8
9

from geoanalytics_fabric.sql import functions as ST

data = [('s00wq',), ('s004b',), ('s007w',)]
df = spark.createDataFrame(data, ["bin_id"]) \
          .withColumn("geohash_bin", ST.geohash_bin("bin_id", 5)) \
          .withColumn("bin_geometry", ST.bin_geometry("geohash_bin"))

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

Scala Examples

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

import com.esri.geoanalytics.sql.{functions => ST}
import org.apache.spark.sql.{functions => F}

case class GeometryRow(wkt: String)
val data = Seq(GeometryRow("POINT (1 1)"),
               GeometryRow("LINESTRING (0 0, 0 0.4, 0 0.8, 0 1)"),
               GeometryRow("POLYGON ((0.5 0.5, 0.5 0.8, 0.8 0.8, 0.8 0.5, 0.5 0.5))"))

val df = spark.createDataFrame(data)
              .withColumn("geometry", ST.geomFromText($"wkt", F.lit(4326)))
              .withColumn("geohash_bin", ST.geohashBin($"geometry", F.lit(5)))
              .withColumn("bin_id", ST.binId($"geohash_bin"))

df.select("geohash_bin", "bin_id").show()
Result
1
2
3
4
5
6
7
+------------------+------+
|       geohash_bin|bin_id|
+------------------+------+
|bin#70746701332837| s00tw|
|bin#70368744210613| s004b|
|bin#70609262379237| s007w|
+------------------+------+
Scala
1
2
3
4
5
6
7
8
9
10
11
12

import com.esri.geoanalytics.sql.{functions => ST}

case class BinID(binID: String)
val data = Seq(BinID("s00wq"),
               BinID("s004b"),
               BinID("s007w"))

val df = spark.createDataFrame(data)
              .withColumn("geohash_bin", ST.geohashBin($"binID", F.lit(5)))

df.select("geohash_bin").show()
Result
1
2
3
4
5
6
7
+------------------+
|       geohash_bin|
+------------------+
|bin#70746701332885|
|bin#70368744210613|
|bin#70609262379237|
+------------------+

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.

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