PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum lwgeom_cmp ( PG_FUNCTION_ARGS  )

Definition at line 335 of file lwgeom_btree.c.

References BTREE_SRID_MISMATCH_SEVERITY, FPeq, gserialized_get_gbox_p(), gserialized_get_srid(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

336 {
337  GSERIALIZED *geom1 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
338  GSERIALIZED *geom2 = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
339  GBOX box1;
340  GBOX box2;
341 
342  POSTGIS_DEBUG(2, "lwgeom_cmp called");
343 
344  if (gserialized_get_srid(geom1) != gserialized_get_srid(geom2))
345  {
347  "Operation on two GEOMETRIES with different SRIDs\n");
348  PG_FREE_IF_COPY(geom1, 0);
349  PG_FREE_IF_COPY(geom2, 1);
350  PG_RETURN_NULL();
351  }
352 
353  gserialized_get_gbox_p(geom1, &box1);
354  gserialized_get_gbox_p(geom2, &box2);
355 
356  PG_FREE_IF_COPY(geom1, 0);
357  PG_FREE_IF_COPY(geom2, 1);
358 
359  if ( ! FPeq(box1.xmin , box2.xmin) )
360  {
361  if (box1.xmin < box2.xmin)
362  {
363  PG_RETURN_INT32(-1);
364  }
365  PG_RETURN_INT32(1);
366  }
367 
368  if ( ! FPeq(box1.ymin , box2.ymin) )
369  {
370  if (box1.ymin < box2.ymin)
371  {
372  PG_RETURN_INT32(-1);
373  }
374  PG_RETURN_INT32(1);
375  }
376 
377  if ( ! FPeq(box1.xmax , box2.xmax) )
378  {
379  if (box1.xmax < box2.xmax)
380  {
381  PG_RETURN_INT32(-1);
382  }
383  PG_RETURN_INT32(1);
384  }
385 
386  if ( ! FPeq(box1.ymax , box2.ymax) )
387  {
388  if (box1.ymax < box2.ymax)
389  {
390  PG_RETURN_INT32(-1);
391  }
392  PG_RETURN_INT32(1);
393  }
394 
395  PG_RETURN_INT32(0);
396 }
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
Definition: g_serialized.c:373
double xmax
Definition: liblwgeom.h:249
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
#define BTREE_SRID_MISMATCH_SEVERITY
Definition: lwgeom_btree.c:42
double ymax
Definition: liblwgeom.h:251
#define FPeq(A, B)
Definition: box2d.c:11
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:70

Here is the call graph for this function: