PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gbox_get_sortable_hash()

uint64_t gbox_get_sortable_hash ( const GBOX g)

Return a sortable key based on the center point of the GBOX.

Definition at line 259 of file g_serialized.c.

References cart2geog(), floatuint::f, GBOX::flags, FLAGS_GET_GEODETIC, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, normalize(), floatuint::u, uint32_interleave_2(), POINT3D::x, GBOX::xmax, GBOX::xmin, POINT3D::y, GBOX::ymax, GBOX::ymin, POINT3D::z, GBOX::zmax, and GBOX::zmin.

Referenced by gserialized_cmp().

260 {
261  union floatuint x, y;
262 
263  /*
264  * Since in theory the bitwise representation of an IEEE
265  * float is sortable (exponents come before mantissa, etc)
266  * we just copy the bits directly into an int and then
267  * interleave those ints.
268  */
269  if ( FLAGS_GET_GEODETIC(g->flags) )
270  {
271  GEOGRAPHIC_POINT gpt;
272  POINT3D p;
273  p.x = (g->xmax + g->xmin) / 2.0;
274  p.y = (g->ymax + g->ymin) / 2.0;
275  p.z = (g->zmax + g->zmin) / 2.0;
276  normalize(&p);
277  cart2geog(&p, &gpt);
278  x.f = gpt.lon;
279  y.f = gpt.lat;
280  }
281  else
282  {
283  /*
284  * Here we'd like to get two ordinates from 4 in the box.
285  * Since it's just a sortable bit representation we can omit division from (A+B)/2.
286  * All it should do is subtract 1 from exponent anyways.
287  */
288  x.f = g->xmax + g->xmin;
289  y.f = g->ymax + g->ymin;
290  }
291  return uint32_interleave_2(x.u, y.u);
292 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:611
double y
Definition: liblwgeom.h:340
#define FLAGS_GET_GEODETIC(flags)
Definition: liblwgeom.h:143
double xmax
Definition: liblwgeom.h:293
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:410
double x
Definition: liblwgeom.h:340
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:52
double z
Definition: liblwgeom.h:340
double zmax
Definition: liblwgeom.h:297
double ymin
Definition: liblwgeom.h:294
static uint64_t uint32_interleave_2(uint32_t u1, uint32_t u2)
Definition: g_serialized.c:228
double xmin
Definition: liblwgeom.h:292
double ymax
Definition: liblwgeom.h:295
uint8_t flags
Definition: liblwgeom.h:291
double zmin
Definition: liblwgeom.h:296
Here is the call graph for this function:
Here is the caller graph for this function: