ST_GeomFromGeoHash
以指定的 GeoHash 形状返回多边形。
行为类型
不可变语法
ST_GeomFromGeoHash(GeoHash)
参数
- GeoHash
- 任意长度的有效 GeoHash 字符串。
返回
GEOGRAPHY
示例
以下示例显示了如何使用 ST_GeomFromGeoHash。
将 GeoHash 字符串转换为 Geography 对象并转换回 GeoHash
=> SELECT ST_GeoHash(ST_GeomFromGeoHash(‘vert1c9’));
ST_GeoHash
--------------------
vert1c9
(1 row)
返回指定 GeoHash 的多边形并使用 ST_AsText 将多边形、矩形图块转换为熟知文本:
=> SELECT ST_AsText(ST_GeomFromGeoHash('drt3jj9n4dpcbcdef'));
ST_AsText
------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON ((-71.1459699298 42.3945346513, -71.1459699297 42.3945346513, -71.1459699297 42.3945346513, -71.1459699298 42.3945346513, -71.1459699298 42.3945346513))
(1 row)
返回指定 GeoHash 的多个多边形及其面积。高级 GeoHash (1234) 的多边形面积很大,而低级 GeoHash (1234567890bcdefhjkmn) 的面积为零。
=> SELECT ST_Area(short) short_area, ST_AsText(short) short_WKT, ST_Area(long) long_area, ST_AsText(long) long_WKT from (SELECT ST_GeomFromGeoHash('1234') short, ST_GeomFromGeoHash('1234567890bcdefhjkmn') long) as foo;
-[ RECORD 1 ]---------------------------------------------------------------------------------------------------------------------------------------------------------------------
short_area | 24609762.8991076
short_WKT | POLYGON ((-122.34375 -88.2421875, -121.9921875 -88.2421875, -121.9921875 -88.06640625, -122.34375 -88.06640625, -122.34375 -88.2421875))
long_area | 0
long_WKT | POLYGON ((-122.196077187 -88.2297377551, -122.196077187 -88.2297377551, -122.196077187 -88.2297377551, -122.196077187 -88.2297377551, -122.196077187 -88.2297377551))