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

Definition at line 2551 of file rt_pg.c.

References ovdump::band, FALSE, rtrowdump::raster, rt_band_get_hasnodata_flag(), rt_band_set_isnodata_flag(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), rt_raster_serialize(), and rt_raster_serialized_t::size.

2552 {
2553  rt_pgraster *pgraster = NULL;
2554  rt_pgraster *pgrtn = NULL;
2555  rt_raster raster = NULL;
2556  rt_band band = NULL;
2557  int32_t bandindex;
2558 
2559  if (PG_ARGISNULL(0))
2560  PG_RETURN_NULL();
2561  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2562 
2563  raster = rt_raster_deserialize(pgraster, FALSE);
2564  if (!raster) {
2565  PG_FREE_IF_COPY(pgraster, 0);
2566  elog(ERROR, "RASTER_setBandIsNoData: Could not deserialize raster");
2567  PG_RETURN_NULL();
2568  }
2569 
2570  /* Check index is not NULL or smaller than 1 */
2571  if (PG_ARGISNULL(1))
2572  bandindex = -1;
2573  else
2574  bandindex = PG_GETARG_INT32(1);
2575 
2576  if (bandindex < 1)
2577  elog(NOTICE, "Invalid band index (must use 1-based). Isnodata flag not set. Returning original raster");
2578  else {
2579  /* Fetch requested band */
2580  band = rt_raster_get_band(raster, bandindex - 1);
2581 
2582  if (!band)
2583  elog(NOTICE, "Could not find raster band of index %d. Isnodata flag not set. Returning original raster", bandindex);
2584  else {
2585  if (!rt_band_get_hasnodata_flag(band)) {
2586  elog(NOTICE, "Band of index %d has no NODATA so cannot be NODATA. Returning original raster", bandindex);
2587  }
2588  /* Set the band's nodata value */
2589  else {
2590  rt_band_set_isnodata_flag(band, 1);
2591  }
2592  }
2593  }
2594 
2595  /* Serialize raster again */
2596  pgrtn = rt_raster_serialize(raster);
2597  rt_raster_destroy(raster);
2598  PG_FREE_IF_COPY(pgraster, 0);
2599  if (!pgrtn) PG_RETURN_NULL();
2600 
2601  SET_VARSIZE(pgrtn, pgrtn->size);
2602  PG_RETURN_POINTER(pgrtn);
2603 }
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
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_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_api.c:2023
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
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_api.c:2002

Here is the call graph for this function: