PostGIS  2.5.7dev-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.

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 }
static uint64_t uint32_interleave_2(uint32_t u1, uint32_t u2)
Definition: g_serialized.c:228
#define FLAGS_GET_GEODETIC(flags)
Definition: liblwgeom.h:143
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:615
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:414
double ymax
Definition: liblwgeom.h:298
double zmax
Definition: liblwgeom.h:300
double xmax
Definition: liblwgeom.h:296
double zmin
Definition: liblwgeom.h:299
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
uint8_t flags
Definition: liblwgeom.h:294
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:53
double z
Definition: liblwgeom.h:343
double x
Definition: liblwgeom.h:343
double y
Definition: liblwgeom.h:343

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

Referenced by gserialized_cmp(), and rect_node_cmp().

Here is the call graph for this function:
Here is the caller graph for this function: