Geohash Functions
Studio provides a set of functions to manipulate, process, and derive new Geohash spatial indices.
Function | Description |
---|---|
geohashToBounds(geohash , closed? ) | Returns a geojson containing the SW/NE lat/lng bounds of specified Geohash. |
geohashToGeo(geohash ) | Returns a [lat , lng ] pair representing the approximate center of the Geohash cell at reasonable precision. |
geohashToNeighbor(geohash , direction ) | Returns the adjacent Geohash cell in the given direction (N , S , E , W ). |
geohashToNeighbors(geohash ) | Returns a Geohash array containing the 8 adjacent cells to specified Geohash. |
geohashIsValid(geohash ) | Returns true if the given Geohash string is valid, or false if the Geohash string is invalid. |
geoToGeohash(lat , lng , precision? ) geoToGeohash( [lat, lng] , precision? ) | Encodes a lat/lng pair to Geohash, either to specified precision or to an automatically evaluated precision. |
Note: Arguments that end with a question mark (e.g.,
closed?
) are not required, but may be necessary for your use case.
geohashToBounds
Returns a geojson
containing the SW/NE lat/lng bounds of specified Geohash.
Method
geohashToBounds(geohash: string, closed?: boolean): geojson;
Parameters
Parameter | Type | Description |
---|---|---|
geohash | string | Geohash cell from which to derive bounds. |
closed | bool | If true , the first vertex will be duplicated at the end. |
Returns
Returns a geojson
polygon representing the bounds of the Geohash.
Example
For this example, we will call geohashtoBounds()
on a single Geohash cell. In Studio, users are expected to call functions on columns.
Create a geojson
polygon representing the bounds of Geohash cell 'u120fw'
.
geohashToBounds("u120fxw");
Returns the following geojson
object:
{
"type": "Feature",
"properties": null,
"geometry": {
"type": "Polygon",
"coordinates": [
[
[0.10986328125, 52.196044921875],
[0.10986328125, 52.2015380859375],
[0.120849609375, 52.2015380859375],
[0.120849609375, 52.196044921875],
[0.10986328125, 52.196044921875]
]
]
}
}
geohashToGeo
Derive a [lat
, lng
] pair from the approximate center of the Geohash cell at reasonable precision.
Method
geohashToGeo(geohash: string): number[];
Parameters
Parameter | Type | Description |
---|---|---|
geohash | string | Geohash cell from which to derive the approximate center point. |
Returns
Returns a [lat
, lng
] pair representing the approximate center of the Geohash cell at reasonable precision.
Example
For this example, we will call geohashToGeo()
on a single Geohash cell. In Studio, users are expected to call functions on columns.
Find the center of Geohash cell 'u120fxw'
.
geoHashToGeo("u120fxw"); // => `[52.205, 0.1188]`.
geohashToNeighbor
Find the adjacent Geohash cell in the given direction (N
, S
, E
, W
).
Method
geohashToNeighbor(geohash: string, direction: string): string;
Parameters
Parameter | Type | Description |
---|---|---|
geohash | string | Geohash cell from which to find the specified neighbor. |
direction | string | Direction to search from the specified Geohash cell ('N' /'S' /'E' /'W' ). |
Returns
Returns the adjacent Geohash cell in the given direction (N
, S
, E
, W
).
Example
For this example, we will call geohashToNeighbor()
on a single Geohash cell. In Studio, users are expected to call functions on columns.
Find the northern neighbor of Geohash cell '9q592mxz37202'
.
geohashToNeighbor("9q592mxz37202", "N"); // => `'9q592mxz37208'`
geohashToNeighbors
Find the 8 adjacent cells to specified Geohash.
Method
geohashToNeighbors(geohash: string): string[];
Parameters
Parameter | Type | Description |
---|---|---|
geohash | string | Geohash cell from which to find adjacent neighbors. |
Returns
Returns a Geohash array containing the 8 adjacent cells to specified Geohash.
Example
For this example, we will call geohashToNeighbors()
on a single Geohash cell. In Studio, users are expected to call functions on columns.
Find all adjacent neighbors of Geohash cell 'dp3w'
.
geohashToNeighbors("dp3w"); // => `[dp3x,dp3z,dp3y,dp3v,dp3t,dp3m,dp3q,dp3r]`
geohashIsValid
Determine whether the given Geohash cell is valid.
Method
geohashIsValid(value: string): boolean;
Parameters
Parameter | Type | Description |
---|---|---|
value | string | Value to test for Geohash validity. |
Returns
Returns true
if the value can be a Geohash, or false
if it is not a Geohash.
Example
For these examples, we will call geohashIsValid()
on a single Geohash cell. In Studio, users are expected to call functions on columns.
geohashIsValid(`u120fw`); // => true
geohashIsValid(`i120fw`); // => false
geoToGeohash
Encodes a lat/lng pair to Geohash, either to specified precision or to automatically evaluated precision.
Method
geoToGeohash(lngLat: number[], precision?: number): string;
Parameters
Parameter | Type | Description |
---|---|---|
lng | number | Longitude in degrees. |
lat | number | Latitude in degrees. |
lngLat | number[] | Longitude, latitude pair in an array. |
precision | number | Optional. Number of characters in resulting geohash. |
Returns
Returns a Geohash cell from the supplied latitude/longitude coordinates.
Example
For this example, we will call geoToGeohash()
on a single pair of coordinates. In Studio, users are expected to call functions on columns.
Find the Geohash cell for coordinates [0.119, 52.205]
at resolution 7 (seven Geohash digits):
geoToGeohash([0.119, 52.205], 7); // => 'u120fxw'
Find the Geohash cell for coordinate pair 0.119, 52.205
at resolution 7 (seven Geohash digits). This is the same function as the one above, except lng
and lat
are in separate columns.
geoToGeohash(0.119, 52.205, 7); // => 'u120fxw'
Find the Geohash cell for coordinates [0.119, 52.205]
at an automatic resolution:
geoToGeohash([0.119, 52.205]); // => 'u120fxwshvkg'
Updated 10 months ago