PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rt_raster_fully_within_distance()

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

560 {
561 LWMPOLY *surface = NULL;
562 LWGEOM *surface1 = NULL;
563 LWGEOM *surface2 = NULL;
564 double maxdist = 0;
565
566 RASTER_DEBUG(3, "Starting");
567
568 assert(NULL != rast1);
569 assert(NULL != rast2);
570 assert(NULL != dfwithin);
571
572 if (nband1 < 0 && nband2 < 0) {
573 nband1 = -1;
574 nband2 = -1;
575 }
576 else {
577 assert(nband1 >= 0 && nband1 < rt_raster_get_num_bands(rast1));
578 assert(nband2 >= 0 && nband2 < rt_raster_get_num_bands(rast2));
579 }
580
581 /* initialize to zero, false result */
582 *dfwithin = 0;
583
584 /* same srid */
585 if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
586 rterror("rt_raster_fully_within_distance: The two rasters provided have different SRIDs");
587 return ES_ERROR;
588 }
589
590 /* distance cannot be less than zero */
591 if (distance < 0) {
592 rterror("rt_raster_fully_within_distance: Distance cannot be less than zero");
593 return ES_ERROR;
594 }
595
596 /* get LWMPOLY of each band */
597 if (rt_raster_surface(rast1, nband1, &surface) != ES_NONE) {
598 rterror("rt_raster_fully_within_distance: Could not get surface of the specified band from the first raster");
599 return ES_ERROR;
600 }
601 surface1 = lwmpoly_as_lwgeom(surface);
602
603 if (rt_raster_surface(rast2, nband2, &surface) != ES_NONE) {
604 rterror("rt_raster_fully_within_distance: Could not get surface of the specified band from the second raster");
605 lwgeom_free(surface1);
606 return ES_ERROR;
607 }
608 surface2 = lwmpoly_as_lwgeom(surface);
609
610 /* either surface is NULL, test is false */
611 if (surface1 == NULL || surface2 == NULL) {
612 if (surface1 != NULL) lwgeom_free(surface1);
613 if (surface2 != NULL) lwgeom_free(surface2);
614 return ES_NONE;
615 }
616
617 /* get the maximum distance between the two surfaces */
618 maxdist = lwgeom_maxdistance2d_tolerance(surface1, surface2, distance);
619
620 lwgeom_free(surface1);
621 lwgeom_free(surface2);
622
623 /* if distance >= maxdist, true */
624 if (FLT_EQ(maxdist, distance) || distance > maxdist)
625 *dfwithin = 1;
626
627 RASTER_DEBUGF(3, "(maxdist, distance, dfwithin) = (%f, %f, %d)", maxdist, distance, *dfwithin);
628
629 return ES_NONE;
630}
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
double lwgeom_maxdistance2d_tolerance(const LWGEOM *lw1, const LWGEOM *lw2, double tolerance)
Function handling max distance calculations and dfullywithin calculations.
Definition measures.c:192
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition lwgeom.c:322
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
Definition librtcore.h:304
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition rt_raster.c:360
#define RASTER_DEBUGF(level, msg,...)
Definition librtcore.h:308
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
#define FLT_EQ(x, y)
Definition librtcore.h:2436
@ ES_NONE
Definition librtcore.h:182
@ ES_ERROR
Definition librtcore.h:183
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:376
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032

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

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