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

Definition at line 2731 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().

2732 {
2733  GSERIALIZED *geom1;
2734  GSERIALIZED *geom2;
2735  GEOSGeometry *g1, *g2;
2736  bool result;
2737  GBOX box1, box2;
2738 
2739  geom1 = PG_GETARG_GSERIALIZED_P(0);
2740  geom2 = PG_GETARG_GSERIALIZED_P(1);
2741 
2742  errorIfGeometryCollection(geom1,geom2);
2744 
2745  /* A.Touches(Empty) == FALSE */
2746  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2747  PG_RETURN_BOOL(false);
2748 
2749  /*
2750  * short-circuit 1: if geom2 bounding box does not overlap
2751  * geom1 bounding box we can prematurely return FALSE.
2752  * Do the test IFF BOUNDING BOX AVAILABLE.
2753  */
2754  if ( gserialized_get_gbox_p(geom1, &box1) &&
2755  gserialized_get_gbox_p(geom2, &box2) )
2756  {
2757  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
2758  {
2759  PG_RETURN_BOOL(FALSE);
2760  }
2761  }
2762 
2763  initGEOS(lwpgnotice, lwgeom_geos_error);
2764 
2765  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1 );
2766  if ( 0 == g1 ) /* exception thrown at construction */
2767  {
2768  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2769  PG_RETURN_NULL();
2770  }
2771 
2772  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2 );
2773  if ( 0 == g2 ) /* exception thrown at construction */
2774  {
2775  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2776  GEOSGeom_destroy(g1);
2777  PG_RETURN_NULL();
2778  }
2779 
2780  result = GEOSTouches(g1,g2);
2781 
2782  GEOSGeom_destroy(g1);
2783  GEOSGeom_destroy(g2);
2784 
2785  if (result == 2)
2786  {
2787  HANDLE_GEOS_ERROR("GEOSTouches");
2788  PG_RETURN_NULL(); /* never get here */
2789  }
2790 
2791  PG_FREE_IF_COPY(geom1, 0);
2792  PG_FREE_IF_COPY(geom2, 1);
2793 
2794  PG_RETURN_BOOL(result);
2795 }
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: