From: Paul Ramsey Date: Fri, 8 Sep 2017 13:04:38 +0000 (+0000) Subject: #3873, st_geohash drops a char for some non-point features, X-Git-Tag: 2.4.0rc1~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d35ada3169b548f49b44630e3e38920e2ea4b47c;p=postgis #3873, st_geohash drops a char for some non-point features, due to a difference between the calculation of the correct amount of precision to return and the calculation of the effective geohash bounds of a feature git-svn-id: http://svn.osgeo.org/postgis/trunk@15661 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_algorithm.c b/liblwgeom/cunit/cu_algorithm.c index c24f38028..1acd1dcd0 100644 --- a/liblwgeom/cunit/cu_algorithm.c +++ b/liblwgeom/cunit/cu_algorithm.c @@ -788,7 +788,7 @@ static void test_geohash(void) lwline = (LWLINE*)lwgeom_from_wkt("LINESTRING(23.0 23.0,23.001 23.001)", LW_PARSER_CHECK_NONE); geohash = lwgeom_geohash((LWGEOM*)lwline,0); //printf("geohash %s\n",geohash); - CU_ASSERT_STRING_EQUAL(geohash, "ss06g7"); + CU_ASSERT_STRING_EQUAL(geohash, "ss06g7h"); lwline_free(lwline); lwfree(geohash); diff --git a/liblwgeom/lwalgorithm.c b/liblwgeom/lwalgorithm.c index 3f8404c65..f01b4a513 100644 --- a/liblwgeom/lwalgorithm.c +++ b/liblwgeom/lwalgorithm.c @@ -795,6 +795,19 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds) { lonmaxadjust = -1 * lonwidth / 2.0; } + if ( lonminadjust || lonmaxadjust ) + { + lonmin += lonminadjust; + lonmax += lonmaxadjust; + /* Each adjustment cycle corresponds to 2 bits of storage in the + ** geohash. */ + precision++; + } + else + { + break; + } + if ( miny > latmin + latwidth / 2.0 ) { latminadjust = latwidth / 2.0; @@ -804,15 +817,13 @@ int lwgeom_geohash_precision(GBOX bbox, GBOX *bounds) latmaxadjust = -1 * latwidth / 2.0; } /* Only adjust if adjustments are legal (we haven't crossed any edges). */ - if ( (lonminadjust || lonmaxadjust) && (latminadjust || latmaxadjust ) ) + if ( latminadjust || latmaxadjust ) { latmin += latminadjust; - lonmin += lonminadjust; latmax += latmaxadjust; - lonmax += lonmaxadjust; /* Each adjustment cycle corresponds to 2 bits of storage in the ** geohash. */ - precision += 2; + precision++; } else {