[postgis-tickets] r15661 - #3873, st_geohash drops a char for some non-point features,
Paul Ramsey
pramsey at cleverelephant.ca
Fri Sep 8 06:04:39 PDT 2017
Author: pramsey
Date: 2017-09-08 06:04:38 -0700 (Fri, 08 Sep 2017)
New Revision: 15661
Modified:
trunk/liblwgeom/cunit/cu_algorithm.c
trunk/liblwgeom/lwalgorithm.c
Log:
#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
Modified: trunk/liblwgeom/cunit/cu_algorithm.c
===================================================================
--- trunk/liblwgeom/cunit/cu_algorithm.c 2017-09-08 03:48:45 UTC (rev 15660)
+++ trunk/liblwgeom/cunit/cu_algorithm.c 2017-09-08 13:04:38 UTC (rev 15661)
@@ -788,7 +788,7 @@
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);
Modified: trunk/liblwgeom/lwalgorithm.c
===================================================================
--- trunk/liblwgeom/lwalgorithm.c 2017-09-08 03:48:45 UTC (rev 15660)
+++ trunk/liblwgeom/lwalgorithm.c 2017-09-08 13:04:38 UTC (rev 15661)
@@ -795,6 +795,19 @@
{
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 @@
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
{
More information about the postgis-tickets
mailing list