ST_GeomFromGeoHash

更新时间:
复制 MD 格式

Returns a polygon representing the bounding box of a Geohash string.

Syntax

geometry ST_GeomFromGeoHash(text geohash, integer precision)

Parameters

ParameterTypeDescription
geohashtextThe Geohash string to convert.
precisionintegerThe number of characters of the Geohash string to use when constructing the bounding box. If omitted, the full length of the Geohash string is used.

Examples

The following examples use the Geohash string wx47x9u8gumnhzp791zb, which encodes a location near Beijing.

Return a polygon using the full Geohash string:

SELECT ST_AsText(ST_GeomFromGeoHash('wx47x9u8gumnhzp791zb'));

Output:

                           st_astext
---------------------------------------------------------------
 POLYGON((116 39.9999999999999,116 40,116 40,116 39.9999999999999,116 39.9999999999999))
(1 row)

Return a polygon using the first 2 characters of the Geohash string:

SELECT ST_AsText(ST_GeomFromGeoHash('wx47x9u8gumnhzp791zb',2));

Output:

                           st_astext
---------------------------------------------------------------
 POLYGON((112.5 39.375,112.5 45,123.75 45,123.75 39.375,112.5 39.375))
(1 row)

A lower precision value produces a larger bounding box because fewer characters encode a coarser geographic area.