跳转到主要内容

pg_geohash

使用GeoHash处理空间坐标的函数包

pg_geohash · 使用GeoHash处理空间坐标的函数包

概览

ID扩展软件包版本类别许可证编程语言
1590pg_geohashpg_geohash1.0GISMITC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.019 18 17 16 15pg_geohash-
RPMPIGSTY1.019 18 17 16 15pg_geohash_$v-
DEBPIGSTY1.019 18 17 16 15postgresql-$v-pg-geohash-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el8.aarch64N/APIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el9.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
el10.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d12.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
d13.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u22.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u24.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.x86_64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
u26.aarch64PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0PIGSTY 1.0
软件包版本平台仓库大小下载
pg_geohash_191.0el9.x86_64pigsty26.2 KiBpg_geohash_19-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_191.0el9.aarch64pigsty25.8 KiBpg_geohash_19-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_191.0el10.x86_64pigsty26.3 KiBpg_geohash_19-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_191.0el10.aarch64pigsty26.0 KiBpg_geohash_19-1.0-5PGSTY.el10.aarch64.rpm
postgresql-19-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-19-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-19-pg-geohash1.0d13.x86_64pigsty18.4 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-19-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-19-pg-geohash1.0u22.x86_64pigsty18.4 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-19-pg-geohash1.0u22.aarch64pigsty18.0 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-19-pg-geohash1.0u24.x86_64pigsty18.5 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-19-pg-geohash1.0u24.aarch64pigsty18.2 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-19-pg-geohash1.0u26.x86_64pigsty18.5 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-19-pg-geohash1.0u26.aarch64pigsty18.3 KiBpostgresql-19-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_geohash_181.0el8.x86_64pigsty26.8 KiBpg_geohash_18-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_181.0el8.aarch64pigsty26.4 KiBpg_geohash_18-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_181.0el9.x86_64pigsty26.1 KiBpg_geohash_18-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_181.0el9.aarch64pigsty25.8 KiBpg_geohash_18-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_181.0el10.x86_64pigsty26.2 KiBpg_geohash_18-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_181.0el10.aarch64pigsty25.9 KiBpg_geohash_18-1.0-5PGSTY.el10.aarch64.rpm
postgresql-18-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-18-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-18-pg-geohash1.0d13.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-18-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-18-pg-geohash1.0u22.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-18-pg-geohash1.0u22.aarch64pigsty18.0 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-18-pg-geohash1.0u24.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-18-pg-geohash1.0u24.aarch64pigsty18.2 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-18-pg-geohash1.0u26.x86_64pigsty18.4 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-18-pg-geohash1.0u26.aarch64pigsty18.3 KiBpostgresql-18-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_geohash_171.0el8.x86_64pigsty26.8 KiBpg_geohash_17-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_171.0el8.aarch64pigsty26.4 KiBpg_geohash_17-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_171.0el9.x86_64pigsty26.1 KiBpg_geohash_17-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_171.0el9.aarch64pigsty25.8 KiBpg_geohash_17-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_171.0el10.x86_64pigsty26.2 KiBpg_geohash_17-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_171.0el10.aarch64pigsty25.9 KiBpg_geohash_17-1.0-5PGSTY.el10.aarch64.rpm
postgresql-17-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-17-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-17-pg-geohash1.0d13.x86_64pigsty18.3 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-17-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-17-pg-geohash1.0u22.x86_64pigsty18.8 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-17-pg-geohash1.0u22.aarch64pigsty18.4 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-17-pg-geohash1.0u24.x86_64pigsty18.4 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-17-pg-geohash1.0u24.aarch64pigsty18.1 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-17-pg-geohash1.0u26.x86_64pigsty18.4 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-17-pg-geohash1.0u26.aarch64pigsty18.2 KiBpostgresql-17-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_geohash_161.0el8.x86_64pigsty26.8 KiBpg_geohash_16-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_161.0el8.aarch64pigsty26.4 KiBpg_geohash_16-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_161.0el9.x86_64pigsty26.1 KiBpg_geohash_16-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_161.0el9.aarch64pigsty25.7 KiBpg_geohash_16-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_161.0el10.x86_64pigsty26.2 KiBpg_geohash_16-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_161.0el10.aarch64pigsty25.9 KiBpg_geohash_16-1.0-5PGSTY.el10.aarch64.rpm
postgresql-16-pg-geohash1.0d12.x86_64pigsty18.3 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-16-pg-geohash1.0d12.aarch64pigsty18.1 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-16-pg-geohash1.0d13.x86_64pigsty18.3 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-16-pg-geohash1.0d13.aarch64pigsty18.1 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-16-pg-geohash1.0u22.x86_64pigsty18.8 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-16-pg-geohash1.0u22.aarch64pigsty18.4 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-16-pg-geohash1.0u24.x86_64pigsty18.4 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-16-pg-geohash1.0u24.aarch64pigsty18.2 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-16-pg-geohash1.0u26.x86_64pigsty18.4 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-16-pg-geohash1.0u26.aarch64pigsty18.3 KiBpostgresql-16-pg-geohash_1.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_geohash_151.0el8.x86_64pigsty26.9 KiBpg_geohash_15-1.0-5PGSTY.el8.x86_64.rpm
pg_geohash_151.0el8.aarch64pigsty26.5 KiBpg_geohash_15-1.0-5PGSTY.el8.aarch64.rpm
pg_geohash_151.0el9.x86_64pigsty27.1 KiBpg_geohash_15-1.0-5PGSTY.el9.x86_64.rpm
pg_geohash_151.0el9.aarch64pigsty26.8 KiBpg_geohash_15-1.0-5PGSTY.el9.aarch64.rpm
pg_geohash_151.0el10.x86_64pigsty27.4 KiBpg_geohash_15-1.0-5PGSTY.el10.x86_64.rpm
pg_geohash_151.0el10.aarch64pigsty27.0 KiBpg_geohash_15-1.0-5PGSTY.el10.aarch64.rpm
postgresql-15-pg-geohash1.0d12.x86_64pigsty18.4 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~bookworm_amd64.deb
postgresql-15-pg-geohash1.0d12.aarch64pigsty18.2 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~bookworm_arm64.deb
postgresql-15-pg-geohash1.0d13.x86_64pigsty18.5 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~trixie_amd64.deb
postgresql-15-pg-geohash1.0d13.aarch64pigsty18.3 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~trixie_arm64.deb
postgresql-15-pg-geohash1.0u22.x86_64pigsty19.7 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~jammy_amd64.deb
postgresql-15-pg-geohash1.0u22.aarch64pigsty19.3 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~jammy_arm64.deb
postgresql-15-pg-geohash1.0u24.x86_64pigsty19.4 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~noble_amd64.deb
postgresql-15-pg-geohash1.0u24.aarch64pigsty19.1 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~noble_arm64.deb
postgresql-15-pg-geohash1.0u26.x86_64pigsty19.4 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~resolute_amd64.deb
postgresql-15-pg-geohash1.0u26.aarch64pigsty19.2 KiBpostgresql-15-pg-geohash_1.0-4PGSTY~resolute_arm64.deb

源码

pig build pkg pg_geohash;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_geohash;		# install by package name

pig install pg_geohash -v 19;   # install for PG 19
pig install pg_geohash -v 18;   # install for PG 18
pig install pg_geohash -v 17;   # install for PG 17
pig install pg_geohash -v 16;   # install for PG 16
pig install pg_geohash -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pg_geohash;

用法

pg_geohash: PostgreSQL 的 Geohash 函数

基于 C 实现的 PostgreSQL Geohash 函数(同时支持 HAWQ 和 Greenplum)。基于 libgeohash C 库。

Geohash 背景知识:维基百科:Geohash

函数

将经纬度编码为指定精度的 geohash 字符串:

SELECT LAT_LON_TO_GEOHASH_WITH_LEN(latitude, longitude, 5) AS geohash;

将经纬度编码为全精度的 geohash:

SELECT LAT_LON_TO_GEOHASH(latitude, longitude) AS geohash;

将 geohash 解码回经纬度:

SELECT GEOHASH_TO_LAT_LON('dp3w7') AS lat_lon;

示例

使用 5 字符精度(约 2.4km x 4.9km 网格)计算基于 geohash 的聚合:

SELECT LAT_LON_TO_GEOHASH_WITH_LEN(latitude, longitude, 5) AS geohash,
       COUNT(*)
FROM crimes
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;
 geohash | count
---------+-------
 dp3w7   | 72404
 dp3tt   | 70713
 dp3tw   | 63642
 dp3wm   | 62332
 dp3wk   | 56467

从 geohash 恢复坐标:

SELECT location,
       GEOHASH_TO_LAT_LON(LAT_LON_TO_GEOHASH(latitude, longitude))
FROM crimes
LIMIT 5;

表格阅读器