St_GeoHash: boundary handling in non-point case

Paul Ramsey pramsey at cleverelephant.ca
Fri Jan 30 11:57:37 PST 2026


It looks like just adjusting some gt/lt tests into gte/lte effects your
rount-trip test... it breaks one regression test, for ticket
https://trac.osgeo.org/postgis/ticket/4399 but that's it, and the test
isn't really pushing on geohash behaviour. I would need to add some tests
and confirm the behaviour is consistent in other ways.

P.

On Wed, Jan 28, 2026 at 9:26 AM Sztegi <sztegi at gmail.com> wrote:

> Hi!
>
> I have bumped into something I find counter intuitive with
> St_GeoHash() - boundary checking for non-point objects seems stricter
> than for points in case precision is not set:
>
> select st_geohash(ST_MakeLine(st_point(0, 0), st_point(0.00002, 0.00002)));
> -- returns "" <- this is unexpected, I expected "s00000000"
>
> This breaks my assumption that st_geoshash(st_geomfromgeohash(hash))
> will return the original geohash:
> select st_geohash(st_geomfromgeohash('s0'));
> -- returns "" <- I expected "s0"
>
> I bumped to this in Postgis 3.2.1 and it is still reproducible in 3.6.1
>
> Meanwhile if precision is set OR the geometry is a point OR it doesn't
> touch geohash boundaries then I get what I expect:
>
> select st_geohash(st_point(0, 0), 8));
> -- returns "s0000000"
>
> select st_geohash(st_point(0, 0));
> --- returns "s0000000000000000000"
>
> select st_geohash(ST_MakeLine(st_point(0, 0), st_point(0.00002, 0.00002)),
> 8);
> -- returns "s0000000"
>
> select st_geohash(ST_MakeLine(st_point(0.00001, 0.00001),
> st_point(0.00002, 0.00002)), 8);
> -- returns "s0000000"
>
> select st_geohash(ST_MakeLine(st_point(0.00001, 0.00001),
> st_point(0.00002, 0.00002)));
> -- returns "s00000000"
>
> I plan to create a bug report about this, but wanted to check first on
> the mailing list if this is something intended.
>
> These edge cases are interesting to me because I am trying to create
> an implementation of st_geohash()/st_geomfromgeohash() for two Apache
> projects (Hive, Impala), and cross- checked my tests with the results
> in postgis.
>
> regards,
> Csaba
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20260130/a14a9a44/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geohash-bounds.patch
Type: application/octet-stream
Size: 968 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20260130/a14a9a44/attachment.obj>


More information about the postgis-users mailing list