PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum crosses ( PG_FUNCTION_ARGS  )

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

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

2502 {
2503  GSERIALIZED *geom1;
2504  GSERIALIZED *geom2;
2505  GEOSGeometry *g1, *g2;
2506  int result;
2507  GBOX box1, box2;
2508 
2509  geom1 = PG_GETARG_GSERIALIZED_P(0);
2510  geom2 = PG_GETARG_GSERIALIZED_P(1);
2511 
2512  errorIfGeometryCollection(geom1,geom2);
2514 
2515  /* A.Crosses(Empty) == FALSE */
2516  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2517  PG_RETURN_BOOL(false);
2518 
2519  /*
2520  * short-circuit 1: if geom2 bounding box does not overlap
2521  * geom1 bounding box we can prematurely return FALSE.
2522  * Do the test IFF BOUNDING BOX AVAILABLE.
2523  */
2524  if ( gserialized_get_gbox_p(geom1, &box1) &&
2525  gserialized_get_gbox_p(geom2, &box2) )
2526  {
2527  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
2528  {
2529  PG_RETURN_BOOL(FALSE);
2530  }
2531  }
2532 
2533  initGEOS(lwpgnotice, lwgeom_geos_error);
2534 
2535  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
2536  if ( 0 == g1 ) /* exception thrown at construction */
2537  {
2538  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2539  PG_RETURN_NULL();
2540  }
2541 
2542  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
2543  if ( 0 == g2 ) /* exception thrown at construction */
2544  {
2545  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2546  GEOSGeom_destroy(g1);
2547  PG_RETURN_NULL();
2548  }
2549 
2550  result = GEOSCrosses(g1,g2);
2551 
2552  GEOSGeom_destroy(g1);
2553  GEOSGeom_destroy(g2);
2554 
2555  if (result == 2)
2556  {
2557  HANDLE_GEOS_ERROR("GEOSCrosses");
2558  PG_RETURN_NULL(); /* never get here */
2559  }
2560 
2561  PG_FREE_IF_COPY(geom1, 0);
2562  PG_FREE_IF_COPY(geom2, 1);
2563 
2564  PG_RETURN_BOOL(result);
2565 }
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:371
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:139
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:62
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:300
#define FALSE
Definition: dbfopen.c:168
GEOSGeometry * POSTGIS2GEOS(GSERIALIZED *pglwgeom)
#define HANDLE_GEOS_ERROR(label)
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:69
void errorIfGeometryCollection(GSERIALIZED *g1, GSERIALIZED *g2)
Throws an ereport ERROR if either geometry is a COLLECTIONTYPE.

Here is the call graph for this function: