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

Definition at line 2478 of file rt_pg.c.

References ovdump::band, FALSE, POSTGIS_RT_DEBUGF, rtrowdump::raster, rt_band_check_is_nodata(), rt_band_set_hasnodata_flag(), rt_band_set_nodata(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), rt_raster_serialize(), rt_raster_serialized_t::size, and TRUE.

2479 {
2480  rt_pgraster *pgraster = NULL;
2481  rt_pgraster *pgrtn = NULL;
2482  rt_raster raster = NULL;
2483  rt_band band = NULL;
2484  double nodata;
2485  int32_t bandindex;
2486  bool forcechecking = FALSE;
2487  bool skipset = FALSE;
2488 
2489  /* Deserialize raster */
2490  if (PG_ARGISNULL(0))
2491  PG_RETURN_NULL();
2492  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2493 
2494  /* Check index is not NULL or smaller than 1 */
2495  if (PG_ARGISNULL(1))
2496  bandindex = -1;
2497  else
2498  bandindex = PG_GETARG_INT32(1);
2499  if (bandindex < 1) {
2500  elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
2501  skipset = TRUE;
2502  }
2503 
2504  raster = rt_raster_deserialize(pgraster, FALSE);
2505  if (!raster) {
2506  PG_FREE_IF_COPY(pgraster, 0);
2507  elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
2508  PG_RETURN_NULL();
2509  }
2510 
2511  if (!skipset) {
2512  /* Fetch requested band */
2513  band = rt_raster_get_band(raster, bandindex - 1);
2514  if (!band) {
2515  elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
2516  }
2517  else {
2518  if (!PG_ARGISNULL(3))
2519  forcechecking = PG_GETARG_BOOL(3);
2520 
2521  if (PG_ARGISNULL(2)) {
2522  /* Set the hasnodata flag to FALSE */
2524  POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
2525  }
2526  else {
2527  /* Get the nodata value */
2528  nodata = PG_GETARG_FLOAT8(2);
2529 
2530  /* Set the band's nodata value */
2531  rt_band_set_nodata(band, nodata, NULL);
2532 
2533  /* Recheck all pixels if requested */
2534  if (forcechecking)
2536  }
2537  }
2538  }
2539 
2540  pgrtn = rt_raster_serialize(raster);
2541  rt_raster_destroy(raster);
2542  PG_FREE_IF_COPY(pgraster, 0);
2543  if (!pgrtn)
2544  PG_RETURN_NULL();
2545 
2546  SET_VARSIZE(pgrtn, pgrtn->size);
2547  PG_RETURN_POINTER(pgrtn);
2548 }
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_api.c:8158
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_api.c:2061
tuple band
Definition: ovdump.py:57
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_api.c:3080
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_api.c:2009
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function: