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

Return ES_ERROR if error occurred in function.

Parameter dfwithin returns non-zero if rast1 is fully 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
dfwithin: non-zero value if rast1 is fully within the specified distance of rast2
Returns
ES_NONE if success, ES_ERROR if error

Definition at line 12685 of file rt_api.c.

References ES_ERROR, ES_NONE, FLT_EQ, lwgeom_free(), lwgeom_maxdistance2d_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_dfullywithin(), and test_raster_fully_within_distance().

12690  {
12691  LWMPOLY *surface = NULL;
12692  LWGEOM *surface1 = NULL;
12693  LWGEOM *surface2 = NULL;
12694  double maxdist = 0;
12695 
12696  RASTER_DEBUG(3, "Starting");
12697 
12698  assert(NULL != rast1);
12699  assert(NULL != rast2);
12700  assert(NULL != dfwithin);
12701 
12702  if (nband1 < 0 && nband2 < 0) {
12703  nband1 = -1;
12704  nband2 = -1;
12705  }
12706  else {
12707  assert(nband1 >= 0 && nband1 < rt_raster_get_num_bands(rast1));
12708  assert(nband2 >= 0 && nband2 < rt_raster_get_num_bands(rast2));
12709  }
12710 
12711  /* initialize to zero, false result */
12712  *dfwithin = 0;
12713 
12714  /* same srid */
12715  if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
12716  rterror("rt_raster_fully_within_distance: The two rasters provided have different SRIDs");
12717  return ES_ERROR;
12718  }
12719 
12720  /* distance cannot be less than zero */
12721  if (distance < 0) {
12722  rterror("rt_raster_fully_within_distance: Distance cannot be less than zero");
12723  return ES_ERROR;
12724  }
12725 
12726  /* get LWMPOLY of each band */
12727  if (rt_raster_surface(rast1, nband1, &surface) != ES_NONE) {
12728  rterror("rt_raster_fully_within_distance: Could not get surface of the specified band from the first raster");
12729  return ES_ERROR;
12730  }
12731  surface1 = lwmpoly_as_lwgeom(surface);
12732 
12733  if (rt_raster_surface(rast2, nband2, &surface) != ES_NONE) {
12734  rterror("rt_raster_fully_within_distance: Could not get surface of the specified band from the second raster");
12735  lwgeom_free(surface1);
12736  return ES_ERROR;
12737  }
12738  surface2 = lwmpoly_as_lwgeom(surface);
12739 
12740  /* either surface is NULL, test is false */
12741  if (surface1 == NULL || surface2 == NULL) {
12742  if (surface1 != NULL) lwgeom_free(surface1);
12743  if (surface2 != NULL) lwgeom_free(surface2);
12744  return ES_NONE;
12745  }
12746 
12747  /* get the maximum distance between the two surfaces */
12748  maxdist = lwgeom_maxdistance2d_tolerance(surface1, surface2, distance);
12749 
12750  lwgeom_free(surface1);
12751  lwgeom_free(surface2);
12752 
12753  /* if distance >= maxdist, true */
12754  if (FLT_EQ(maxdist, distance) || distance > maxdist)
12755  *dfwithin = 1;
12756 
12757  RASTER_DEBUGF(3, "(maxdist, distance, dfwithin) = (%f, %f, %d)", maxdist, distance, *dfwithin);
12758 
12759  return ES_NONE;
12760 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
double lwgeom_maxdistance2d_tolerance(LWGEOM *lw1, LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfyllywithin calculations.
Definition: measures.c:141
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: