PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ RASTER_setBandNoDataValue()

Datum RASTER_setBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 610 of file rtpg_band_properties.c.

References ovdump::band, FALSE, PG_FUNCTION_INFO_V1(), POSTGIS_RT_DEBUGF, rtrowdump::raster, RASTER_setBandIsNoData(), 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.

Referenced by RASTER_bandmetadata().

611 {
612  rt_pgraster *pgraster = NULL;
613  rt_pgraster *pgrtn = NULL;
614  rt_raster raster = NULL;
615  rt_band band = NULL;
616  double nodata;
617  int32_t bandindex;
618  bool forcechecking = FALSE;
619  bool skipset = FALSE;
620 
621  /* Deserialize raster */
622  if (PG_ARGISNULL(0))
623  PG_RETURN_NULL();
624  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
625 
626  /* Check index is not NULL or smaller than 1 */
627  if (PG_ARGISNULL(1))
628  bandindex = -1;
629  else
630  bandindex = PG_GETARG_INT32(1);
631  if (bandindex < 1) {
632  elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
633  skipset = TRUE;
634  }
635 
636  raster = rt_raster_deserialize(pgraster, FALSE);
637  if (!raster) {
638  PG_FREE_IF_COPY(pgraster, 0);
639  elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
640  PG_RETURN_NULL();
641  }
642 
643  if (!skipset) {
644  /* Fetch requested band */
645  band = rt_raster_get_band(raster, bandindex - 1);
646  if (!band) {
647  elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
648  }
649  else {
650  if (!PG_ARGISNULL(3))
651  forcechecking = PG_GETARG_BOOL(3);
652 
653  if (PG_ARGISNULL(2)) {
654  /* Set the hasnodata flag to FALSE */
656  POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
657  }
658  else {
659  /* Get the nodata value */
660  nodata = PG_GETARG_FLOAT8(2);
661 
662  /* Set the band's nodata value */
663  rt_band_set_nodata(band, nodata, NULL);
664 
665  /* Recheck all pixels if requested */
666  if (forcechecking)
668  }
669  }
670  }
671 
672  pgrtn = rt_raster_serialize(raster);
673  rt_raster_destroy(raster);
674  PG_FREE_IF_COPY(pgraster, 0);
675  if (!pgrtn)
676  PG_RETURN_NULL();
677 
678  SET_VARSIZE(pgrtn, pgrtn->size);
679  PG_RETURN_POINTER(pgrtn);
680 }
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
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_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:57
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_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1619
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_band.c:548
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2213
#define TRUE
Definition: dbfopen.c:169
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: