PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ RASTER_setBandNoDataValue()

Datum RASTER_setBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 799 of file rtpg_band_properties.c.

800 {
801  rt_pgraster *pgraster = NULL;
802  rt_pgraster *pgrtn = NULL;
803  rt_raster raster = NULL;
804  rt_band band = NULL;
805  double nodata;
806  int32_t bandindex;
807  bool forcechecking = FALSE;
808  bool skipset = FALSE;
809 
810  /* Deserialize raster */
811  if (PG_ARGISNULL(0))
812  PG_RETURN_NULL();
813  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
814 
815  /* Check index is not NULL or smaller than 1 */
816  if (PG_ARGISNULL(1))
817  bandindex = -1;
818  else
819  bandindex = PG_GETARG_INT32(1);
820  if (bandindex < 1) {
821  elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
822  skipset = TRUE;
823  }
824 
825  raster = rt_raster_deserialize(pgraster, FALSE);
826  if (!raster) {
827  PG_FREE_IF_COPY(pgraster, 0);
828  elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
829  PG_RETURN_NULL();
830  }
831 
832  if (!skipset) {
833  /* Fetch requested band */
834  band = rt_raster_get_band(raster, bandindex - 1);
835  if (!band) {
836  elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
837  }
838  else {
839  if (!PG_ARGISNULL(3))
840  forcechecking = PG_GETARG_BOOL(3);
841 
842  if (PG_ARGISNULL(2)) {
843  /* Set the hasnodata flag to FALSE */
845  POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
846  }
847  else {
848  /* Get the nodata value */
849  nodata = PG_GETARG_FLOAT8(2);
850 
851  /* Set the band's nodata value */
852  rt_band_set_nodata(band, nodata, NULL);
853 
854  /* Recheck all pixels if requested */
855  if (forcechecking)
857  }
858  }
859  }
860 
861  pgrtn = rt_raster_serialize(raster);
863  PG_FREE_IF_COPY(pgraster, 0);
864  if (!pgrtn)
865  PG_RETURN_NULL();
866 
867  SET_VARSIZE(pgrtn, pgrtn->size);
868  PG_RETURN_POINTER(pgrtn);
869 }
#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:69
Struct definitions.
Definition: librtcore.h:2403

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: