This topic describes the GeoHash function. This function returns a Geohash string that represents a geometry object.
Syntax
text ST_GeoHash(geometry geom , integer maxchars);
Parameters
Parameter | Description |
---|---|
geom | The geometry object whose Geohash representation you want to obtain. |
maxchars | The precision based on which the Geohash string is returned. If you do not specify the maxchars parameter, this function returns a Geohash string based on the full precision of the geometry object. |
Description
- If the geometry object that you specify is not a point object, this function starts the calculation from the center of the bounding box of the geometry object.
- This function does not support geometry objects that are not in longitude- and latitude-based geographic systems.
- This function supports circular strings and curves.
Examples
- Obtain a Geohash string with the default precision retained.
SELECT ST_GeoHash(ST_GeomFromText('POINT(116 40)',4326)); st_geohash ---------------------- wx47x9u8gumnhzp791zb (1 row)
- Obtain a Geohash string with a custom precision specified.
SELECT ST_GeoHash(ST_GeomFromText('POINT(116 40)',4326),3); st_geohash ------------ wx4 (1 row)