PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum RASTER_setBandIsNoData ( PG_FUNCTION_ARGS  )

Definition at line 683 of file rtpg_band_properties.c.

References ovdump::band, FALSE, rtrowdump::raster, rt_band_get_hasnodata_flag(), rt_band_set_isnodata_flag(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), rt_raster_serialize(), and rt_raster_serialized_t::size.

684 {
685  rt_pgraster *pgraster = NULL;
686  rt_pgraster *pgrtn = NULL;
687  rt_raster raster = NULL;
688  rt_band band = NULL;
689  int32_t bandindex;
690 
691  if (PG_ARGISNULL(0))
692  PG_RETURN_NULL();
693  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
694 
695  raster = rt_raster_deserialize(pgraster, FALSE);
696  if (!raster) {
697  PG_FREE_IF_COPY(pgraster, 0);
698  elog(ERROR, "RASTER_setBandIsNoData: Could not deserialize raster");
699  PG_RETURN_NULL();
700  }
701 
702  /* Check index is not NULL or smaller than 1 */
703  if (PG_ARGISNULL(1))
704  bandindex = -1;
705  else
706  bandindex = PG_GETARG_INT32(1);
707 
708  if (bandindex < 1)
709  elog(NOTICE, "Invalid band index (must use 1-based). Isnodata flag not set. Returning original raster");
710  else {
711  /* Fetch requested band */
712  band = rt_raster_get_band(raster, bandindex - 1);
713 
714  if (!band)
715  elog(NOTICE, "Could not find raster band of index %d. Isnodata flag not set. Returning original raster", bandindex);
716  else {
717  if (!rt_band_get_hasnodata_flag(band)) {
718  elog(NOTICE, "Band of index %d has no NODATA so cannot be NODATA. Returning original raster", bandindex);
719  }
720  /* Set the band's nodata value */
721  else {
722  rt_band_set_isnodata_flag(band, 1);
723  }
724  }
725  }
726 
727  /* Serialize raster again */
728  pgrtn = rt_raster_serialize(raster);
729  rt_raster_destroy(raster);
730  PG_FREE_IF_COPY(pgraster, 0);
731  if (!pgrtn) PG_RETURN_NULL();
732 
733  SET_VARSIZE(pgrtn, pgrtn->size);
734  PG_RETURN_POINTER(pgrtn);
735 }
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
tuple band
Definition: ovdump.py:57
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
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_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_band.c:562
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2201
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: