PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_getBandNoDataValue()

Datum RASTER_getBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 180 of file rtpg_band_properties.c.

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

Referenced by RASTER_getBandPixelTypeName().

181 {
182  rt_pgraster *pgraster = NULL;
183  rt_raster raster = NULL;
184  rt_band band = NULL;
185  int32_t bandindex;
186  double nodata;
187 
188  /* Deserialize raster */
189  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
190  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
191 
192  /* Index is 1-based */
193  bandindex = PG_GETARG_INT32(1);
194  if ( bandindex < 1 ) {
195  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
196  PG_FREE_IF_COPY(pgraster, 0);
197  PG_RETURN_NULL();
198  }
199 
200  raster = rt_raster_deserialize(pgraster, FALSE);
201  if ( ! raster ) {
202  PG_FREE_IF_COPY(pgraster, 0);
203  elog(ERROR, "RASTER_getBandNoDataValue: Could not deserialize raster");
204  PG_RETURN_NULL();
205  }
206 
207  /* Fetch requested band and its nodata value */
208  band = rt_raster_get_band(raster, bandindex - 1);
209  if ( ! band ) {
210  elog(NOTICE, "Could not find raster band of index %d when getting band nodata value. Returning NULL", bandindex);
211  rt_raster_destroy(raster);
212  PG_FREE_IF_COPY(pgraster, 0);
213  PG_RETURN_NULL();
214  }
215 
216  if ( ! rt_band_get_hasnodata_flag(band) ) {
217  /* Raster does not have a nodata value set so we return NULL */
218  rt_raster_destroy(raster);
219  PG_FREE_IF_COPY(pgraster, 0);
220  PG_RETURN_NULL();
221  }
222 
223  rt_band_get_nodata(band, &nodata);
224 
225  rt_raster_destroy(raster);
226  PG_FREE_IF_COPY(pgraster, 0);
227 
228  PG_RETURN_FLOAT8(nodata);
229 }
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
band
Definition: ovdump.py:57
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2201
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
Here is the call graph for this function:
Here is the caller graph for this function: