PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ geohash_point_as_int()

unsigned int geohash_point_as_int ( POINT2D pt)

Definition at line 656 of file lwalgorithm.c.

References POINT2D::x, and POINT2D::y.

Referenced by circ_node_compare(), and test_geohash_point_as_int().

657 {
658  int is_even=1;
659  double lat[2], lon[2], mid;
660  int bit=32;
661  unsigned int ch = 0;
662 
663  double longitude = pt->x;
664  double latitude = pt->y;
665 
666  lat[0] = -90.0;
667  lat[1] = 90.0;
668  lon[0] = -180.0;
669  lon[1] = 180.0;
670 
671  while (--bit >= 0)
672  {
673  if (is_even)
674  {
675  mid = (lon[0] + lon[1]) / 2;
676  if (longitude > mid)
677  {
678  ch |= 0x0001u << bit;
679  lon[0] = mid;
680  }
681  else
682  {
683  lon[1] = mid;
684  }
685  }
686  else
687  {
688  mid = (lat[0] + lat[1]) / 2;
689  if (latitude > mid)
690  {
691  ch |= 0x0001 << bit;
692  lat[0] = mid;
693  }
694  else
695  {
696  lat[1] = mid;
697  }
698  }
699 
700  is_even = !is_even;
701  }
702  return ch;
703 }
double x
Definition: liblwgeom.h:330
double y
Definition: liblwgeom.h:330
Here is the caller graph for this function: