PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwgeom_cmp()

Datum lwgeom_cmp ( PG_FUNCTION_ARGS  )

Definition at line 330 of file lwgeom_btree.c.

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

Referenced by lwgeom_gt().

331 {
332  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
333  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
334  GBOX box1;
335  GBOX box2;
336  bool empty1, empty2;
337 
338  POSTGIS_DEBUG(2, "lwgeom_cmp called");
339 
341 
342  empty1 = ( gserialized_get_gbox_p(geom1, &box1) == LW_FAILURE );
343  empty2 = ( gserialized_get_gbox_p(geom2, &box2) == LW_FAILURE );
344 
345  PG_FREE_IF_COPY(geom1, 0);
346  PG_FREE_IF_COPY(geom2, 1);
347 
348  if ( empty1 || empty2 )
349  {
350  if ( empty1 && empty2 )
351  {
352  PG_RETURN_INT32(1);
353  }
354  else if ( empty1 )
355  {
356  PG_RETURN_INT32(-1);
357  }
358  else
359  {
360  PG_RETURN_INT32(1);
361  }
362  }
363 
364  if ( ! FPeq(box1.xmin , box2.xmin) )
365  {
366  if (box1.xmin < box2.xmin)
367  {
368  PG_RETURN_INT32(-1);
369  }
370  PG_RETURN_INT32(1);
371  }
372 
373  if ( ! FPeq(box1.ymin , box2.ymin) )
374  {
375  if (box1.ymin < box2.ymin)
376  {
377  PG_RETURN_INT32(-1);
378  }
379  PG_RETURN_INT32(1);
380  }
381 
382  if ( ! FPeq(box1.xmax , box2.xmax) )
383  {
384  if (box1.xmax < box2.xmax)
385  {
386  PG_RETURN_INT32(-1);
387  }
388  PG_RETURN_INT32(1);
389  }
390 
391  if ( ! FPeq(box1.ymax , box2.ymax) )
392  {
393  if (box1.ymax < box2.ymax)
394  {
395  PG_RETURN_INT32(-1);
396  }
397  PG_RETURN_INT32(1);
398  }
399 
400  PG_RETURN_INT32(0);
401 }
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:398
double xmax
Definition: liblwgeom.h:292
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
#define LW_FAILURE
Definition: liblwgeom.h:78
double ymin
Definition: liblwgeom.h:293
double xmin
Definition: liblwgeom.h:291
double ymax
Definition: liblwgeom.h:294
#define FPeq(A, B)
Definition: box2d.c:37
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:83
Here is the call graph for this function:
Here is the caller graph for this function: