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

Definition at line 648 of file lwalgorithm.c.

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

Referenced by circ_node_compare(), and test_geohash_point_as_int().

649 {
650  int is_even=1;
651  double lat[2], lon[2], mid;
652  int bit=32;
653  unsigned int ch = 0;
654 
655  double longitude = pt->x;
656  double latitude = pt->y;
657 
658  lat[0] = -90.0;
659  lat[1] = 90.0;
660  lon[0] = -180.0;
661  lon[1] = 180.0;
662 
663  while (--bit >= 0)
664  {
665  if (is_even)
666  {
667  mid = (lon[0] + lon[1]) / 2;
668  if (longitude > mid)
669  {
670  ch |= 0x0001 << bit;
671  lon[0] = mid;
672  }
673  else
674  {
675  lon[1] = mid;
676  }
677  }
678  else
679  {
680  mid = (lat[0] + lat[1]) / 2;
681  if (latitude > mid)
682  {
683  ch |= 0x0001 << bit;
684  lat[0] = mid;
685  }
686  else
687  {
688  lat[1] = mid;
689  }
690  }
691 
692  is_even = !is_even;
693  }
694  return ch;
695 }
double x
Definition: liblwgeom.h:284
double y
Definition: liblwgeom.h:284

Here is the caller graph for this function: