PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ decode_geohash_bbox()

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

Definition at line 721 of file lwalgorithm.c.

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