PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ RASTER_coveredby()

Datum RASTER_coveredby ( PG_FUNCTION_ARGS  )

Definition at line 792 of file rtpg_spatial_relationship.c.

793 {
794  const uint32_t set_count = 2;
795  rt_pgraster *pgrast[2];
796  int pgrastpos[2] = {-1, -1};
797  rt_raster rast[2] = {NULL};
798  uint32_t bandindex[2] = {0};
799  uint32_t hasbandindex[2] = {0};
800 
801  uint32_t i;
802  uint32_t j;
803  uint32_t k;
804  uint32_t numBands;
805  int rtn;
806  int result;
807 
808  for (i = 0, j = 0; i < set_count; i++) {
809  /* pgrast is null, return null */
810  if (PG_ARGISNULL(j)) {
811  for (k = 0; k < i; k++) {
813  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
814  }
815  PG_RETURN_NULL();
816  }
817  pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
818  pgrastpos[i] = j;
819  j++;
820 
821  /* raster */
822  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
823  if (!rast[i]) {
824  for (k = 0; k <= i; k++) {
825  if (k < i)
827  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
828  }
829  elog(ERROR, "RASTER_coveredby: Could not deserialize the %s raster", i < 1 ? "first" : "second");
830  PG_RETURN_NULL();
831  }
832 
833  /* numbands */
834  numBands = rt_raster_get_num_bands(rast[i]);
835  if (numBands < 1) {
836  elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
837  if (i > 0) i++;
838  for (k = 0; k < i; k++) {
840  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
841  }
842  PG_RETURN_NULL();
843  }
844 
845  /* band index */
846  if (!PG_ARGISNULL(j)) {
847  bandindex[i] = PG_GETARG_INT32(j);
848  if (bandindex[i] < 1 || bandindex[i] > numBands) {
849  elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
850  if (i > 0) i++;
851  for (k = 0; k < i; k++) {
853  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
854  }
855  PG_RETURN_NULL();
856  }
857  hasbandindex[i] = 1;
858  }
859  else
860  hasbandindex[i] = 0;
861  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
862  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
863  j++;
864  }
865 
866  /* hasbandindex must be balanced */
867  if (
868  (hasbandindex[0] && !hasbandindex[1]) ||
869  (!hasbandindex[0] && hasbandindex[1])
870  ) {
871  elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
872  for (k = 0; k < set_count; k++) {
874  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
875  }
876  PG_RETURN_NULL();
877  }
878 
879  /* SRID must match */
881  for (k = 0; k < set_count; k++) {
883  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
884  }
885  elog(ERROR, "The two rasters provided have different SRIDs");
886  PG_RETURN_NULL();
887  }
888 
889  rtn = rt_raster_coveredby(
890  rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
891  rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
892  &result
893  );
894  for (k = 0; k < set_count; k++) {
896  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
897  }
898 
899  if (rtn != ES_NONE) {
900  elog(ERROR, "RASTER_coveredby: Could not test that the first raster is covered by the second raster");
901  PG_RETURN_NULL();
902  }
903 
904  PG_RETURN_BOOL(result);
905 }
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
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:86
rt_errorstate rt_raster_coveredby(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *coveredby)
Return ES_ERROR if error occurred in function.
@ 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_coveredby(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_num_bands(), and rt_raster_get_srid().

Here is the call graph for this function: