PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 713 of file lwalgorithm.c.

References base32, and precision.

Referenced by parse_geohash().

714 {
715  int i, j, hashlen;
716  char c, cd, mask, is_even = 1;
717  static char bits[] = {16, 8, 4, 2, 1};
718 
719  lat[0] = -90.0;
720  lat[1] = 90.0;
721  lon[0] = -180.0;
722  lon[1] = 180.0;
723 
724  hashlen = strlen(geohash);
725 
726  if (precision < 0 || precision > hashlen)
727  {
728  precision = hashlen;
729  }
730 
731  for (i = 0; i < precision; i++)
732  {
733  c = tolower(geohash[i]);
734  cd = strchr(base32, c) - base32;
735 
736  for (j = 0; j < 5; j++)
737  {
738  mask = bits[j];
739  if (is_even)
740  {
741  lon[!(cd & mask)] = (lon[0] + lon[1]) / 2;
742  }
743  else
744  {
745  lat[!(cd & mask)] = (lat[0] + lat[1]) / 2;
746  }
747  is_even = !is_even;
748  }
749  }
750 }
uint8_t precision
Definition: cu_in_twkb.c:25
static char * base32
Definition: lwalgorithm.c:584
Here is the caller graph for this function: