PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_errorstate rt_raster_within_distance ( rt_raster  rast1,
int  nband1,
rt_raster  rast2,
int  nband2,
double  distance,
int *  dwithin 
)

Return ES_ERROR if error occurred in function.

Parameter dwithin returns non-zero if rast1 is within the specified distance of rast2

Parameters
rast1: the first raster whose band will be tested
nband1: the 0-based band of raster rast1 to use if value is less than zero, bands are ignored. if nband1 gte zero, nband2 must be gte zero
rast2: the second raster whose band will be tested
nband2: the 0-based band of raster rast2 to use if value is less than zero, bands are ignored if nband2 gte zero, nband1 must be gte zero
dwithin: non-zero value if rast1 is within the specified distance of rast2
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 12590 of file rt_api.c.

References ES_ERROR, ES_NONE, FLT_EQ, lwgeom_free(), lwgeom_mindistance2d_tolerance(), lwmpoly_as_lwgeom(), RASTER_DEBUG, RASTER_DEBUGF, rt_raster_get_num_bands(), rt_raster_get_srid(), rt_raster_surface(), and rterror().

Referenced by RASTER_dwithin(), and test_raster_within_distance().

12595  {
12596  LWMPOLY *surface = NULL;
12597  LWGEOM *surface1 = NULL;
12598  LWGEOM *surface2 = NULL;
12599  double mindist = 0;
12600 
12601  RASTER_DEBUG(3, "Starting");
12602 
12603  assert(NULL != rast1);
12604  assert(NULL != rast2);
12605  assert(NULL != dwithin);
12606 
12607  if (nband1 < 0 && nband2 < 0) {
12608  nband1 = -1;
12609  nband2 = -1;
12610  }
12611  else {
12612  assert(nband1 >= 0 && nband1 < rt_raster_get_num_bands(rast1));
12613  assert(nband2 >= 0 && nband2 < rt_raster_get_num_bands(rast2));
12614  }
12615 
12616  /* initialize to zero, false result */
12617  *dwithin = 0;
12618 
12619  /* same srid */
12620  if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
12621  rterror("rt_raster_distance_within: The two rasters provided have different SRIDs");
12622  return ES_ERROR;
12623  }
12624 
12625  /* distance cannot be less than zero */
12626  if (distance < 0) {
12627  rterror("rt_raster_distance_within: Distance cannot be less than zero");
12628  return ES_ERROR;
12629  }
12630 
12631  /* get LWMPOLY of each band */
12632  if (rt_raster_surface(rast1, nband1, &surface) != ES_NONE) {
12633  rterror("rt_raster_distance_within: Could not get surface of the specified band from the first raster");
12634  return ES_ERROR;
12635  }
12636  surface1 = lwmpoly_as_lwgeom(surface);
12637 
12638  if (rt_raster_surface(rast2, nband2, &surface) != ES_NONE) {
12639  rterror("rt_raster_distance_within: Could not get surface of the specified band from the second raster");
12640  lwgeom_free(surface1);
12641  return ES_ERROR;
12642  }
12643  surface2 = lwmpoly_as_lwgeom(surface);
12644 
12645  /* either surface is NULL, test is false */
12646  if (surface1 == NULL || surface2 == NULL) {
12647  if (surface1 != NULL) lwgeom_free(surface1);
12648  if (surface2 != NULL) lwgeom_free(surface2);
12649  return ES_NONE;
12650  }
12651 
12652  /* get the min distance between the two surfaces */
12653  mindist = lwgeom_mindistance2d_tolerance(surface1, surface2, distance);
12654 
12655  lwgeom_free(surface1);
12656  lwgeom_free(surface2);
12657 
12658  /* if distance >= mindist, true */
12659  if (FLT_EQ(mindist, distance) || distance > mindist)
12660  *dwithin = 1;
12661 
12662  RASTER_DEBUGF(3, "(mindist, distance) = (%f, %f, %d)", mindist, distance, *dwithin);
12663 
12664  return ES_NONE;
12665 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
double lwgeom_mindistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:173
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
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
#define RASTER_DEBUGF(level, msg,...)
Definition: rt_api.h:285
#define FLT_EQ(x, y)
Definition: rt_api.h:2159
Datum distance(PG_FUNCTION_ARGS)
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: