PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_containsProperly()

Datum RASTER_containsProperly ( PG_FUNCTION_ARGS  )

Definition at line 549 of file rtpg_spatial_relationship.c.

References ES_NONE, FALSE, rt_raster_serialized_t::numBands, PG_FUNCTION_INFO_V1(), POSTGIS_RT_DEBUGF, rtpixdump::rast, RASTER_covers(), rt_raster_contains_properly(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), and rt_raster_get_srid().

Referenced by RASTER_contains().

550 {
551  const int set_count = 2;
552  rt_pgraster *pgrast[2];
553  int pgrastpos[2] = {-1, -1};
554  rt_raster rast[2] = {NULL};
555  uint32_t bandindex[2] = {0};
556  uint32_t hasbandindex[2] = {0};
557 
558  uint32_t i;
559  uint32_t j;
560  uint32_t k;
562  int rtn;
563  int result;
564 
565  for (i = 0, j = 0; i < set_count; i++) {
566  /* pgrast is null, return null */
567  if (PG_ARGISNULL(j)) {
568  for (k = 0; k < i; k++) {
569  rt_raster_destroy(rast[k]);
570  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
571  }
572  PG_RETURN_NULL();
573  }
574  pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
575  pgrastpos[i] = j;
576  j++;
577 
578  /* raster */
579  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
580  if (!rast[i]) {
581  for (k = 0; k <= i; k++) {
582  if (k < i)
583  rt_raster_destroy(rast[k]);
584  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
585  }
586  elog(ERROR, "RASTER_containsProperly: Could not deserialize the %s raster", i < 1 ? "first" : "second");
587  PG_RETURN_NULL();
588  }
589 
590  /* numbands */
591  numBands = rt_raster_get_num_bands(rast[i]);
592  if (numBands < 1) {
593  elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
594  if (i > 0) i++;
595  for (k = 0; k < i; k++) {
596  rt_raster_destroy(rast[k]);
597  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
598  }
599  PG_RETURN_NULL();
600  }
601 
602  /* band index */
603  if (!PG_ARGISNULL(j)) {
604  bandindex[i] = PG_GETARG_INT32(j);
605  if (bandindex[i] < 1 || bandindex[i] > numBands) {
606  elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
607  if (i > 0) i++;
608  for (k = 0; k < i; k++) {
609  rt_raster_destroy(rast[k]);
610  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
611  }
612  PG_RETURN_NULL();
613  }
614  hasbandindex[i] = 1;
615  }
616  else
617  hasbandindex[i] = 0;
618  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
619  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
620  j++;
621  }
622 
623  /* hasbandindex must be balanced */
624  if (
625  (hasbandindex[0] && !hasbandindex[1]) ||
626  (!hasbandindex[0] && hasbandindex[1])
627  ) {
628  elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
629  for (k = 0; k < set_count; k++) {
630  rt_raster_destroy(rast[k]);
631  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
632  }
633  PG_RETURN_NULL();
634  }
635 
636  /* SRID must match */
637  if (rt_raster_get_srid(rast[0]) != rt_raster_get_srid(rast[1])) {
638  for (k = 0; k < set_count; k++) {
639  rt_raster_destroy(rast[k]);
640  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
641  }
642  elog(ERROR, "The two rasters provided have different SRIDs");
643  PG_RETURN_NULL();
644  }
645 
647  rast[0], (hasbandindex[0] ? bandindex[0] - 1 : -1),
648  rast[1], (hasbandindex[1] ? bandindex[1] - 1 : -1),
649  &result
650  );
651  for (k = 0; k < set_count; k++) {
652  rt_raster_destroy(rast[k]);
653  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
654  }
655 
656  if (rtn != ES_NONE) {
657  elog(ERROR, "RASTER_containsProperly: Could not test that the first raster contains properly the second raster");
658  PG_RETURN_NULL();
659  }
660 
661  PG_RETURN_BOOL(result);
662 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
unsigned int uint32_t
Definition: uthash.h:78
int32_t rt_raster_get_srid(rt_raster raster)
Get raster&#39;s SRID.
Definition: rt_raster.c:356
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2201
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
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.
Here is the call graph for this function:
Here is the caller graph for this function: