PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_covers()

Datum RASTER_covers ( PG_FUNCTION_ARGS  )

Definition at line 669 of file rtpg_spatial_relationship.c.

670 {
671  const uint32_t set_count = 2;
672  rt_pgraster *pgrast[2];
673  int pgrastpos[2] = {-1, -1};
674  rt_raster rast[2] = {NULL};
675  uint32_t bandindex[2] = {0};
676  uint32_t hasbandindex[2] = {0};
677 
678  uint32_t i;
679  uint32_t j;
680  uint32_t k;
681  uint32_t numBands;
682  int rtn;
683  int result;
684 
685  for (i = 0, j = 0; i < set_count; i++) {
686  /* pgrast is null, return null */
687  if (PG_ARGISNULL(j)) {
688  for (k = 0; k < i; k++) {
690  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
691  }
692  PG_RETURN_NULL();
693  }
694  pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
695  pgrastpos[i] = j;
696  j++;
697 
698  /* raster */
699  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
700  if (!rast[i]) {
701  for (k = 0; k <= i; k++) {
702  if (k < i)
704  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
705  }
706  elog(ERROR, "RASTER_covers: Could not deserialize the %s raster", i < 1 ? "first" : "second");
707  PG_RETURN_NULL();
708  }
709 
710  /* numbands */
711  numBands = rt_raster_get_num_bands(rast[i]);
712  if (numBands < 1) {
713  elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
714  if (i > 0) i++;
715  for (k = 0; k < i; k++) {
717  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
718  }
719  PG_RETURN_NULL();
720  }
721 
722  /* band index */
723  if (!PG_ARGISNULL(j)) {
724  bandindex[i] = PG_GETARG_INT32(j);
725  if (bandindex[i] < 1 || bandindex[i] > numBands) {
726  elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
727  if (i > 0) i++;
728  for (k = 0; k < i; k++) {
730  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
731  }
732  PG_RETURN_NULL();
733  }
734  hasbandindex[i] = 1;
735  }
736  else
737  hasbandindex[i] = 0;
738  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
739  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
740  j++;
741  }
742 
743  /* hasbandindex must be balanced */
744  if (
745  (hasbandindex[0] && !hasbandindex[1]) ||
746  (!hasbandindex[0] && hasbandindex[1])
747  ) {
748  elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
749  for (k = 0; k < set_count; k++) {
751  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
752  }
753  PG_RETURN_NULL();
754  }
755 
756  /* SRID must match */
758  for (k = 0; k < set_count; k++) {
760  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
761  }
762  elog(ERROR, "The two rasters provided have different SRIDs");
763  PG_RETURN_NULL();
764  }
765 
766  rtn = rt_raster_covers(
767  rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
768  rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
769  &result
770  );
771  for (k = 0; k < set_count; k++) {
773  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
774  }
775 
776  if (rtn != ES_NONE) {
777  elog(ERROR, "RASTER_covers: Could not test that the first raster covers the second raster");
778  PG_RETURN_NULL();
779  }
780 
781  PG_RETURN_BOOL(result);
782 }
#define FALSE
Definition: dbfopen.c:168
int32_t rt_raster_get_srid(rt_raster raster)
Get raster'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
@ ES_NONE
Definition: librtcore.h:180
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
rt_errorstate rt_raster_covers(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *covers)
Return ES_ERROR if error occurred in function.
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:65
Struct definitions.
Definition: librtcore.h:2250
unsigned int uint32_t
Definition: uthash.h:78

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

Here is the call graph for this function: