PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ rt_raster_within_distance()

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 460 of file rt_spatial_relationship.c.

465  {
466  LWMPOLY *surface = NULL;
467  LWGEOM *surface1 = NULL;
468  LWGEOM *surface2 = NULL;
469  double mindist = 0;
470 
471  RASTER_DEBUG(3, "Starting");
472 
473  assert(NULL != rast1);
474  assert(NULL != rast2);
475  assert(NULL != dwithin);
476 
477  if (nband1 < 0 && nband2 < 0) {
478  nband1 = -1;
479  nband2 = -1;
480  }
481  else {
482  assert(nband1 >= 0 && nband1 < rt_raster_get_num_bands(rast1));
483  assert(nband2 >= 0 && nband2 < rt_raster_get_num_bands(rast2));
484  }
485 
486  /* initialize to zero, false result */
487  *dwithin = 0;
488 
489  /* same srid */
490  if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
491  rterror("rt_raster_distance_within: The two rasters provided have different SRIDs");
492  return ES_ERROR;
493  }
494 
495  /* distance cannot be less than zero */
496  if (distance < 0) {
497  rterror("rt_raster_distance_within: Distance cannot be less than zero");
498  return ES_ERROR;
499  }
500 
501  /* get LWMPOLY of each band */
502  if (rt_raster_surface(rast1, nband1, &surface) != ES_NONE) {
503  rterror("rt_raster_distance_within: Could not get surface of the specified band from the first raster");
504  return ES_ERROR;
505  }
506  surface1 = lwmpoly_as_lwgeom(surface);
507 
508  if (rt_raster_surface(rast2, nband2, &surface) != ES_NONE) {
509  rterror("rt_raster_distance_within: Could not get surface of the specified band from the second raster");
510  lwgeom_free(surface1);
511  return ES_ERROR;
512  }
513  surface2 = lwmpoly_as_lwgeom(surface);
514 
515  /* either surface is NULL, test is false */
516  if (surface1 == NULL || surface2 == NULL) {
517  if (surface1 != NULL) lwgeom_free(surface1);
518  if (surface2 != NULL) lwgeom_free(surface2);
519  return ES_NONE;
520  }
521 
522  /* get the min distance between the two surfaces */
523  mindist = lwgeom_mindistance2d_tolerance(surface1, surface2, distance);
524 
525  lwgeom_free(surface1);
526  lwgeom_free(surface2);
527 
528  /* if distance >= mindist, true */
529  if (FLT_EQ(mindist, distance) || distance > mindist)
530  *dwithin = 1;
531 
532  RASTER_DEBUGF(3, "(mindist, distance) = (%f, %f, %d)", mindist, distance, *dwithin);
533 
534  return ES_NONE;
535 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:285
double lwgeom_mindistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling min distance calculations and dwithin calculations.
Definition: measures.c:213
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
#define RASTER_DEBUG(level, msg)
Definition: librtcore.h:295
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
#define FLT_EQ(x, y)
Definition: librtcore.h:2234
@ ES_NONE
Definition: librtcore.h:180
@ ES_ERROR
Definition: librtcore.h:181
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
Datum distance(PG_FUNCTION_ARGS)

References distance(), 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().

Here is the call graph for this function:
Here is the caller graph for this function: