PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 729 of file lwalgorithm.c.

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