Studio provides a set of functions to manipulate, process, and derive new [Geohash](https://en.wikipedia.org/wiki/Geohash) spatial indices.

| Function | Description |
| --- | --- |
| [geohashToBounds(`geohash`, `closed?`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geohashtobounds) | Returns a `geojson` containing the SW/NE lat/lng bounds of specified Geohash. |
| [geohashToGeo(`geohash`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geohashtogeo) | Returns a [`lat`, `lng`] pair representing the approximate center of the Geohash cell at reasonable precision. |
| [geohashToNeighbor(`geohash`, `direction`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geohashtoneighbor) | Returns the adjacent Geohash cell in the given direction (`N`, `S`, `E`, `W`). |
| [geohashToNeighbors(`geohash`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geohashtoneighbors) | Returns a Geohash array containing the 8 adjacent cells to specified Geohash. |
| [geohashIsValid(`geohash`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geohashisvalid) | Returns `true` if the given Geohash string is valid, or `false` if the Geohash string is invalid. |
| [geoToGeohash(`lat`, `lng`, `precision?`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geotogeohash)<br>[geoToGeohash(`[lat, lng]`, `precision?`)](https://docs.foursquare.com/analytics-products/docs/expressions-geohash#geotogeohash) | Encodes a lat/lng pair to Geohash, either to specified precision or to an automatically evaluated precision. |

---

# geohashToBounds

Returns a `geojson` containing the SW/NE lat/lng bounds of specified Geohash.

### Method

JavaScript

```javascript
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'`.

JavaScript

```javascript
geohashToBounds("u120fxw");
```

Returns the following `geojson` object:

JSON

```json
{
  "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

JavaScript

```javascript
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'`.

JavaScript

```javascript
geoHashToGeo("u120fxw"); // => `[52.205, 0.1188]`.
```

---

# geohashToNeighbor

Find the adjacent Geohash cell in the given direction (`N`, `S`, `E`, `W`).

### Method

JavaScript

```javascript
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'`.

JavaScript

```javascript
geohashToNeighbor("9q592mxz37202", "N"); // => `'9q592mxz37208'`
```

---

# geohashToNeighbors

Find the 8 adjacent cells to specified Geohash.

### Method

JavaScript

```javascript
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'`.

JavaScript

```javascript
geohashToNeighbors("dp3w"); // => `[dp3x,dp3z,dp3y,dp3v,dp3t,dp3m,dp3q,dp3r]`
```

---

# geohashIsValid

Determine whether the given Geohash cell is valid.

### Method

JavaScript

```javascript
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.

JavaScript

```javascript
geohashIsValid(`u120fw`); // => true
```

JavaScript

```javascript
geohashIsValid(`i120fw`); // => false
```

---

# geoToGeohash

Encodes a lat/lng pair to Geohash, either to specified precision or to automatically evaluated precision.

### Method

JavaScript

```javascript
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](https://en.wikipedia.org/wiki/Geohash#Digits_and_precision_in_km) 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):

JavaScript

```javascript
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.

JavaScript

```javascript
geoToGeohash(0.119, 52.205, 7); // => 'u120fxw'
```

Find the Geohash cell for coordinates `[0.119, 52.205]` at an automatic resolution:

JavaScript

```javascript
geoToGeohash([0.119, 52.205]); // => 'u120fxwshvkg'
```
