PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ RASTER_containsProperly()

Datum RASTER_containsProperly ( PG_FUNCTION_ARGS  )

Definition at line 554 of file rtpg_spatial_relationship.c.

555 {
556  const uint32_t set_count = 2;
557  rt_pgraster *pgrast[2];
558  int pgrastpos[2] = {-1, -1};
559  rt_raster rast[2] = {NULL};
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;
568  int result;
569 
570  for (i = 0, j = 0; i < set_count; i++) {
571  /* pgrast is null, return null */
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  /* raster */
584  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
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  /* numbands */
596  numBands = rt_raster_get_num_bands(rast[i]);
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  /* band index */
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;
623  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
624  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
625  j++;
626  }
627 
628  /* hasbandindex must be balanced */
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  /* SRID must match */
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),
654  &result
655  );
656  for (k = 0; k < set_count; k++) {
658  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
659  }
660 
661  if (rtn != ES_NONE) {
662  elog(ERROR, "RASTER_containsProperly: Could not test that the first raster contains properly the second raster");
663  PG_RETURN_NULL();
664  }
665 
666  PG_RETURN_BOOL(result);
667 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
#define FALSE
Definition: dbfopen.c:72
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:360
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.
Definition: rt_raster.c:86
@ ES_NONE
Definition: librtcore.h:182
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:376
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:69
Struct definitions.
Definition: librtcore.h:2440

References ES_NONE, FALSE, POSTGIS_RT_DEBUGF, rtpixdump::rast, result, rt_raster_contains_properly(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), and rt_raster_get_srid().

Here is the call graph for this function: