PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 736 of file lwalgorithm.c.

737 {
738  bool is_even = 1;
739 
740  lat[0] = -90.0;
741  lat[1] = 90.0;
742  lon[0] = -180.0;
743  lon[1] = 180.0;
744 
745  size_t hashlen = strlen(geohash);
746  if (precision < 0 || (size_t)precision > hashlen)
747  {
748  precision = (int)hashlen;
749  }
750 
751  for (int i = 0; i < precision; i++)
752  {
753  char c = tolower(geohash[i]);
754 
755  /* Valid characters are all digits in base32 */
756  char *base32_pos = strchr(base32, c);
757  if (!base32_pos)
758  {
759  lwerror("%s: Invalid character '%c'", __func__, geohash[i]);
760  return;
761  }
762  char cd = base32_pos - base32;
763 
764  for (size_t j = 0; j < 5; j++)
765  {
766  const char bits[] = {16, 8, 4, 2, 1};
767  char mask = bits[j];
768  if (is_even)
769  {
770  lon[!(cd & mask)] = (lon[0] + lon[1]) / 2;
771  }
772  else
773  {
774  lat[!(cd & mask)] = (lat[0] + lat[1]) / 2;
775  }
776  is_even = !is_even;
777  }
778  }
779 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static char * base32
Definition: lwalgorithm.c:605
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.

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: