PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ RASTER_containsProperly()

Datum RASTER_containsProperly ( PG_FUNCTION_ARGS  )

Definition at line 550 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().

551 {
552  const uint32_t set_count = 2;
553  rt_pgraster *pgrast[2];
554  int pgrastpos[2] = {-1, -1};
555  rt_raster rast[2] = {NULL};
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;
563  int rtn;
564  int result;
565 
566  for (i = 0, j = 0; i < set_count; i++) {
567  /* pgrast is null, return null */
568  if (PG_ARGISNULL(j)) {
569  for (k = 0; k < i; k++) {
570  rt_raster_destroy(rast[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  /* raster */
580  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
581  if (!rast[i]) {
582  for (k = 0; k <= i; k++) {
583  if (k < i)
584  rt_raster_destroy(rast[k]);
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  /* numbands */
592  numBands = rt_raster_get_num_bands(rast[i]);
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++) {
597  rt_raster_destroy(rast[k]);
598  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
599  }
600  PG_RETURN_NULL();
601  }
602 
603  /* band index */
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++) {
610  rt_raster_destroy(rast[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;
619  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
620  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
621  j++;
622  }
623 
624  /* hasbandindex must be balanced */
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++) {
631  rt_raster_destroy(rast[k]);
632  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
633  }
634  PG_RETURN_NULL();
635  }
636 
637  /* SRID must match */
638  if (rt_raster_get_srid(rast[0]) != rt_raster_get_srid(rast[1])) {
639  for (k = 0; k < set_count; k++) {
640  rt_raster_destroy(rast[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++) {
653  rt_raster_destroy(rast[k]);
654  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
655  }
656 
657  if (rtn != ES_NONE) {
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 }
uint16_t 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:2250
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
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: