[postgis-users] How to generate a map grid given a GeoHash?

Regina Obe lr at pcorp.us
Fri Dec 16 08:35:01 PST 2022


Not sure what you are looking for here, but I suspect the answer is no.  You wouldn’t get a grid. More like a set of nested squares. Geohash is not of much use except possibly for very very small grids. Even then it’s not that great.

 

Maybe you can read this to get some ideas

 

https://en.wikipedia.org/wiki/Geohash

 

 

For example this grid many of the tiles have the same geohash:

 

SELECT i, j, geom , ST_GeoHash(geom) AS geohash

FROM ST_SquareGrid(0.5, ST_MakeEnvelope(-78,38,-77, 39, 4326))

ORDER BY geohash;

 



 

You could compute a bounding box from a GeoHash with https://postgis.net/docs/ST_GeomFromGeoHash.html

 

So if I take the above and compute a bounding box based on distinct GeoHash 

 

SELECT DISTINCT ST_GeoHash(geom) AS geohash, ST_GeomFromGeoHash(ST_GeoHash(geom)) AS geom

FROM ST_SquareGrid(0.5, ST_MakeEnvelope(-78,38,-77, 39, 4326))

ORDER BY geohash;

 

I would get a result that looks like this

 



 

 

If you pick a smaller tile size such as:

SELECT DISTINCT ST_GeoHash(geom) AS geohash, ST_SetSRID(ST_GeomFromGeoHash(ST_GeoHash(geom)),4326) AS geom

FROM ST_SquareGrid(0.005, ST_MakeEnvelope(-78,38,-77, 39, 4326))

ORDER BY geohash;

 

The story is better, but still not something you can count on for gridding.  So you were right the first time you asked about there being more to it than bounding box, the shorter than bounding box hash doesn’t necessarily mean the bounding box you generated from is bigger than another bounding box located elsewhere that has a longer hash.  Also depends on position on the earth.

 



 

From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of Shaozhong SHI
Sent: Friday, December 16, 2022 8:39 AM
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
Subject: [postgis-users] How to generate a map grid given a GeoHash?

 

Can a map grid be worked out or generated given a Geohash?

 

Regards,

 

David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20221216/7238554b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 243488 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20221216/7238554b/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 35482 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20221216/7238554b/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 119023 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20221216/7238554b/attachment-0002.png>


More information about the postgis-users mailing list