555{
556 const uint32_t set_count = 2;
558 int pgrastpos[2] = {-1, -1};
560 uint32_t bandindex[2] = {0};
561 uint32_t hasbandindex[2] = {0};
562
563 uint32_t i;
564 uint32_t j;
565 uint32_t k;
566 uint32_t numBands;
567 int rtn;
569
570 for (i = 0, j = 0; i < set_count; i++) {
571
572 if (PG_ARGISNULL(j)) {
573 for (k = 0; k < i; k++) {
575 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
576 }
577 PG_RETURN_NULL();
578 }
579 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
580 pgrastpos[i] = j;
581 j++;
582
583
585 if (!rast[i]) {
586 for (k = 0; k <= i; k++) {
587 if (k < i)
589 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
590 }
591 elog(ERROR, "RASTER_containsProperly: Could not deserialize the %s raster", i < 1 ? "first" : "second");
592 PG_RETURN_NULL();
593 }
594
595
597 if (numBands < 1) {
598 elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
599 if (i > 0) i++;
600 for (k = 0; k < i; k++) {
602 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
603 }
604 PG_RETURN_NULL();
605 }
606
607
608 if (!PG_ARGISNULL(j)) {
609 bandindex[i] = PG_GETARG_INT32(j);
610 if (bandindex[i] < 1 || bandindex[i] > numBands) {
611 elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
612 if (i > 0) i++;
613 for (k = 0; k < i; k++) {
615 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
616 }
617 PG_RETURN_NULL();
618 }
619 hasbandindex[i] = 1;
620 }
621 else
622 hasbandindex[i] = 0;
625 j++;
626 }
627
628
629 if (
630 (hasbandindex[0] && !hasbandindex[1]) ||
631 (!hasbandindex[0] && hasbandindex[1])
632 ) {
633 elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
634 for (k = 0; k < set_count; k++) {
636 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
637 }
638 PG_RETURN_NULL();
639 }
640
641
643 for (k = 0; k < set_count; k++) {
645 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
646 }
647 elog(ERROR, "The two rasters provided have different SRIDs");
648 PG_RETURN_NULL();
649 }
650
652 rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
653 rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
655 );
656 for (k = 0; k < set_count; k++) {
658 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
659 }
660
662 elog(ERROR, "RASTER_containsProperly: Could not test that the first raster contains properly the second raster");
663 PG_RETURN_NULL();
664 }
665
667}
char result[OUT_DOUBLE_BUFFER_SIZE]
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,...)