https://github.com/yihong0618/pg_geohash
Geohash algorithm implementation in for Postgres using pgrx. It encodes/decodes a longitude-latitude tuple into/from a hashed string
https://github.com/yihong0618/pg_geohash
Last synced: 3 months ago
JSON representation
Geohash algorithm implementation in for Postgres using pgrx. It encodes/decodes a longitude-latitude tuple into/from a hashed string
- Host: GitHub
- URL: https://github.com/yihong0618/pg_geohash
- Owner: yihong0618
- License: mit
- Created: 2024-11-05T10:55:51.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-11-05T10:58:44.000Z (12 months ago)
- Last Synced: 2025-04-11T01:52:40.162Z (6 months ago)
- Language: Rust
- Size: 3.91 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg_geohash
Geohashing functionality for PostgreSQL, Greenplum and Cloudberry
## Usage
```sql
-- First create the extension
CREATE EXTENSION pg_geohash;-- Encode latitude/longitude to geohash (default precision is 12)
SELECT geohash_encode(point(-5.60302734375, 42.60498046875));
-- Returns: ezs42...-- Encode with specific precision
SELECT geohash_encode_with_precision(point(-5.60302734375, 42.60498046875), 5);
-- Returns: ezs42-- Decode geohash to lat/lon point
SELECT geohash_decode('ezs42');
-- Returns: (-5.60302734375,42.60498046875)-- Find neighboring geohash
-- direction: 0=North, 1=NorthEast, 2=East, 3=SouthEast, 4=South, 5=SouthWest, 6=West, 7=NorthWest
SELECT geohash_neighbor('ezs42', 0); -- Northern neighbor
-- Returns: ezs48SELECT geohash_neighbor('ezs42', 2); -- Eastern neighbor
-- Returns: ezs43
```## Installation
Assuming that rust toolchain is already istalled:
```sh
# install pgrx
cargo install --locked cargo-pgrx
cargo pgrx init
# build and install pg_geohash
git clone https://github.com/yihong0618/pg_geohash.git
cd pg_geohash
cargo pgrx run## source pg_config then
cargo pgrx install
```## Kudos
- https://github.com/georust/geohash
- https://github.com/pgcentralfoundation/pgrx
- https://github.com/sunng87/node-geohash