PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 704 of file lwalgorithm.c.

References base32, lwerror(), and precision.

Referenced by parse_geohash(), and test_geohash_bbox().

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