PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ RASTER_getBandNoDataValue()

Datum RASTER_getBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 182 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().

183 {
184  rt_pgraster *pgraster = NULL;
185  rt_raster raster = NULL;
186  rt_band band = NULL;
187  int32_t bandindex;
188  double nodata;
189 
190  /* Deserialize raster */
191  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
192  pgraster = (rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
193 
194  /* Index is 1-based */
195  bandindex = PG_GETARG_INT32(1);
196  if ( bandindex < 1 ) {
197  elog(NOTICE, "Invalid band index (must use 1-based). Returning NULL");
198  PG_FREE_IF_COPY(pgraster, 0);
199  PG_RETURN_NULL();
200  }
201 
202  raster = rt_raster_deserialize(pgraster, FALSE);
203  if ( ! raster ) {
204  PG_FREE_IF_COPY(pgraster, 0);
205  elog(ERROR, "RASTER_getBandNoDataValue: Could not deserialize raster");
206  PG_RETURN_NULL();
207  }
208 
209  /* Fetch requested band and its nodata value */
210  band = rt_raster_get_band(raster, bandindex - 1);
211  if ( ! band ) {
212  elog(NOTICE, "Could not find raster band of index %d when getting band nodata value. Returning NULL", bandindex);
213  rt_raster_destroy(raster);
214  PG_FREE_IF_COPY(pgraster, 0);
215  PG_RETURN_NULL();
216  }
217 
218  if ( ! rt_band_get_hasnodata_flag(band) ) {
219  /* Raster does not have a nodata value set so we return NULL */
220  rt_raster_destroy(raster);
221  PG_FREE_IF_COPY(pgraster, 0);
222  PG_RETURN_NULL();
223  }
224 
225  rt_band_get_nodata(band, &nodata);
226 
227  rt_raster_destroy(raster);
228  PG_FREE_IF_COPY(pgraster, 0);
229 
230  PG_RETURN_FLOAT8(nodata);
231 }
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:1682
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:626
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:2230
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: