PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_containsProperly ( PG_FUNCTION_ARGS  )

Definition at line 13783 of file rt_pg.c.

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

13784 {
13785  const int set_count = 2;
13786  rt_pgraster *pgrast[2];
13787  int pgrastpos[2] = {-1, -1};
13788  rt_raster rast[2] = {NULL};
13789  uint32_t bandindex[2] = {0};
13790  uint32_t hasbandindex[2] = {0};
13791 
13792  uint32_t i;
13793  uint32_t j;
13794  uint32_t k;
13795  uint32_t numBands;
13796  int rtn;
13797  int result;
13798 
13799  for (i = 0, j = 0; i < set_count; i++) {
13800  /* pgrast is null, return null */
13801  if (PG_ARGISNULL(j)) {
13802  for (k = 0; k < i; k++) {
13803  rt_raster_destroy(rast[k]);
13804  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13805  }
13806  PG_RETURN_NULL();
13807  }
13808  pgrast[i] = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(j));
13809  pgrastpos[i] = j;
13810  j++;
13811 
13812  /* raster */
13813  rast[i] = rt_raster_deserialize(pgrast[i], FALSE);
13814  if (!rast[i]) {
13815  for (k = 0; k <= i; k++) {
13816  if (k < i)
13817  rt_raster_destroy(rast[k]);
13818  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13819  }
13820  elog(ERROR, "RASTER_containsProperly: Could not deserialize the %s raster", i < 1 ? "first" : "second");
13821  PG_RETURN_NULL();
13822  }
13823 
13824  /* numbands */
13825  numBands = rt_raster_get_num_bands(rast[i]);
13826  if (numBands < 1) {
13827  elog(NOTICE, "The %s raster provided has no bands", i < 1 ? "first" : "second");
13828  if (i > 0) i++;
13829  for (k = 0; k < i; k++) {
13830  rt_raster_destroy(rast[k]);
13831  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13832  }
13833  PG_RETURN_NULL();
13834  }
13835 
13836  /* band index */
13837  if (!PG_ARGISNULL(j)) {
13838  bandindex[i] = PG_GETARG_INT32(j);
13839  if (bandindex[i] < 1 || bandindex[i] > numBands) {
13840  elog(NOTICE, "Invalid band index (must use 1-based) for the %s raster. Returning NULL", i < 1 ? "first" : "second");
13841  if (i > 0) i++;
13842  for (k = 0; k < i; k++) {
13843  rt_raster_destroy(rast[k]);
13844  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13845  }
13846  PG_RETURN_NULL();
13847  }
13848  hasbandindex[i] = 1;
13849  }
13850  else
13851  hasbandindex[i] = 0;
13852  POSTGIS_RT_DEBUGF(4, "hasbandindex[%d] = %d", i, hasbandindex[i]);
13853  POSTGIS_RT_DEBUGF(4, "bandindex[%d] = %d", i, bandindex[i]);
13854  j++;
13855  }
13856 
13857  /* hasbandindex must be balanced */
13858  if (
13859  (hasbandindex[0] && !hasbandindex[1]) ||
13860  (!hasbandindex[0] && hasbandindex[1])
13861  ) {
13862  elog(NOTICE, "Missing band index. Band indices must be provided for both rasters if any one is provided");
13863  for (k = 0; k < set_count; k++) {
13864  rt_raster_destroy(rast[k]);
13865  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13866  }
13867  PG_RETURN_NULL();
13868  }
13869 
13870  /* SRID must match */
13871  if (rt_raster_get_srid(rast[0]) != rt_raster_get_srid(rast[1])) {
13872  for (k = 0; k < set_count; k++) {
13873  rt_raster_destroy(rast[k]);
13874  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13875  }
13876  elog(ERROR, "The two rasters provided have different SRIDs");
13877  PG_RETURN_NULL();
13878  }
13879 
13881  rast[0], (hasbandindex[0] ? bandindex[0] - 1 : -1),
13882  rast[1], (hasbandindex[1] ? bandindex[1] - 1 : -1),
13883  &result
13884  );
13885  for (k = 0; k < set_count; k++) {
13886  rt_raster_destroy(rast[k]);
13887  PG_FREE_IF_COPY(pgrast[k], pgrastpos[k]);
13888  }
13889 
13890  if (rtn != ES_NONE) {
13891  elog(ERROR, "RASTER_containsProperly: Could not test that the first raster contains properly the second raster");
13892  PG_RETURN_NULL();
13893  }
13894 
13895  PG_RETURN_BOOL(result);
13896 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
tuple rast
Definition: rtpixdump.py:62
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
char ** result
Definition: liblwgeom.h:218
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.
Definition: rt_api.c:12495
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350

Here is the call graph for this function: