ST_PointFromGeoHash

更新时间:
复制 MD 格式

Returns a point geometry representing the center of the region encoded by a Geohash string.

Syntax

point ST_PointFromGeoHash(text geohash, integer precision);

Parameters

ParameterTypeDescription
geohashtextThe Geohash string to decode.
precisionintegerThe number of characters of the Geohash string to use when computing the center point. If omitted, the full string is used.

Description

ST_PointFromGeoHash decodes a Geohash string and returns the center point of the geographic region it represents. When you specify precision, only the first precision characters of the Geohash are used, which produces the center of a larger, less precise region.

Examples

Default precision — use the full Geohash string:

SELECT ST_AsText(ST_PointFromGeoHash('wx47x9u8gumnhzp791zb'));
          st_astext
-----------------------------
 POINT(116 39.9999999999999)
(1 row)

Custom precision — use only the first 2 characters:

SELECT ST_AsText(ST_PointFromGeoHash('wx47x9u8gumnhzp791zb', 2));
       st_astext
------------------------
 POINT(118.125 42.1875)
(1 row)

Reducing precision expands the bounding region, so the returned center point shifts accordingly.