The Geospatial Toolkit provides functions for encoding and decoding
geohashes.
The Geospatial Toolkit provides functions for encoding a geometry (points, lines, polygons, etc.)
as one or more geohashes. The resulting geohashes can be stored either as binary strings or in the
more common alphanumeric base-32 format.
Note: Encoding a geometry that spans the Prime (Greenwich)
Meridian (where longitude is zero), the poles (where longitude is undefined), or the Equator (where
latitude is 0) returns the empty string, because no single geohash can contain such a
geometry.
Geohash bit depth
The number of bits used to encode the geohash is referred to as its
bit depth. It
determines the north-south and east-west extent of a region, and the length of the generated geohash
string. More bits result in a longer geohash and a smaller region. The following table shows, for a
point near the Equator on a spherical Earth, the relationship between the number of bits used to
encode a geohash, the number of characters in the resulting base-32 string, and the dimensions and
area of a region that contains that point.
The units of length are meters and of area are square meters. Use this chart to determine the
number of bits to use with the Hangout or SpatialRouter operators. For example, for areas near the
Equator, a bit depth of 33 would result in regions of 305m x 305m.
Because this data is with reference to a point near the Equator, and because regions are narrower
(that is, their east-west extent is smaller) the further they are from the Equator, use the
following procedure to determine how many bits to use for regions at other
latitudes:
target = region_size;
latitudeInDegrees = latitude_of_point_within_area_of_interest;
adjustedExtent = target/cos(latitudeInDegrees);
double extentAtEquator = MAX(adjustedExtent, target);
Note that the procedure will not work for points at either pole (that is, when
latitudeInDegrees
is 90 or -90).
For example, assume that a region of 300m x 300m is required for a target in France, at 45.8
degrees latitude. The value of target
is 300 and of
latitudeInDegrees
is 45.8. This procedure calculates that an east-west extent of
300m at 45.8 degrees corresponds to an east-west extent of 424.26m near the Equator. In the table of
geohash bit depths, the extent value that is closest to 424.26m is 611.50m, which has a bit depth of
31.