Returns a point geometry representing the center of the region encoded by a Geohash string.
Syntax
point ST_PointFromGeoHash(text geohash, integer precision);Parameters
| Parameter | Type | Description |
|---|---|---|
geohash | text | The Geohash string to decode. |
precision | integer | The 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.
该文章对您有帮助吗?