PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geohash_point_as_int()

unsigned int geohash_point_as_int ( POINT2D pt)

Definition at line 657 of file lwalgorithm.c.

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

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

Referenced by circ_node_compare(), and test_geohash_point_as_int().

Here is the caller graph for this function: