PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_setBandNoDataValue()

Datum RASTER_setBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 776 of file rtpg_band_properties.c.

777 {
778  rt_pgraster *pgraster = NULL;
779  rt_pgraster *pgrtn = NULL;
780  rt_raster raster = NULL;
781  rt_band band = NULL;
782  double nodata;
783  int32_t bandindex;
784  bool forcechecking = FALSE;
785  bool skipset = FALSE;
786 
787  /* Deserialize raster */
788  if (PG_ARGISNULL(0))
789  PG_RETURN_NULL();
790  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
791 
792  /* Check index is not NULL or smaller than 1 */
793  if (PG_ARGISNULL(1))
794  bandindex = -1;
795  else
796  bandindex = PG_GETARG_INT32(1);
797  if (bandindex < 1) {
798  elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
799  skipset = TRUE;
800  }
801 
802  raster = rt_raster_deserialize(pgraster, FALSE);
803  if (!raster) {
804  PG_FREE_IF_COPY(pgraster, 0);
805  elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
806  PG_RETURN_NULL();
807  }
808 
809  if (!skipset) {
810  /* Fetch requested band */
811  band = rt_raster_get_band(raster, bandindex - 1);
812  if (!band) {
813  elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
814  }
815  else {
816  if (!PG_ARGISNULL(3))
817  forcechecking = PG_GETARG_BOOL(3);
818 
819  if (PG_ARGISNULL(2)) {
820  /* Set the hasnodata flag to FALSE */
822  POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
823  }
824  else {
825  /* Get the nodata value */
826  nodata = PG_GETARG_FLOAT8(2);
827 
828  /* Set the band's nodata value */
829  rt_band_set_nodata(band, nodata, NULL);
830 
831  /* Recheck all pixels if requested */
832  if (forcechecking)
834  }
835  }
836  }
837 
838  pgrtn = rt_raster_serialize(raster);
840  PG_FREE_IF_COPY(pgraster, 0);
841  if (!pgrtn)
842  PG_RETURN_NULL();
843 
844  SET_VARSIZE(pgrtn, pgrtn->size);
845  PG_RETURN_POINTER(pgrtn);
846 }
#define TRUE
Definition: dbfopen.c:169
#define FALSE
Definition: dbfopen.c:168
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:82
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:1752
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:381
band
Definition: ovdump.py:57
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:65
Struct definitions.
Definition: librtcore.h:2250

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: