PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 718 of file lwalgorithm.c.

719 {
720  bool is_even = 1;
721 
722  lat[0] = -90.0;
723  lat[1] = 90.0;
724  lon[0] = -180.0;
725  lon[1] = 180.0;
726 
727  size_t hashlen = strlen(geohash);
728  if (precision < 0 || (size_t)precision > hashlen)
729  {
730  precision = (int)hashlen;
731  }
732 
733  for (int i = 0; i < precision; i++)
734  {
735  char c = tolower(geohash[i]);
736 
737  /* Valid characters are all digits in base32 */
738  char *base32_pos = strchr(base32, c);
739  if (!base32_pos)
740  {
741  lwerror("%s: Invalid character '%c'", __func__, geohash[i]);
742  return;
743  }
744  char cd = base32_pos - base32;
745 
746  for (size_t j = 0; j < 5; j++)
747  {
748  const char bits[] = {16, 8, 4, 2, 1};
749  char mask = bits[j];
750  if (is_even)
751  {
752  lon[!(cd & mask)] = (lon[0] + lon[1]) / 2;
753  }
754  else
755  {
756  lat[!(cd & mask)] = (lat[0] + lat[1]) / 2;
757  }
758  is_even = !is_even;
759  }
760  }
761 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static char * base32
Definition: lwalgorithm.c:587
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: