PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_coveredby()

Datum RASTER_coveredby ( PG_FUNCTION_ARGS  )

Definition at line 788 of file rtpg_spatial_relationship.c.

789 {
790  const uint32_t set_count = 2;
791  rt_pgraster *pgrast[2];
792  int pgrastpos[2] = {-1, -1};
793  rt_raster rast[2] = {NULL};
794  uint32_t bandindex[2] = {0};
795  uint32_t hasbandindex[2] = {0};
796 
797  uint32_t i;
798  uint32_t j;
799  uint32_t k;
800  uint32_t numBands;
801  int rtn;
802  int result;
803 
804  for (i = 0, j = 0; i < set_count; i++) {
805  /* pgrast is null, return null */
806  if (PG_ARGISNULL(j)) {
807  for (k = 0; k < i; k++) {
809  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
810  }
811  PG_RETURN_NULL();
812  }
813  pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
814  pgrastpos[i] = j;
815  j++;
816 
817  /* raster */
818  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
819  if (!rast[i]) {
820  for (k = 0; k <= i; k++) {
821  if (k < i)
823  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
824  }
825  elog(ERROR, "RASTER_coveredby: Could not deserialize the %s raster", i < 1 ? "first" : "second");
826  PG_RETURN_NULL();
827  }
828 
829  /* numbands */
830  numBands = rt_raster_get_num_bands(rast[i]);
831  if (numBands < 1) {
832  elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
833  if (i > 0) i++;
834  for (k = 0; k < i; k++) {
836  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
837  }
838  PG_RETURN_NULL();
839  }
840 
841  /* band index */
842  if (!PG_ARGISNULL(j)) {
843  bandindex[i] = PG_GETARG_INT32(j);
844  if (bandindex[i] < 1 || bandindex[i] > numBands) {
845  elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
846  if (i > 0) i++;
847  for (k = 0; k < i; k++) {
849  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
850  }
851  PG_RETURN_NULL();
852  }
853  hasbandindex[i] = 1;
854  }
855  else
856  hasbandindex[i] = 0;
857  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
858  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
859  j++;
860  }
861 
862  /* hasbandindex must be balanced */
863  if (
864  (hasbandindex[0] && !hasbandindex[1]) ||
865  (!hasbandindex[0] && hasbandindex[1])
866  ) {
867  elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
868  for (k = 0; k < set_count; k++) {
870  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
871  }
872  PG_RETURN_NULL();
873  }
874 
875  /* SRID must match */
877  for (k = 0; k < set_count; k++) {
879  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
880  }
881  elog(ERROR, "The two rasters provided have different SRIDs");
882  PG_RETURN_NULL();
883  }
884 
885  rtn = rt_raster_coveredby(
886  rast[0], (hasbandindex[0] ? (int)bandindex[0] - 1 : -1),
887  rast[1], (hasbandindex[1] ? (int)bandindex[1] - 1 : -1),
888  &result
889  );
890  for (k = 0; k < set_count; k++) {
892  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
893  }
894 
895  if (rtn != ES_NONE) {
896  elog(ERROR, "RASTER_coveredby: Could not test that the first raster is covered by the second raster");
897  PG_RETURN_NULL();
898  }
899 
900  PG_RETURN_BOOL(result);
901 }
#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
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:180
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
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_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: