PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ touches()

Datum touches ( PG_FUNCTION_ARGS  )

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

References disjoint(), 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(), PG_FUNCTION_INFO_V1(), and POSTGIS2GEOS().

Referenced by geos_intersects().

2438 {
2439  GSERIALIZED *geom1;
2440  GSERIALIZED *geom2;
2441  GEOSGeometry *g1, *g2;
2442  bool result;
2443  GBOX box1, box2;
2444 
2445  geom1 = PG_GETARG_GSERIALIZED_P(0);
2446  geom2 = PG_GETARG_GSERIALIZED_P(1);
2447 
2448  errorIfGeometryCollection(geom1,geom2);
2450 
2451  /* A.Touches(Empty) == FALSE */
2452  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2453  PG_RETURN_BOOL(false);
2454 
2455  /*
2456  * short-circuit 1: if geom2 bounding box does not overlap
2457  * geom1 bounding box we can prematurely return FALSE.
2458  */
2459  if ( gserialized_get_gbox_p(geom1, &box1) &&
2460  gserialized_get_gbox_p(geom2, &box2) )
2461  {
2462  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
2463  {
2464  PG_RETURN_BOOL(FALSE);
2465  }
2466  }
2467 
2468  initGEOS(lwpgnotice, lwgeom_geos_error);
2469 
2470  g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1 );
2471  if ( 0 == g1 ) /* exception thrown at construction */
2472  {
2473  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2474  PG_RETURN_NULL();
2475  }
2476 
2477  g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2 );
2478  if ( 0 == g2 ) /* exception thrown at construction */
2479  {
2480  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2481  GEOSGeom_destroy(g1);
2482  PG_RETURN_NULL();
2483  }
2484 
2485  result = GEOSTouches(g1,g2);
2486 
2487  GEOSGeom_destroy(g1);
2488  GEOSGeom_destroy(g2);
2489 
2490  if (result == 2)
2491  {
2492  HANDLE_GEOS_ERROR("GEOSTouches");
2493  PG_RETURN_NULL(); /* never get here */
2494  }
2495 
2496  PG_FREE_IF_COPY(geom1, 0);
2497  PG_FREE_IF_COPY(geom2, 1);
2498 
2499  PG_RETURN_BOOL(result);
2500 }
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
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:369
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:153
void lwgeom_geos_error(const char *fmt,...)
#define LW_FALSE
Definition: liblwgeom.h:76
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
#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:83
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: