Geohash
Geohash
Main page
1324777

Geohash

logo
Community Hub0 subscribers

Wikipedia

from Wikipedia
The 6g[1] cell and its sub-grid.

Geohash is a public domain geocode system invented in 2008 by Gustavo Niemeyer[2] which encodes a geographic location into a short string of letters and digits. Similar ideas were introduced by G.M. Morton in 1966.[3] It is a hierarchical spatial data structure which subdivides space into buckets of grid shape, which is one of the many applications of what is known as a Z-order curve, and generally space-filling curves.

Geohashes offer properties like arbitrary precision and the possibility of gradually removing characters from the end of the code to reduce its size (and gradually lose precision). Geohashing guarantees that the longer a shared prefix between two geohashes is, the spatially closer they are together. The reverse of this is not guaranteed, as two points can be very close but have a short or no shared prefix.

History

[edit]

The core part of the Geohash algorithm and the first initiative to similar solution was documented in a report of G.M. Morton in 1966, "A Computer Oriented Geodetic Data Base and a New Technique in File Sequencing".[3] The Morton work was used for efficient implementations of Z-order curve, like in this modern (2014) Geohash-integer version (based on directly interleaving 64-bit integers), but his geocode proposal was not human-readable and was not popular.

Apparently, in the late 2000s, G. Niemeyer still didn't know about Morton's work, and reinvented it, adding the use of base32 representation. In February 2008, together with the announcement of the system,[2] he launched the website geohash.org, which allows users to convert geographic coordinates to short URLs which uniquely identify positions on the Earth, so that referencing them in emails, forums, and websites is more convenient.

Many variations have been developed, including OpenStreetMap's short link[4] (using base64 instead of base32) in 2009, the 64-bit Geohash[5] in 2014, the exotic Hilbert-Geohash[6] in 2016, and others.

Typical and main usages

[edit]

To obtain the Geohash, the user provides an address to be geocoded, or latitude and longitude coordinates, in a single input box (most commonly used formats for latitude and longitude pairs are accepted), and performs the request.

Besides showing the latitude and longitude corresponding to the given Geohash, users who navigate to a Geohash at geohash.org are also presented with an embedded map, and may download a GPX file, or transfer the waypoint directly to certain GPS receivers. Links are also provided to external sites that may provide further details around the specified location.

For example, the coordinate pair 57.64911,10.40744 (near the tip of the peninsula of Jutland, Denmark) produces a slightly shorter hash of u4pruydqqvj.

The main usages of Geohashes are:

  • As a unique identifier.
  • To represent point data, e.g. in databases.

Geohashes have also been proposed to be used for geotagging.

When used in a database, the structure of geohashed data has two advantages. First, data indexed by geohash will have all points for a given rectangular area in contiguous slices (the number of slices depends on the precision required and the presence of geohash "fault lines"). This is especially useful in database systems where queries on a single index are much easier or faster than multiple-index queries. Second, this index structure can be used for a quick-and-dirty proximity search: the closest points are often among the closest geohashes.

Technical description

[edit]

A formal description for computational and mathematical views.

Textual representation

[edit]

For exact latitude and longitude translations Geohash is a spatial index of base 4, because it transforms the continuous latitude and longitude space coordinates into a hierarchical discrete grid, using a recurrent four-partition of the space. To be a compact code it uses base 32 and represents its values by the following alphabet, that is the "standard textual representation".

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Base 32 0 1 2 3 4 5 6 7 8 9 b c d e f g
 
Decimal 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Base 32 h j k m n p q r s t u v w x y z

The "Geohash alphabet" (32ghs) uses all digits 0-9 and all lower case letters except "a", "i", "l" and "o".

For example, using the table above and the constant , the Geohash ezs42 can be converted to a decimal representation by ordinary positional notation:

[ezs42]32ghs =
=
=
= =

Geometrical representation

[edit]

The geometry of the Geohash has a mixed spatial representation:

  • Geohashes with 2, 4, 6, ... e digits (even digits) are represented by Z-order curve in a "regular grid" where decoded pair (latitude, longitude) has uniform uncertainty, valid as Geo URI.
  • Geohashes with 1, 3, 5, ... d digits (odd digits) are represented by "И-order curve". Latitude and longitude of the decoded pair has different uncertainty (longitude is truncated).
The curve of the grid of 32 cells was obtained merging 2 by 2 cells of the "next level" (64 cells grid illustrated here) to obtain a geometrical representation of the "odd-digit Geohash".

It is possible to build the "И-order curve" from the Z-order curve by merging neighboring cells and indexing the resulting rectangular grid by the function . The illustration shows how to obtain the grid of 32 rectangular cells from the grid of 64 square cells.

The most important property of Geohash for humans is that it preserves spatial hierarchy in the code prefixes.
For example, in the "1 Geohash digit grid" illustration of 32 rectangles, above, the spatial region of the code e (rectangle of greyish blue circle at position 4,3) is preserved with prefix e in the "2 digit grid" of 1024 rectangles (scale showing em and greyish green to blue circles at grid).

Algorithm and example

[edit]

Using the hash ezs42 as an example, here is how it is decoded into a decimal latitude and longitude. The first step is decoding it from textual "base 32ghs", as showed above, to obtain the binary representation:

.

This operation results in the bits 01101 11111 11000 00100 00010. Starting to count from the left side with the digit 0 in the first position, the digits in the even positions form the longitude code (0111110000000), while the digits in the odd positions form the latitude code (101111001001).

Each binary code is then used in a series of divisions, considering one bit at a time, again from the left to the right side. For the latitude value, the interval −90 to +90 is divided by 2, producing two intervals: −90 to 0, and 0 to +90. Since the first bit is 1, the higher interval is chosen, and becomes the current interval. The procedure is repeated for all bits in the code. Finally, the latitude value is the center of the resulting interval. Longitudes are processed in an equivalent way, keeping in mind that the initial interval is −180 to +180.

For example, in the latitude code 101111001001, the first bit is 1, so we know our latitude is somewhere between 0 and 90. Without any more bits, we'd guess the latitude was 45, giving us an error of ±45. Since more bits are available, we can continue with the next bit, and each subsequent bit halves this error. This table shows the effect of each bit. At each stage, the relevant half of the range is highlighted in green; a low bit selects the lower range, a high bit selects the upper range.

The column "mean value" shows the latitude, simply the mean value of the range. Each subsequent bit makes this value more precise.

Latitude code 101111001001
bit position bit value min mid max mean value maximum error
0 1 −90.000 0.000 90.000 45.000 45.000
1 0 0.000 45.000 90.000 22.500 22.500
2 1 0.000 22.500 45.000 33.750 11.250
3 1 22.500 33.750 45.000 39.375 5.625
4 1 33.750 39.375 45.000 42.188 2.813
5 1 39.375 42.188 45.000 43.594 1.406
6 0 42.188 43.594 45.000 42.891 0.703
7 0 42.188 42.891 43.594 42.539 0.352
8 1 42.188 42.539 42.891 42.715 0.176
9 0 42.539 42.715 42.891 42.627 0.088
10 0 42.539 42.627 42.715 42.583 0.044
11 1 42.539 42.583 42.627 42.605 0.022
Longitude code 0111110000000
bit position bit value min mid max mean value maximum error
0 0 −180.000 0.000 180.000 −90.000 90.000
1 1 −180.000 −90.000 0.000 −45.000 45.000
2 1 −90.000 −45.000 0.000 −22.500 22.500
3 1 −45.000 −22.500 0.000 −11.250 11.250
4 1 −22.500 −11.250 0.000 −5.625 5.625
5 1 −11.250 −5.625 0.000 −2.813 2.813
6 0 −5.625 −2.813 0.000 −4.219 1.406
7 0 −5.625 −4.219 −2.813 −4.922 0.703
8 0 −5.625 −4.922 −4.219 −5.273 0.352
9 0 −5.625 −5.273 −4.922 −5.449 0.176
10 0 −5.625 −5.449 −5.273 −5.537 0.088
11 0 −5.625 −5.537 −5.449 −5.581 0.044
12 0 −5.625 −5.581 −5.537 −5.603 0.022

(The numbers in the above table have been rounded to 3 decimal places for clarity)

Final rounding should be done carefully in a way that

So while rounding 42.605 to 42.61 or 42.6 is correct, rounding to 43 is not.

Digits and precision in km

[edit]
geohash length lat bits lng bits lat error lng error km error
1 2 3 ±23 ±23 ±2,500 km (1,600 mi)
2 5 5 ±2.8 ±5.6 ±630 km (390 mi)
3 7 8 ±0.70 ±0.70 ±78 km (48 mi)
4 10 10 ±0.087 ±0.18 ±20 km (12 mi)
5 12 13 ±0.022 ±0.022 ±2.4 km (1.5 mi; 2,400 m)
6 15 15 ±0.0027 ±0.0055 ±0.61 km (0.38 mi; 610 m)
7 17 18 ±0.00068 ±0.00068 ±0.076 km (0.047 mi; 76 m)
8 20 20 ±0.000085 ±0.00017 ±0.019 km (0.012 mi; 19 m)

Limitations when used for deciding proximity

[edit]

Edge cases

[edit]

Geohashes can be used to find points in proximity to each other based on a common prefix. However, edge case locations close to each other but on opposite sides of the 180 degree meridian will result in Geohash codes with no common prefix (different longitudes for near physical locations). Points close to the North and South poles will have very different geohashes (different longitudes for near physical locations).

Two close locations on either side of the Equator (or Greenwich meridian) will not have a long common prefix since they belong to different 'halves' of the world. Put simply, one location's binary latitude (or longitude) will be 011111... and the other 100000...., so they will not have a common prefix and most bits will be flipped. This can also be seen as a consequence of relying on the Z-order curve (which could more appropriately be called an N-order visit in this case) for ordering the points, as two points close by might be visited at very different times. However, two points with a long common prefix will be close by.

In order to do a proximity search, one could compute the southwest corner (low geohash with low latitude and longitude) and northeast corner (high geohash with high latitude and longitude) of a bounding box and search for geohashes between those two. This search will retrieve all points in the z-order curve between the two corners, which can be far too many points. This method also breaks down at the 180 meridians and the poles. Solr uses a filter list of prefixes, by computing the prefixes of the nearest squares close to the geohash [1].

Non-linearity

[edit]

Since a geohash (in this implementation) is based on coordinates of longitude and latitude the distance between two geohashes reflects the distance in latitude/longitude coordinates between two points, which does not translate to actual distance, see Haversine formula.

Example of non-linearity for latitude-longitude system:

  • At the Equator (0 Degrees) the length of a degree of longitude is 111.320 km, while a degree of latitude measures 110.574 km, an error of 0.67%.
  • At 30 Degrees (Mid Latitudes) the error is 110.852/96.486 = 14.89%
  • At 60 Degrees (High Arctic) the error is 111.412/55.800 = 99.67%, reaching infinity at the poles.

Note that these limitations are not due to geohashing, and not due to latitude-longitude coordinates, but due to the difficulty of mapping coordinates on a sphere (non linear and with wrapping of values, similar to modulo arithmetic) to two dimensional coordinates and the difficulty of exploring a two dimensional space uniformly. The first is related to Geographical coordinate system and Map projection, and the other to Hilbert curve and z-order curve. Once a coordinate system is found that represents points linearly in distance and wraps up at the edges, and can be explored uniformly, applying geohashing to those coordinates will not suffer from the limitations above.

While it is possible to apply geohashing to an area with a Cartesian coordinate system, it would then only apply to the area where the coordinate system applies.

Despite those issues, there are possible workarounds, and the algorithm has been successfully used in Elasticsearch,[7] MongoDB,[8] HBase, Redis,[9] and Accumulo[10] to implement proximity searches.

Similar indexing systems

[edit]
It is possible to use same base32-Geohash codes in different indexing curves. For quadrilateral tiling the Hilbert curve is the best alternative for Morton curve, used for example in the S2-geometry.
Codes with even number of digits (2, 4, ...) are mapped to regular grids, but codes of odd number (1, 3, ...) must be mapped to an irregular intermediary grid, with cells indexed by degenerated curves.

An alternative to storing Geohashes as strings in a database are Locational codes, which are also called spatial keys and similar to QuadTiles.[11][12]

In some geographical information systems and Big Data spatial databases, a Hilbert curve based indexation can be used as an alternative to Z-order curve, like in the S2 Geometry library.[13]

In 2019 a front-end was designed by QA Locate[14] in what they called GeohashPhrase[15] to use phrases to code Geohashes for easier communication via spoken English language. There were plans to make GeohashPhrase open source.[16]

Licensing

[edit]

The Geohash algorithm was put in the public domain by its inventor in a public announcement on February 26, 2008.[17]

While comparable algorithms have been successfully patented[18] and had copyright claimed upon,[19][20] GeoHash is based on an entirely different algorithm and approach.

Formal Standard

[edit]

Geohash is standardized as CTA-5009.[21]  This standard follows the Wikipedia article as of the 2023 version but provides additional detail in a formal (normative) reference. In the absence of an official specification since the creation of Geohash, the CTA WAVE organization published CTA-5009 to aid in broader adoption and compatibility across implementers in the industry.

See also

[edit]

References

[edit]
[edit]

Grokipedia

from Grokipedia
Geohash is a public domain geocoding system invented in 2008 by Gustavo Niemeyer that encodes a geographic location, specified by latitude and longitude coordinates, into a short alphanumeric string using base-32 encoding.[1][2] This encoding interleaves the binary representations of latitude and longitude values to represent a rectangular cell on Earth's surface, with the string length determining precision—shorter strings identify larger areas (up to thousands of kilometers), while longer ones pinpoint locations within meters.[3][4] The system employs a 32-character alphabet consisting of the digits 0–9 and the lowercase letters b–z excluding i, l, and o, and operates hierarchically, subdividing the globe into a grid where adjacent cells share common prefixes, enabling efficient spatial partitioning.[3][1] Geohash facilitates geospatial indexing by converting coordinates into compact, sortable keys that simplify database queries for proximity searches, range filtering, and location-based services without requiring complex geometric computations.[5] It is integrated into various technologies, including NoSQL databases like Elasticsearch for spatial data retrieval and MongoDB for efficient indexing of location data, as well as real-time applications such as location tracking in messaging platforms.[2][4] Despite its rectangular grid introducing minor distortions near poles and the date line, Geohash's simplicity and URL-friendly format have made it a foundational tool in modern geospatial computing.[3][4]

Overview

Definition and Purpose

Geohash is a public domain geocoding system that encodes geographic coordinates—specifically latitude and longitude—into a compact, hierarchical string using base-32 encoding based on a Z-order curve, which interleaves the binary representations of the coordinates to preserve spatial proximity.[3] This method transforms two-dimensional location data into a one-dimensional alphanumeric identifier, maintaining precision up to the specified length of the string without information loss within that resolution.[3] The primary purpose of Geohash is to generate short, unique identifiers for geographic points, facilitating efficient storage, querying, and sharing of location data in databases, URLs, and other systems where traditional decimal coordinates may be cumbersome.[6] By providing a human-readable and URL-safe format, it simplifies the representation of locations for practical applications such as mapping services and data exchange.[6] For example, the Geohash string "u4pruydqqvj" encodes the coordinates approximately 57.64911° N, 10.40744° E, corresponding to a location near Aarhus, Denmark, with high precision determined by its 11-character length.[3] This hierarchical structure allows for variable precision, where truncating the string coarsens the represented area while retaining the core location.[3]

Key Features and Benefits

Geohash employs a custom base-32 encoding alphabet consisting of digits 0-9 and lowercase letters b-h, j-k, m-n, and p-z, deliberately excluding a, i, l, and o to minimize visual confusion with other characters and ensure compatibility in URLs and text-based systems.[7] This design enhances human readability and reduces errors during manual entry or transcription.[7] A core feature is its hierarchical structure, where each additional character refines the location precision by subdividing the geographic area, allowing adjustable resolution based on application needs.[7] For instance, a 5-character Geohash covers approximately 4.8 km × 4.8 km, while a 9-character string achieves about ±2.4 meters accuracy on the x-axis.[7][8] Nearby locations share common prefixes in their Geohash strings, enabling efficient identification of spatial proximity through simple string comparison.[7] These attributes yield significant benefits for geospatial tasks, including compact representation that is shorter and easier to store than separate latitude and longitude coordinates.[4] The system's support for range queries via prefix matching simplifies spatial indexing in databases, avoiding the need for full coordinate computations while maintaining query efficiency.[7] Overall, Geohash facilitates easier sharing, storage, and processing of location data in human-facing and computational contexts.

History and Development

Origins and Invention

The concept underlying Geohash draws inspiration from G.M. Morton's 1966 work on Z-order curves for spatial indexing in geodetic databases, which proposed interleaving coordinates to preserve locality in file sequencing.[9] Geohash was invented by Gustavo Niemeyer in 2008 following a year of development, with the system publicly released into the public domain on February 26, 2008, via the announcement of geohash.org.[10] The initial design focused on encoding latitude and longitude pairs into short, hierarchical strings that facilitate proximity-based queries by sharing prefixes for nearby locations.[10] In its original implementation, Geohash employed base-32 encoding using the alphanumeric characters 0-9 and bcdfghjkmnpqrstvwxyz to produce compact, URL-safe strings that avoid visual confusion with letters like a, i, l, and o.[7] This choice emphasized web-friendliness, enabling easy integration into online services for location sharing and caching.[10] Early adoption milestones included the launch of geohash.org features such as embedded maps for location visualization and GPX exports for waypoints, supporting immediate use in GPS navigation tools.[10] By May 2008, the system's popularity surged through its adaptation in recreational geohashing expeditions, which relied on GPS devices to reach algorithmically generated coordinates.[11]

Variations and Extensions

One early encoding similar to Geohash, introduced in 2009, employed base64 encoding instead of the standard base32 to achieve higher character density for compact representations, particularly in systems like OpenStreetMap's short link mechanism.[12] The 64-bit Geohash, formalized around 2013-2014, extends the original encoding to use a full 64-bit integer representation by interleaving 32 bits each from quantized latitude and longitude values, enabling finer precision in fixed-length encodings suitable for database indexing.[13] In 2016, the Hilbert-Geohash variant was proposed, adapting the Hilbert space-filling curve to replace the Z-order curve in Geohash, which improves clustering of nearby points and locality preservation for geospatial queries, though it increases computational complexity.[14] A more recent extension, GeohashPhrase from 2019, maps Geohash strings to memorable natural language phrases using a predefined dictionary, facilitating human-readable location encoding while maintaining compatibility with standard Geohash decoding for applications requiring easy memorization or verbal communication.[15] Community-driven implementations have proliferated, including the Python geohash library, which provides efficient encoding, decoding, and neighbor-finding functions, supporting both string and integer representations for integration into geospatial applications and research.[16]

Technical Details

Encoding Algorithm

The Geohash encoding algorithm generates a string representation of a geographic location by interleaving the binary digits of the normalized latitude and longitude coordinates, creating a linear approximation of a Z-order (Morton) curve that preserves spatial locality to some extent. Invented by Gustavo Niemeyer in 2008 and placed in the public domain, this method recursively bisects the coordinate ranges to determine bits, which are then grouped into base-32 symbols for compactness.[17][3] The process begins by normalizing the coordinates to fit within unit intervals. For longitude λ\lambda, the normalized value is λ+180360\frac{\lambda + 180}{360}, mapping the range [-180, 180] to [0, 1]. For latitude ϕ\phi, it is ϕ+90180\frac{\phi + 90}{180}, mapping [-90, 90] to [0, 1]. To obtain the binary representation for a desired precision requiring nn total bits, each normalized value is multiplied by 2n2^n and the integer part's binary digits are extracted (discarding the fractional part to avoid floating-point precision issues in practice). However, the standard implementation uses iterative bisection to generate bits directly. For a total of n=5kn = 5k bits with kk characters, longitude receives n/2\lceil n/2 \rceil bits and latitude n/2\lfloor n/2 \rfloor bits, ensuring comparable precision in degrees despite the differing ranges.[3]
  • Initialize intervals: longitude [λmin,λmax]=[180,180][\lambda_{\min}, \lambda_{\max}] = [-180, 180], latitude [ϕmin,ϕmax]=[90,90][\phi_{\min}, \phi_{\max}] = [-90, 90].
  • For each bit position i=[0](/page/0)i = [0](/page/0) to n1n-1 (starting from the most significant bit):
    • If ii is even (0-based), bisect the longitude interval: midpoint = (λmin+λmax)/2(\lambda_{\min} + \lambda_{\max}) / 2.
      • If λ\lambda \geq midpoint, append bit 1 and set λmin=\lambda_{\min} = midpoint; else append bit 0 and set λmax=\lambda_{\max} = midpoint.
    • If ii is odd, perform the analogous bisection on the latitude interval using ϕ\phi.
  • This produces a binary string where even-indexed bits (starting from 0 as MSB) correspond to longitude and odd-indexed bits to latitude.
The resulting binary string is divided into groups of 5 bits, each converted to a decimal value (0-31) and mapped to the Geohash base-32 alphabet: 0123456789bcdefghjkmnpqrstuvwxyz (noting the omission of 'a', 'i', 'l', 'o' for readability).[3][18] For example, consider encoding the coordinates of San Francisco at ϕ=37.7749\phi = 37.7749^\circ, λ=122.4194\lambda = -122.4194^\circ to 5 characters (25 bits). The bisection process yields the binary string 0100110110010001111011110 (interleaved longitude and latitude bits, MSB to LSB). Grouping into 5-bit chunks: 01001 (9), 10110 (22 = 'q'), 01000 (8), 11110 (30 = 'y'), 11110 (30 = 'y'), yielding the geohash "9q8yy".[19][3] The binary interleaving can be formalized as follows for mlatm_\text{lat} and mlonm_\text{lon} bits per coordinate (with n=mlat+mlonn = m_\text{lat} + m_\text{lon}):
\text{lat_bits} = \left\lfloor \frac{\phi + 90}{180} \times 2^{m_\text{lat}} \right\rfloor, \quad \text{lon_bits} = \left\lfloor \frac{\lambda + 180}{360} \times 2^{m_\text{lon}} \right\rfloor
The interleaved value is constructed by merging bits starting from the MSB:
\text{hash_value} = \sum_{k=0}^{\min(m_\text{lat}, m_\text{lon})-1} \left( \text{lon_bits}[k] \times 2^{2k+1} + \text{lat_bits}[k] \times 2^{2k} \right) + \text{extra terms if } m_\text{lon} > m_\text{lat}
where bit indices are from the least significant bit (k=0 as LSB). This integer is then segmented into 5-bit fields for base-32 encoding. For the San Francisco example with mlon=13m_\text{lon}=13, mlat=12m_\text{lat}=12 (25 bits total), the process yields the binary leading to base-32 digits '9', 'q', '8', 'y', 'y'.[18]

Representations and Precision

Geohash is primarily represented as a textual string encoded in base-32 using the alphabet consisting of digits 0-9 and lowercase letters bcdfghjkmnpqrstuvwxyz, which excludes a, i, l, and o to minimize visual confusion with numerals.[20] Each character in this string corresponds to 5 bits of interleaved latitude and longitude data, allowing the full string to be decoded back into the bounding latitude and longitude coordinates of a rectangular geospatial cell.[3] At the binary level, Geohash interleaves the binary representations of the normalized latitude (ranging from -90 to 90 degrees) and longitude (ranging from -180 to 180 degrees) by alternately taking bits from each, starting with longitude.[21] This produces a compact binary string that can be packed into a 64-bit integer, facilitating efficient storage, computation, and comparison in systems like databases or spatial indexes. The spatial precision of a Geohash depends on its string length, with each additional character refining the cell size by a factor related to base-32 subdivision. Longer strings yield smaller cells and higher accuracy, though cell dimensions vary by latitude: latitude precision is uniform globally, while longitude precision decreases toward the poles due to the converging meridians. The approximate cell size in degrees can be estimated as $ 2^{-\text{digits} \cdot \log_2(32)/2} $, or roughly $ 2^{-2.5 \cdot \text{digits}} $ degrees per dimension, since each character adds 5 bits (2.5 bits on average per coordinate).[22] To convert to kilometers, multiply by Earth's mean radius of approximately 6371 km and $ \pi / 180 $ radians per degree, yielding about 111 km per degree for latitude and $ 111 \cos(\phi) $ km per degree for longitude at latitude $ \phi $.[3] The table below summarizes representative precision levels, showing approximate maximum errors (half the cell size) in kilometers or meters at the equator for illustration:
DigitsLatitude ErrorLongitude Error (at equator)
1±2,500 km±2,500 km
5±2.4 km±2.4 km
9±2.4 m±2.4 m
12±0.93 cm±1.86 cm
These values establish the scale of resolution, from continental to sub-meter accuracy, with longitude errors scaling by cosine of latitude.[3][23]

Geospatial Properties

Geometrical Structure

Geohash divides the Earth's surface into a hierarchical grid of rectangular cells through repeated binary splits of the longitude interval from -180° to 180° and the latitude interval from -90° to 90°.[3] This subdivision process encodes geographic positions by progressively narrowing the bounds around a point, forming a quadtree-like spatial hierarchy where coarser levels represent broad areas and finer levels pinpoint smaller regions.[3] The resulting structure organizes space into nested grids, with each additional geohash character refining the resolution by subdividing an existing cell into 32 subcells via base-32 encoding of interleaved binary coordinates.[3] This hierarchical refinement enables scalable spatial partitioning, where removing trailing characters coarsens the grid to larger encompassing cells, facilitating operations like range queries over variable precision levels.[24] At its core, the geometrical layout follows a Z-order curve, or Morton order, which preserves spatial locality by interleaving latitude and longitude bits such that nearby points tend to share longer common prefixes in their geohash strings.[3] However, this linearization of two-dimensional space introduces distortions, especially near cell edges, where spatially adjacent locations may receive codes with differing prefixes, potentially affecting proximity-based interpretations.[24] In visualization terms, the grid manifests as a nested partitioning where adjacent cells sharing prefixes delineate contiguous spatial zones; for example, single-character geohashes delineate 32 large global regions, each spanning thousands of kilometers and covering broad continental or oceanic expanses.[4]

Distance and Proximity Behavior

Geohash facilitates proximity detection through its prefix-sharing mechanism, where locations in the same or adjacent grid cells exhibit identical initial characters in their hash strings. A longer shared prefix corresponds to a finer subdivision of the hierarchical grid, implying greater spatial closeness and enabling efficient neighbor queries via simple string prefix matching in storage systems. This approach reduces the complexity of spatial searches to lexicographical operations, as points with matching prefixes up to a certain length are guaranteed to lie within a defined rectangular region.[3] However, the mapping from hash similarity to geographic distance exhibits non-linearity stemming from the latitude-longitude coordinate system. While intervals in latitude degrees maintain uniform north-south physical lengths of approximately 111 km per degree globally, east-west lengths for longitude degrees contract by a factor of cos(ϕ)\cos(\phi) as latitude ϕ\phi increases toward the poles, resulting in elongated cells at higher latitudes. Consequently, points with closely matching hashes may represent varying actual distances depending on their location; for instance, a fixed hash precision yields roughly square cells near the equator but increasingly narrow ones northward or southward.[3] To mitigate these inconsistencies in proximity and bounding box queries, applications often incorporate multiple neighboring geohashes—up to eight adjacent cells plus the central one—to encompass the target area comprehensively. This expansion ensures that database queries capture all relevant points within a specified radius, compensating for potential omissions due to cell boundaries or shape distortions without requiring full distance computations for every candidate.[3] For points within the same cell defined by latitude interval Δϕ\Delta \phi and longitude interval Δλ\Delta \lambda, the maximum intra-cell distance approximates the bounding box diagonal:
dmax=R(Δλcosϕ)2+(Δϕ)2 d_{\max} = R \sqrt{(\Delta \lambda \cdot \cos \phi)^2 + (\Delta \phi)^2}
where R6371R \approx 6371 km is Earth's mean radius and ϕ\phi is the cell's central latitude; this bound establishes the precision limits for proximity assumptions at a given hash length.[3]

Applications

Core Use Cases

Geohash enables geotagging by encoding latitude and longitude coordinates into compact alphanumeric strings that can be embedded directly into URLs, facilitating the creation of short links to specific map locations.[19] Originally developed in 2008 by Gustavo Niemeyer as a URL-shortening service, it allows users to generate concise, shareable identifiers for geographic points, such as through the geohash.org demonstration tool that maps these strings to visual representations.[4] This approach simplifies location sharing in web contexts by replacing lengthy coordinate pairs with human-readable, fixed-length codes. In database systems, Geohash serves as an efficient indexing mechanism for storing and querying point-based geospatial data, where the string-based representation supports prefix matching for range searches.[25] Both SQL and NoSQL databases leverage this property to perform spatial queries, such as finding all points within a bounding box, by indexing on shared prefixes that correspond to hierarchical grid cells.[4] This method reduces storage overhead and accelerates proximity-based retrieval without requiring specialized geospatial extensions in early implementations. Geohash generates unique, compact identifiers for waypoints in GPS devices and mobile applications, aiding in the organization and exchange of location data through formats like GPX.[26] Its URL-safe Base32 encoding makes it ideal for APIs in location-sharing services from the late 2000s, allowing coordinates to be transmitted as strings without encoding issues in web protocols.[19] For instance, early web services used Geohash to pass location parameters securely and efficiently in HTTP requests.[4]

Modern Integrations and Extensions

In database systems, Geohash has been natively integrated into Elasticsearch since the early 2010s to support geospatial indexing and querying of geo_point and geo_shape fields, enabling efficient aggregation of location data into grid-based buckets for applications like mapping and proximity searches.[27] Similarly, MongoDB employs Geohash encoding within its 2d indexes for planar geospatial data management, while 2dsphere indexes use a distinct encoding for spherical calculations; both facilitate operations such as $geoNear aggregations that compute distances and sort results based on location coordinates.[28][29] In IoT and real-time tracking, Geohash's compact string representation reduces data transmission size, making it suitable for low-bandwidth device location reporting in scenarios like smart cities. For instance, it has been applied to enable regional queries for traffic management using taxi trajectory data, supporting mobility prediction and congestion monitoring through geohash-tagged processing for urban traffic flow analysis.[30] Geohash serves as a key encoding method in AI and machine learning for handling geospatial data, particularly by converting coordinates into categorical features that preserve spatial hierarchy for model training. In recommendation systems, it enables proximity-aware sequential modeling, where geohash prefixes group nearby locations to improve predictions for user preferences, such as suggesting venues based on visit history.[31] Extensions like GeohashPhrase address usability gaps in post-2020 human-AI interactions by translating geohash codes into natural language phrases, such as "a young dog kicks the fancy hydrant," which encode precise locations for voice or text-based communication. This facilitates seamless integration in AI-driven interfaces for tasks like emergency reporting or service requests, where users describe positions verbally, and systems decode them to geohash grids for processing.[15]

Limitations and Challenges

Edge Cases

Geohash exhibits notable anomalies in polar regions, where latitudes approach ±90°. Due to the convergence of meridians, the longitudinal extent of cells diminishes dramatically, approaching zero width at the poles themselves. This results in extremely narrow cells in longitude, causing nearby points separated by small longitudinal differences to receive hashes with little to no shared prefix, complicating proximity-based queries that rely on prefix matching. For instance, points near the North Pole at slightly different longitudes, such as 89.999° N, 0° E and 89.999° N, 1° E, may yield divergent prefixes despite their physical closeness.[3] The International Date Line, corresponding to the 180° meridian, introduces a significant discontinuity in Geohash encoding because longitude is linearly mapped from -180° to 180°. Geographically adjacent points on opposite sides of this line, such as those at 0° latitude, 179.999° E and 0° latitude, -179.999° E (equivalent to 180.001° W), are proximal but produce hashes with dissimilar prefixes—often starting with characters like "x" on one side and "b" on the other—due to the binary representation spanning the full range of the encoding space. This boundary requires explicit special handling, such as expanding searches to include wrap-around neighbors, to ensure accurate retrieval of nearby locations.[3] Crossings of the equator and the prime meridian (0° longitude) similarly provoke abrupt changes in Geohash values during continuous movement. These lines delineate halves of the latitude and longitude encoding intervals, respectively, so points immediately on either side belong to distinct binary subspaces and thus share no common prefix. For example, locations at 0.0001° N, 0° E and 0.0001° S, 0° E, or at 50° N, -0.0001° E and 50° N, 0.0001° E, will have entirely different initial characters in their hashes, despite minimal spatial separation. This behavior stems from the hierarchical division process and necessitates careful consideration in applications involving path tracing or boundary-spanning regions.[32]

Non-Uniformity and Performance Issues

Geohash exhibits non-uniform cell sizes primarily due to the Earth's spherical geometry, where cell height remains consistent in latitude degrees across a given precision level, but cell width in longitude degrees translates to progressively smaller physical distances at higher latitudes. This results in cells becoming elongated and narrower near the poles, with the approximate physical width of a cell given by the physical height multiplied by the cosine of the latitude, leading to precision degradation in longitude that can compromise query efficiency for polar or high-latitude regions.[3] For instance, at a fixed encoding length, the same number of longitude bits covers less ground distance as latitude increases, necessitating longer hashes for equivalent spatial resolution compared to equatorial areas. In handling large datasets, Geohash supports efficient prefix-based queries for hierarchical bounding box searches, leveraging its Z-order curve structure to achieve O(log n) average-case performance akin to balanced tree indexes. However, it underperforms R-trees for exact point matches and non-rectangular range queries, as the grid-based approximation introduces space amplification—scanning oversized rectangular cells that require subsequent geometric filtering, unlike R-trees' adaptive bounding boxes. Benchmarks in PostgreSQL environments show GiST (an R-tree implementation) delivering lower query costs (0.28–29,263.75) than Geohash prefix scans (0.42–2.64) for spatial operations on sizable datasets, highlighting Geohash's limitations in scalability for precise or irregular searches.[33] A key criticism of Geohash stems from its Z-order curve's relatively poor locality preservation compared to Hilbert curves, where spatially adjacent points are less likely to share long common prefixes, resulting in clustered but not optimally proximate encodings. This inferiority increases false positives in radius-based proximity searches, as the method may retrieve distant points within the same or adjacent cells, necessitating extensive post-query verification and reducing overall efficiency. Studies comparing space-filling curves confirm Hilbert variants exhibit superior clustering properties, with lower average Levenshtein distances in locality tests (outperforming Z-order in approximately 51.8% of cases across sampled points), underscoring Geohash's drawbacks for applications demanding tight spatial correlation.[34] To address these non-uniformity and performance challenges, hybrid indexing strategies in 2020s GIS software integrate Geohash grids with R-tree mechanisms, partitioning data via coarse grid prefixes for rapid initial filtering before refining with adaptive tree-based searches to better accommodate uneven distributions and minimize false positives. Such approaches, as implemented in multi-level grid-R-tree hybrids, enhance query throughput for large-scale spatial data by balancing the simplicity of Geohash hierarchies with R-trees' precision in dynamic environments.[35]

Similar Geocoding Methods

Locational codes, also known as Morton codes, represent an early precursor to Geohash, originating from G.M. Morton's 1966 technical report on geodetic data management.[36] These codes employ binary interleaving to map two-dimensional coordinates into a one-dimensional Z-order curve, preserving spatial locality by ensuring nearby points share longer common prefixes in their binary representations.[37] Unlike Geohash, which applies base-32 encoding for human-readable strings, Morton codes remain in binary form, making them suitable for computational indexing but less intuitive for direct human use.[38] Google's Plus Codes, introduced in 2015, offer a hierarchical alphanumeric system designed to provide accessible digital addresses, particularly in regions lacking traditional street numbering.[39] Built on the open-source Open Location Code (OLC) framework announced earlier that year, Plus Codes encode latitude and longitude by alternating digits in a base-20 system (using 20 alphanumeric characters, excluding confusing ones like 'O' and 'I'), dividing the globe into progressively smaller rectangular cells starting from 20° × 20° grids and refining to about 14 cm resolution.[40] This linear hierarchical approach contrasts with Geohash's Z-order curve, as Plus Codes prioritize simplicity and shareability over strict locality preservation, allowing shortened codes (e.g., "8FVC9G8F+5W") when combined with a locality reference like a city name.[41] What3words, founded in 2013, diverges from alphanumeric encoding by assigning unique three-word phrases to each 3m × 3m square on Earth's surface, covering approximately 57 trillion locations with a proprietary dictionary of approximately 25,000 words per language (40,000 for English) across 61 languages as of 2025.[42][43] The system uses a flat grid rather than a space-filling curve like Z-order, mapping words to coordinates via a fixed algorithm that ensures no two locations share the same phrase, emphasizing memorability and ease of verbal communication over computational efficiency.[44] Open Location Code, as the underlying technology for Plus Codes, shares this non-Z-order structure but focuses on open, code-based encoding without linguistic elements, enabling offline decoding and integration into mapping tools.[41] These methods collectively highlight a spectrum of geocoding strategies, from binary Z-order foundations to accessibility-oriented alphanumeric and word-based systems.

Comparisons with Alternatives

Geohash employs a Z-order curve for mapping latitude and longitude into a linear string, offering simplicity in implementation but resulting in poorer locality preservation compared to systems like Google's S2 Geometry, which utilizes a Hilbert curve.[45] The Z-order approach in Geohash can cause spatially adjacent points to have dissimilar codes due to edge effects in the grid, leading to jumps across distant regions, whereas the Hilbert curve in S2 maintains better spatial continuity, where nearby points are more likely to share similar prefixes.[45] This makes S2 superior for applications requiring uniform spherical coverage, though its complexity in handling hierarchical cells on a projected icosphere increases development overhead relative to Geohash's straightforward string encoding.[46] In contrast to tree-based spatial indexes such as R-trees and KD-trees, Geohash provides linear storage via compact alphanumeric strings, avoiding the structural overhead of dynamic node balancing and bounding box maintenance inherent in these methods.[47] R-trees excel at handling arbitrary query radii and complex geometries like polygons by adaptively grouping features into minimum bounding rectangles, enabling efficient overlap and intersection operations, but they incur higher memory usage and slower insertion times due to frequent rebalancing.[47] KD-trees, optimized for point data, offer logarithmic search times for nearest neighbors but suffer from performance degradation in high dimensions and overlapping splits, making Geohash preferable for prefix-based bounding box queries where tree traversal costs are unnecessary.[46] Performance benchmarks indicate that Geohash is generally slower than S2 for proximity searches on large datasets due to string operations versus integer-based indexing. Regarding precision uniformity, Geohash exhibits latitude-dependent cell sizes, with distortions near the poles, while S2 and hexagonal alternatives like Uber's H3 provide more consistent resolutions across the globe.[45] Implementation ease favors Geohash, as its algorithm integrates readily into databases like PostGIS without specialized libraries, unlike the more intricate setup for R-trees or S2.[47] For use case suitability, Geohash is particularly effective for web-friendly location encoding and URL-based sharing due to its human-readable strings, whereas alternatives like H3 are better suited for analytics involving hexagonal grids, such as population density mapping or ride-sharing optimizations at Uber, where uniform neighbor connectivity reduces aggregation errors.[48] H3's integer representation also enables faster computations than Geohash's strings, making it preferable for high-volume spatial joins, though Geohash remains viable for simpler, point-based proximity tasks.[49]

Standardization

Formal Standards

Geohash entered the public domain upon its invention in 2008, enabling open development and widespread informal use that eventually prompted formal standardization efforts. In December 2023, the Consumer Technology Association (CTA), through its WAVE committee, published CTA-5009, titled "Fast and Readable Geographical Hashing," to provide a stable, authoritative specification for the system. This standard builds on established practices, offering precise algorithms for encoding and decoding while serving as a reference for registrations such as IANA CBOR tags.[50] CTA-5009 defines Geohash using a base-32 encoding alphabet comprising digits 0-9 and lowercase letters b, c, d, e, f, g, h, j, k, m, n, p, q, r, s, t, u, v, w, x, y, z, selected to minimize visual confusion between similar characters. Encoding interleaves binary representations of latitude and longitude, with each character representing 5 bits (2.5 bits per coordinate on average), resulting in rectangular regions bounded by latitude and longitude lines. The standard mandates lowercase output for encoders and recommends case-insensitive decoding for robustness, while specifying precision by hash length—for instance, a 9-character Geohash achieves approximately 2.3 meters resolution (varying by latitude). It also outlines interoperability requirements, including support for CBOR tag 301 and integration with JWT/CWT claims or CRS wrappers for coordinate reference systems.[51] Post-2023, CTA-5009 has seen adoption in geospatial standards and protocols, such as IANA's CBOR tags and references in IETF drafts for location claims, enabling consistent implementation in APIs, devices, and data exchange formats. A 2024 revision (CTA-5009-A) refined details like tag assignments and errata, further solidifying its role. These developments ensure cross-system compatibility, mitigating variations from prior informal descriptions and promoting reliable use in applications requiring geographic indexing.[52][51]

Licensing and Implementation

Geohash was placed into the public domain by its inventor, Gustavo Niemeyer, through an announcement on February 26, 2008, ensuring no restrictions on its use, modification, or distribution.[6] This open status allows developers and organizations to implement the algorithm freely without licensing fees or attribution requirements, promoting broad adoption across various applications.[53] Implementation of Geohash is facilitated by numerous open-source libraries available in popular programming languages, enabling straightforward integration into software systems. For instance, the Python library pygeohash provides functions for encoding and decoding latitude-longitude coordinates to and from Geohash strings, supporting efficient geospatial indexing.[54] Similarly, the JavaScript library js-geohash offers comparable encoding and decoding capabilities, making it suitable for web-based applications.[55] Best practices for embedding Geohash include selecting appropriate precision levels based on required accuracy—typically 5 to 12 characters for most use cases—and combining it with spatial databases for querying nearby locations, while verifying outputs against the algorithm's binary subdivision to avoid edge errors near grid boundaries.[3] The original geohash.org website serves as a key community resource, offering tools for converting coordinates to Geohash strings, generating maps, and exporting data in formats like GPX for GPS devices, which has supported experimentation and education since its launch.[6] The public domain nature eliminates barriers to such resource development, fostering a ecosystem of additional tools and extensions without legal hurdles. Following its formalization in CTA-5009 (published December 2023, revised 2024), the standard reinforces this openness by detailing the algorithm for compliant implementations while preserving the unrestricted licensing, encouraging interoperability in standards like CBOR without imposing new constraints.[56]

References

User Avatar
No comments yet.