PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ RASTER_setBandNoDataValue()

Datum RASTER_setBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 797 of file rtpg_band_properties.c.

798 {
799  rt_pgraster *pgraster = NULL;
800  rt_pgraster *pgrtn = NULL;
801  rt_raster raster = NULL;
802  rt_band band = NULL;
803  double nodata;
804  int32_t bandindex;
805  bool forcechecking = FALSE;
806  bool skipset = FALSE;
807 
808  /* Deserialize raster */
809  if (PG_ARGISNULL(0))
810  PG_RETURN_NULL();
811  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
812 
813  /* Check index is not NULL or smaller than 1 */
814  if (PG_ARGISNULL(1))
815  bandindex = -1;
816  else
817  bandindex = PG_GETARG_INT32(1);
818  if (bandindex < 1) {
819  elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
820  skipset = TRUE;
821  }
822 
823  raster = rt_raster_deserialize(pgraster, FALSE);
824  if (!raster) {
825  PG_FREE_IF_COPY(pgraster, 0);
826  elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
827  PG_RETURN_NULL();
828  }
829 
830  if (!skipset) {
831  /* Fetch requested band */
832  band = rt_raster_get_band(raster, bandindex - 1);
833  if (!band) {
834  elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
835  }
836  else {
837  if (!PG_ARGISNULL(3))
838  forcechecking = PG_GETARG_BOOL(3);
839 
840  if (PG_ARGISNULL(2)) {
841  /* Set the hasnodata flag to FALSE */
843  POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
844  }
845  else {
846  /* Get the nodata value */
847  nodata = PG_GETARG_FLOAT8(2);
848 
849  /* Set the band's nodata value */
850  rt_band_set_nodata(band, nodata, NULL);
851 
852  /* Recheck all pixels if requested */
853  if (forcechecking)
855  }
856  }
857  }
858 
859  pgrtn = rt_raster_serialize(raster);
861  PG_FREE_IF_COPY(pgraster, 0);
862  if (!pgrtn)
863  PG_RETURN_NULL();
864 
865  SET_VARSIZE(pgrtn, pgrtn->size);
866  PG_RETURN_POINTER(pgrtn);
867 }
#define TRUE
Definition: dbfopen.c:73
#define FALSE
Definition: dbfopen.c:72
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_band.c:681
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:86
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1909
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:733
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:385
band
Definition: ovdump.py:58
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:73
Struct definitions.
Definition: librtcore.h:2396

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

Here is the call graph for this function: