PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geohash_point_as_int()

unsigned int geohash_point_as_int ( POINT2D pt)

Definition at line 647 of file lwalgorithm.c.

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

Referenced by circ_node_compare(), and test_geohash_point_as_int().

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