PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

void decode_geohash_bbox ( char *  geohash,
double *  lat,
double *  lon,
int  precision 
)

Definition at line 714 of file lwalgorithm.c.

715 {
716  int i, j, hashlen;
717  char c, cd, mask, is_even = 1;
718  static char bits[] = {16, 8, 4, 2, 1};
719 
720  lat[0] = -90.0;
721  lat[1] = 90.0;
722  lon[0] = -180.0;
723  lon[1] = 180.0;
724 
725  hashlen = strlen(geohash);
726 
727  if (precision < 0 || precision > hashlen)
728  {
729  precision = hashlen;
730  }
731 
732  for (i = 0; i < precision; i++)
733  {
734  c = tolower(geohash[i]);
735  /* Valid characters are all digits and letters except a, i, l and o */
736  if (!(((c >= '0') && (c <= '9')) ||
737  ((c >= 'b') && (c <= 'z') && (c != 'i') && (c != 'l') && (c != 'o'))))
738  {
739  lwerror("%s: Invalid character '%c'", __func__, geohash[i]);
740  return;
741  }
742  cd = strchr(base32, c) - base32;
743 
744  for (j = 0; j < 5; j++)
745  {
746  mask = bits[j];
747  if (is_even)
748  {
749  lon[!(cd & mask)] = (lon[0] + lon[1]) / 2;
750  }
751  else
752  {
753  lat[!(cd & mask)] = (lat[0] + lat[1]) / 2;
754  }
755  is_even = !is_even;
756  }
757  }
758 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static char * base32
Definition: lwalgorithm.c:584
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190

References base32, lwerror(), and precision.

Referenced by parse_geohash(), and test_geohash_bbox().

Here is the call graph for this function:
Here is the caller graph for this function: