PostGIS  2.2.7dev-r@@SVN_REVISION@@
unsigned int geohash_point_as_int ( POINT2D pt)

Definition at line 633 of file lwalgorithm.c.

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

Referenced by circ_node_compare(), and test_geohash_point_as_int().

634 {
635  int is_even=1;
636  double lat[2], lon[2], mid;
637  int bit=32;
638  unsigned int ch = 0;
639 
640  double longitude = pt->x;
641  double latitude = pt->y;
642 
643  lat[0] = -90.0;
644  lat[1] = 90.0;
645  lon[0] = -180.0;
646  lon[1] = 180.0;
647 
648  while (--bit >= 0)
649  {
650  if (is_even)
651  {
652  mid = (lon[0] + lon[1]) / 2;
653  if (longitude > mid)
654  {
655  ch |= 0x0001u << bit;
656  lon[0] = mid;
657  }
658  else
659  {
660  lon[1] = mid;
661  }
662  }
663  else
664  {
665  mid = (lat[0] + lat[1]) / 2;
666  if (latitude > mid)
667  {
668  ch |= 0x0001 << bit;
669  lat[0] = mid;
670  }
671  else
672  {
673  lat[1] = mid;
674  }
675  }
676 
677  is_even = !is_even;
678  }
679  return ch;
680 }
double x
Definition: liblwgeom.h:312
double y
Definition: liblwgeom.h:312

Here is the caller graph for this function: