PostGIS  2.1.10dev-r@@SVN_REVISION@@
static rt_errorstate rt_raster_geos_spatial_relationship ( rt_raster  rast1,
int  nband1,
rt_raster  rast2,
int  nband2,
rt_geos_spatial_test  testtype,
int *  testresult 
)
static

Definition at line 12267 of file rt_api.c.

References ES_ERROR, ES_NONE, GSR_CONTAINS, GSR_CONTAINSPROPERLY, GSR_COVEREDBY, GSR_COVERS, GSR_OVERLAPS, GSR_TOUCHES, LWGEOM2GEOS(), lwgeom_geos_error(), lwmpoly_as_lwgeom(), lwmpoly_free(), lwnotice(), RASTER_DEBUG, rt_raster_get_num_bands(), rt_raster_get_srid(), rt_raster_surface(), and rterror().

Referenced by rt_raster_contains(), rt_raster_contains_properly(), rt_raster_coveredby(), rt_raster_covers(), rt_raster_overlaps(), and rt_raster_touches().

12272  {
12273  LWMPOLY *surface1 = NULL;
12274  LWMPOLY *surface2 = NULL;
12275  GEOSGeometry *geom1 = NULL;
12276  GEOSGeometry *geom2 = NULL;
12277  int rtn = 0;
12278  int flag = 0;
12279 
12280  RASTER_DEBUG(3, "Starting");
12281 
12282  assert(NULL != rast1);
12283  assert(NULL != rast2);
12284  assert(NULL != testresult);
12285 
12286  if (nband1 < 0 && nband2 < 0) {
12287  nband1 = -1;
12288  nband2 = -1;
12289  }
12290  else {
12291  assert(nband1 >= 0 && nband1 < rt_raster_get_num_bands(rast1));
12292  assert(nband2 >= 0 && nband2 < rt_raster_get_num_bands(rast2));
12293  }
12294 
12295  /* initialize to zero, false result of spatial relationship test */
12296  *testresult = 0;
12297 
12298  /* same srid */
12299  if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
12300  rterror("rt_raster_geos_spatial_relationship: The two rasters provided have different SRIDs");
12301  return ES_ERROR;
12302  }
12303 
12304  initGEOS(lwnotice, lwgeom_geos_error);
12305 
12306  /* get LWMPOLY of each band */
12307  if (rt_raster_surface(rast1, nband1, &surface1) != ES_NONE) {
12308  rterror("rt_raster_geos_spatial_relationship: Could not get surface of the specified band from the first raster");
12309  return ES_ERROR;
12310  }
12311  if (rt_raster_surface(rast2, nband2, &surface2) != ES_NONE) {
12312  rterror("rt_raster_geos_spatial_relationship: Could not get surface of the specified band from the second raster");
12313  lwmpoly_free(surface1);
12314  return ES_ERROR;
12315  }
12316 
12317  /* either surface is NULL, spatial relationship test is false */
12318  if (surface1 == NULL || surface2 == NULL) {
12319  if (surface1 != NULL) lwmpoly_free(surface1);
12320  if (surface2 != NULL) lwmpoly_free(surface2);
12321  return ES_NONE;
12322  }
12323 
12324  /* convert LWMPOLY to GEOSGeometry */
12325  geom1 = LWGEOM2GEOS(lwmpoly_as_lwgeom(surface1));
12326  lwmpoly_free(surface1);
12327  if (geom1 == NULL) {
12328  rterror("rt_raster_geos_spatial_relationship: Could not convert surface of the specified band from the first raster to a GEOSGeometry");
12329  lwmpoly_free(surface2);
12330  return ES_ERROR;
12331  }
12332 
12333  geom2 = LWGEOM2GEOS(lwmpoly_as_lwgeom(surface2));
12334  lwmpoly_free(surface2);
12335  if (geom2 == NULL) {
12336  rterror("rt_raster_geos_spatial_relationship: Could not convert surface of the specified band from the second raster to a GEOSGeometry");
12337  return ES_ERROR;
12338  }
12339 
12340  flag = 0;
12341  switch (testtype) {
12342  case GSR_OVERLAPS:
12343  rtn = GEOSOverlaps(geom1, geom2);
12344  break;
12345  case GSR_TOUCHES:
12346  rtn = GEOSTouches(geom1, geom2);
12347  break;
12348  case GSR_CONTAINS:
12349  rtn = GEOSContains(geom1, geom2);
12350  break;
12351  case GSR_CONTAINSPROPERLY:
12352  rtn = GEOSRelatePattern(geom1, geom2, "T**FF*FF*");
12353  break;
12354  case GSR_COVERS:
12355  rtn = GEOSRelatePattern(geom1, geom2, "******FF*");
12356  break;
12357  case GSR_COVEREDBY:
12358  rtn = GEOSRelatePattern(geom1, geom2, "**F**F***");
12359  break;
12360  default:
12361  rterror("rt_raster_geos_spatial_relationship: Unknown or unsupported GEOS spatial relationship test");
12362  flag = -1;
12363  break;
12364  }
12365  GEOSGeom_destroy(geom1);
12366  GEOSGeom_destroy(geom2);
12367 
12368  /* something happened in the spatial relationship test */
12369  if (rtn == 2) {
12370  rterror("rt_raster_geos_spatial_relationship: Could not run the appropriate GEOS spatial relationship test");
12371  flag = ES_ERROR;
12372  }
12373  /* spatial relationship test ran fine */
12374  else if (flag >= 0) {
12375  if (rtn != 0)
12376  *testresult = 1;
12377  flag = ES_NONE;
12378  }
12379  /* flag < 0 for when testtype is unknown */
12380  else
12381  flag = ES_ERROR;
12382 
12383  return flag;
12384 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom)
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
#define RASTER_DEBUG(level, msg)
Definition: rt_api.h:281
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:40
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:54
void lwgeom_geos_error(const char *fmt,...)
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_api.c:13242
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:204

Here is the call graph for this function:

Here is the caller graph for this function: