PostGIS

ST_GeoHash

Prev

8.9.3. Other Formats

Next

Name

ST_GeoHash — Return a GeoHash representation of the geometry.

Synopsis

text +`*`+ST_GeoHash*(`geometry `geom, integer maxchars=full_precision_of_point`)`;

Description

Return a GeoHash representation (http://en.wikipedia.org/wiki/Geohash) of the geometry. A GeoHash encodes a point into a text form that is sortable and searchable based on prefixing. A shorter GeoHash is a less precise representation of a point. It can also be thought of as a box, that contains the actual point.

If no maxchars is specified ST_GeoHash returns a GeoHash based on full precision of the input geometry type. Points return a GeoHash with 20 characters of precision (about enough to hold the full double precision of the input). Other types return a GeoHash with a variable amount of precision, based on the size of the feature. Larger features are represented with less precision, smaller features with more precision. The idea is that the box implied by the GeoHash will always contain the input feature.

If maxchars is specified ST_GeoHash returns a GeoHash with at most that many characters so a possibly lower precision representation of the input geometry. For non-points, the starting point of the calculation is the center of the bounding box of the geometry.

Availability: 1.4.0

Note

ST_GeoHash will not work with geometries that are not in geographic (lon/lat) coordinates.

check This method supports Circular Strings and Curves

Examples

SELECT ST_GeoHash(ST_SetSRID(ST_Point(-126,48),4326));

     st_geohash
----------------------
 c0w3hf1s70w3hf1s70w3

SELECT ST_GeoHash(ST_SetSRID(ST_Point(-126,48),4326),5);

 st_geohash
------------
 c0w3h

See Also