PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 712 of file lwalgorithm.c.

References base32, and precision.

Referenced by parse_geohash().

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