PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 726 of file lwalgorithm.c.

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