551{
552 const uint32_t set_count = 2;
554 int pgrastpos[2] = {-1, -1};
556 uint32_t bandindex[2] = {0};
557 uint32_t hasbandindex[2] = {0};
558
559 uint32_t i;
560 uint32_t j;
561 uint32_t k;
562 uint32_t numBands;
563 int rtn;
564 int result;
565
566 for (i = 0, j = 0; i < set_count; i++) {
567
568 if (PG_ARGISNULL(j)) {
569 for (k = 0; k < i; k++) {
571 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
572 }
573 PG_RETURN_NULL();
574 }
575 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
576 pgrastpos[i] = j;
577 j++;
578
579
581 if (!rast[i]) {
582 for (k = 0; k <= i; k++) {
583 if (k < i)
585 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
586 }
587 elog(ERROR, "RASTER_containsProperly: Could not deserialize the %s raster", i < 1 ? "first" : "second");
588 PG_RETURN_NULL();
589 }
590
591
593 if (numBands < 1) {
594 elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
595 if (i > 0) i++;
596 for (k = 0; k < i; k++) {
598 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
599 }
600 PG_RETURN_NULL();
601 }
602
603
604 if (!PG_ARGISNULL(j)) {
605 bandindex[i] = PG_GETARG_INT32(j);
606 if (bandindex[i] < 1 || bandindex[i] > numBands) {
607 elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
608 if (i > 0) i++;
609 for (k = 0; k < i; k++) {
611 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
612 }
613 PG_RETURN_NULL();
614 }
615 hasbandindex[i] = 1;
616 }
617 else
618 hasbandindex[i] = 0;
621 j++;
622 }
623
624
625 if (
626 (hasbandindex[0] && !hasbandindex[1]) ||
627 (!hasbandindex[0] && hasbandindex[1])
628 ) {
629 elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
630 for (k = 0; k < set_count; k++) {
632 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
633 }
634 PG_RETURN_NULL();
635 }
636
637
639 for (k = 0; k < set_count; k++) {
641 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
642 }
643 elog(ERROR, "The two rasters provided have different SRIDs");
644 PG_RETURN_NULL();
645 }
646
648 rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
649 rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
650 &result
651 );
652 for (k = 0; k < set_count; k++) {
654 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
655 }
656
658 elog(ERROR, "RASTER_containsProperly: Could not test that the first raster contains properly the second raster");
659 PG_RETURN_NULL();
660 }
661
662 PG_RETURN_BOOL(result);
663}
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
rt_errorstate rt_raster_contains_properly(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
#define POSTGIS_RT_DEBUGF(level, msg,...)