pg_geohash
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_geohash | 1.0 | GIS | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1590 | pg_geohash | No | Yes | No | Yes | No | Yes | - |
| Related | postgis h3 q3c pg_polyline postgis_topology postgis_raster postgis_sfcgal postgis_tiger_geocoder |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | pg_geohash | - |
| RPM | PIGSTY | 1.0 | 1817161514 | pg_geohash_$v | - |
| DEB | PIGSTY | 1.0 | 1817161514 | postgresql-$v-pg-geohash | - |
Build
You can build the RPM / DEB packages for pg_geohash using pig build:
pig build pkg pg_geohash # build RPM / DEB packages
Install
You can install pg_geohash directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_geohash; # Install for current active PG version
pig ext install -y pg_geohash -v 18 # PG 18
pig ext install -y pg_geohash -v 17 # PG 17
pig ext install -y pg_geohash -v 16 # PG 16
pig ext install -y pg_geohash -v 15 # PG 15
pig ext install -y pg_geohash -v 14 # PG 14
dnf install -y pg_geohash_18 # PG 18
dnf install -y pg_geohash_17 # PG 17
dnf install -y pg_geohash_16 # PG 16
dnf install -y pg_geohash_15 # PG 15
dnf install -y pg_geohash_14 # PG 14
apt install -y postgresql-18-pg-geohash # PG 18
apt install -y postgresql-17-pg-geohash # PG 17
apt install -y postgresql-16-pg-geohash # PG 16
apt install -y postgresql-15-pg-geohash # PG 15
apt install -y postgresql-14-pg-geohash # PG 14
Create Extension:
CREATE EXTENSION pg_geohash;
Usage
C-based geohash functions for PostgreSQL (also supports HAWQ and Greenplum). Based on the libgeohash C library.
Background on geohash: Wikipedia: Geohash
Functions
Encode latitude/longitude to a geohash string with specified precision:
SELECT LAT_LON_TO_GEOHASH_WITH_LEN(latitude, longitude, 5) AS geohash;
Encode latitude/longitude to a full-precision geohash:
SELECT LAT_LON_TO_GEOHASH(latitude, longitude) AS geohash;
Decode a geohash back to latitude/longitude:
SELECT GEOHASH_TO_LAT_LON('dp3w7') AS lat_lon;
Example
Compute geohash-based aggregates using 5-character precision (~2.4km x 4.9km cells):
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
Recover coordinates from a geohash:
SELECT location,
GEOHASH_TO_LAT_LON(LAT_LON_TO_GEOHASH(latitude, longitude))
FROM crimes
LIMIT 5;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.