436{
437 const uint32_t set_count = 2;
439 int pgrastpos[2] = {-1, -1};
441 uint32_t bandindex[2] = {0};
442 uint32_t hasbandindex[2] = {0};
443
444 uint32_t i;
445 uint32_t j;
446 uint32_t k;
447 uint32_t numBands;
448 int rtn;
450
451 for (i = 0, j = 0; i < set_count; i++) {
452
453 if (PG_ARGISNULL(j)) {
454 for (k = 0; k < i; k++) {
456 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
457 }
458 PG_RETURN_NULL();
459 }
460 pgrast[i] = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
461 pgrastpos[i] = j;
462 j++;
463
464
466 if (!rast[i]) {
467 for (k = 0; k <= i; k++) {
468 if (k < i)
470 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
471 }
472 elog(ERROR, "RASTER_contains: Could not deserialize the %s raster", i < 1 ? "first" : "second");
473 PG_RETURN_NULL();
474 }
475
476
478 if (numBands < 1) {
479 elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
480 if (i > 0) i++;
481 for (k = 0; k < i; k++) {
483 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
484 }
485 PG_RETURN_NULL();
486 }
487
488
489 if (!PG_ARGISNULL(j)) {
490 bandindex[i] = PG_GETARG_INT32(j);
491 if (bandindex[i] < 1 || bandindex[i] > numBands) {
492 elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
493 if (i > 0) i++;
494 for (k = 0; k < i; k++) {
496 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
497 }
498 PG_RETURN_NULL();
499 }
500 hasbandindex[i] = 1;
501 }
502 else
503 hasbandindex[i] = 0;
506 j++;
507 }
508
509
510 if (
511 (hasbandindex[0] && !hasbandindex[1]) ||
512 (!hasbandindex[0] && hasbandindex[1])
513 ) {
514 elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
515 for (k = 0; k < set_count; k++) {
517 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
518 }
519 PG_RETURN_NULL();
520 }
521
522
524 for (k = 0; k < set_count; k++) {
526 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
527 }
528 elog(ERROR, "The two rasters provided have different SRIDs");
529 PG_RETURN_NULL();
530 }
531
533 rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
534 rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
536 );
537 for (k = 0; k < set_count; k++) {
539 PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
540 }
541
543 elog(ERROR, "RASTER_contains: Could not test that the first raster contains the second raster");
544 PG_RETURN_NULL();
545 }
546
548}
char result[OUT_DOUBLE_BUFFER_SIZE]
rt_errorstate rt_raster_contains(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
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,...)