PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ disjoint()

Datum disjoint ( PG_FUNCTION_ARGS  )

Definition at line 2575 of file postgis/lwgeom_geos.c.

References error_if_srid_mismatch(), errorIfGeometryCollection(), gbox_overlaps_2d(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_is_empty(), HANDLE_GEOS_ERROR, LW_FALSE, lwgeom_geos_error(), PG_FUNCTION_INFO_V1(), POSTGIS2GEOS(), relate_pattern(), and TRUE.

Referenced by touches().

2576 {
2577  GSERIALIZED *geom1;
2578  GSERIALIZED *geom2;
2579  GEOSGeometry *g1, *g2;
2580  char result;
2581  GBOX box1, box2;
2582 
2583  geom1 = PG_GETARG_GSERIALIZED_P(0);
2584  geom2 = PG_GETARG_GSERIALIZED_P(1);
2585 
2586  errorIfGeometryCollection(geom1,geom2);
2588 
2589  /* A.Disjoint(Empty) == TRUE */
2590  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2591  PG_RETURN_BOOL(true);
2592 
2593  /*
2594  * short-circuit 1: if geom2 bounding box does not overlap
2595  * geom1 bounding box we can prematurely return TRUE.
2596  */
2597  if ( gserialized_get_gbox_p(geom1, &box1) &&
2598  gserialized_get_gbox_p(geom2, &box2) )
2599  {
2600  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
2601  {
2602  PG_RETURN_BOOL(TRUE);
2603  }
2604  }
2605 
2606  initGEOS(lwpgnotice, lwgeom_geos_error);
2607 
2608  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2609  if ( 0 == g1 ) /* exception thrown at construction */
2610  {
2611  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2612  PG_RETURN_NULL();
2613  }
2614 
2615  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2616  if ( 0 == g2 ) /* exception thrown at construction */
2617  {
2618  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2619  GEOSGeom_destroy(g1);
2620  PG_RETURN_NULL();
2621  }
2622 
2623  result = GEOSDisjoint(g1,g2);
2624 
2625  GEOSGeom_destroy(g1);
2626  GEOSGeom_destroy(g2);
2627 
2628  if (result == 2)
2629  {
2630  HANDLE_GEOS_ERROR("GEOSDisjoint");
2631  PG_RETURN_NULL(); /* never get here */
2632  }
2633 
2634  PG_FREE_IF_COPY(geom1, 0);
2635  PG_FREE_IF_COPY(geom2, 1);
2636 
2637  PG_RETURN_BOOL(result);
2638 }
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:642
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:371
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:77
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
Definition: g_box.c:335
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
#define TRUE
Definition: dbfopen.c:169
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:100
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.
Here is the call graph for this function:
Here is the caller graph for this function: