]> granicus.if.org Git - postgis/commitdiff
#3873, st_geohash drops a char for some non-point features,
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 8 Sep 2017 13:04:38 +0000 (13:04 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 8 Sep 2017 13:04:38 +0000 (13:04 +0000)
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

liblwgeom/cunit/cu_algorithm.c
liblwgeom/lwalgorithm.c

index c24f3802808f03386fc6b88a2a0044204c444513..1acd1dcd01c52004d6c7f1d12a51fafbd6e556f6 100644 (file)
@@ -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);
 
index 3f8404c65bcada23b098244c49e7f314dfed7b5a..f01b4a513c9b0526a9e6c758c745f6ee39d9538a 100644 (file)
@@ -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
                {