PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 720 of file lwalgorithm.c.

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