PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ touches()

Datum touches ( PG_FUNCTION_ARGS  )

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

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

Referenced by geos_intersects().

2271 {
2272  GSERIALIZED *geom1;
2273  GSERIALIZED *geom2;
2274  GEOSGeometry *g1, *g2;
2275  char result;
2276  GBOX box1, box2;
2277 
2278  geom1 = PG_GETARG_GSERIALIZED_P(0);
2279  geom2 = PG_GETARG_GSERIALIZED_P(1);
2280 
2281  errorIfGeometryCollection(geom1,geom2);
2283 
2284  /* A.Touches(Empty) == FALSE */
2285  if ( gserialized_is_empty(geom1) || gserialized_is_empty(geom2) )
2286  PG_RETURN_BOOL(false);
2287 
2288  /*
2289  * short-circuit 1: if geom2 bounding box does not overlap
2290  * geom1 bounding box we can return FALSE.
2291  */
2292  if ( gserialized_get_gbox_p(geom1, &box1) &&
2293  gserialized_get_gbox_p(geom2, &box2) )
2294  {
2295  if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
2296  {
2297  PG_RETURN_BOOL(false);
2298  }
2299  }
2300 
2301  initGEOS(lwpgnotice, lwgeom_geos_error);
2302 
2303  g1 = POSTGIS2GEOS(geom1 );
2304  if (!g1)
2305  HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
2306 
2307  g2 = POSTGIS2GEOS(geom2 );
2308  if (!g2)
2309  {
2310  GEOSGeom_destroy(g1);
2311  HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
2312  }
2313 
2314  result = GEOSTouches(g1,g2);
2315 
2316  GEOSGeom_destroy(g1);
2317  GEOSGeom_destroy(g2);
2318 
2319  if (result == 2) HANDLE_GEOS_ERROR("GEOSTouches");
2320 
2321  PG_FREE_IF_COPY(geom1, 0);
2322  PG_FREE_IF_COPY(geom2, 1);
2323 
2324  PG_RETURN_BOOL(result);
2325 }
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:639
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:178
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:330
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:99
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: