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

Definition at line 2422 of file rt_pg.c.

References ovdump::band, FALSE, rtrowdump::raster, rt_band_get_hasnodata_flag(), rt_band_get_nodata(), rt_raster_deserialize(), rt_raster_destroy(), and rt_raster_get_band().

2423 {
2424  rt_pgraster *pgraster = NULL;
2425  rt_raster raster = NULL;
2426  rt_band band = NULL;
2427  int32_t bandindex;
2428  double nodata;
2429 
2430  /* Deserialize raster */
2431  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
2432  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
2433 
2434  /* Index is 1-based */
2435  bandindex = PG_GETARG_INT32(1);
2436  if ( bandindex < 1 ) {
2437  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
2438  PG_FREE_IF_COPY(pgraster, 0);
2439  PG_RETURN_NULL();
2440  }
2441 
2442  raster = rt_raster_deserialize(pgraster, FALSE);
2443  if ( ! raster ) {
2444  PG_FREE_IF_COPY(pgraster, 0);
2445  elog(ERROR, "RASTER_getBandNoDataValue: Could not deserialize raster");
2446  PG_RETURN_NULL();
2447  }
2448 
2449  /* Fetch requested band and its nodata value */
2450  band = rt_raster_get_band(raster, bandindex - 1);
2451  if ( ! band ) {
2452  elog(NOTICE, "Could not find raster band of index %d when getting band nodata value. Returning NULL", bandindex);
2453  rt_raster_destroy(raster);
2454  PG_FREE_IF_COPY(pgraster, 0);
2455  PG_RETURN_NULL();
2456  }
2457 
2458  if ( ! rt_band_get_hasnodata_flag(band) ) {
2459  /* Raster does not have a nodata value set so we return NULL */
2460  rt_raster_destroy(raster);
2461  PG_FREE_IF_COPY(pgraster, 0);
2462  PG_RETURN_NULL();
2463  }
2464 
2465  rt_band_get_nodata(band, &nodata);
2466 
2467  rt_raster_destroy(raster);
2468  PG_FREE_IF_COPY(pgraster, 0);
2469 
2470  PG_RETURN_FLOAT8(nodata);
2471 }
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_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_api.c:3058
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: