PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ RASTER_setBandNoDataValue()

Datum RASTER_setBandNoDataValue ( PG_FUNCTION_ARGS  )

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

626 {
627  rt_pgraster *pgraster = NULL;
628  rt_pgraster *pgrtn = NULL;
629  rt_raster raster = NULL;
630  rt_band band = NULL;
631  double nodata;
632  int32_t bandindex;
633  bool forcechecking = FALSE;
634  bool skipset = FALSE;
635 
636  /* Deserialize raster */
637  if (PG_ARGISNULL(0))
638  PG_RETURN_NULL();
639  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
640 
641  /* Check index is not NULL or smaller than 1 */
642  if (PG_ARGISNULL(1))
643  bandindex = -1;
644  else
645  bandindex = PG_GETARG_INT32(1);
646  if (bandindex < 1) {
647  elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
648  skipset = TRUE;
649  }
650 
651  raster = rt_raster_deserialize(pgraster, FALSE);
652  if (!raster) {
653  PG_FREE_IF_COPY(pgraster, 0);
654  elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
655  PG_RETURN_NULL();
656  }
657 
658  if (!skipset) {
659  /* Fetch requested band */
660  band = rt_raster_get_band(raster, bandindex - 1);
661  if (!band) {
662  elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
663  }
664  else {
665  if (!PG_ARGISNULL(3))
666  forcechecking = PG_GETARG_BOOL(3);
667 
668  if (PG_ARGISNULL(2)) {
669  /* Set the hasnodata flag to FALSE */
671  POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
672  }
673  else {
674  /* Get the nodata value */
675  nodata = PG_GETARG_FLOAT8(2);
676 
677  /* Set the band's nodata value */
678  rt_band_set_nodata(band, nodata, NULL);
679 
680  /* Recheck all pixels if requested */
681  if (forcechecking)
683  }
684  }
685  }
686 
687  pgrtn = rt_raster_serialize(raster);
688  rt_raster_destroy(raster);
689  PG_FREE_IF_COPY(pgraster, 0);
690  if (!pgrtn)
691  PG_RETURN_NULL();
692 
693  SET_VARSIZE(pgrtn, pgrtn->size);
694  PG_RETURN_POINTER(pgrtn);
695 }
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:685
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
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:1704
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:633
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2230
#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: