Skip to content

Geohash algorithm implementation in for Postgres using pgrx. It encodes/decodes a longitude-latitude tuple into/from a hashed string

License

Notifications You must be signed in to change notification settings

yihong0618/pg_geohash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg_geohash

Geohashing functionality for PostgreSQL, Greenplum and Cloudberry

Usage

-- 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: ezs48

SELECT geohash_neighbor('ezs42', 2);  -- Eastern neighbor
-- Returns: ezs43

Installation

Assuming that rust toolchain is already istalled:

# 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

About

Geohash algorithm implementation in for Postgres using pgrx. It encodes/decodes a longitude-latitude tuple into/from a hashed string

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages