PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_setBandIsNoData()

Datum RASTER_setBandIsNoData ( PG_FUNCTION_ARGS  )

Definition at line 684 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.

Referenced by RASTER_setBandNoDataValue().

685 {
686  rt_pgraster *pgraster = NULL;
687  rt_pgraster *pgrtn = NULL;
688  rt_raster raster = NULL;
689  rt_band band = NULL;
690  int32_t bandindex;
691 
692  if (PG_ARGISNULL(0))
693  PG_RETURN_NULL();
694  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
695 
696  raster = rt_raster_deserialize(pgraster, FALSE);
697  if (!raster) {
698  PG_FREE_IF_COPY(pgraster, 0);
699  elog(ERROR, "RASTER_setBandIsNoData: Could not deserialize raster");
700  PG_RETURN_NULL();
701  }
702 
703  /* Check index is not NULL or smaller than 1 */
704  if (PG_ARGISNULL(1))
705  bandindex = -1;
706  else
707  bandindex = PG_GETARG_INT32(1);
708 
709  if (bandindex < 1)
710  elog(NOTICE, "Invalid band index (must use 1-based). Isnodata flag not set. Returning original raster");
711  else {
712  /* Fetch requested band */
713  band = rt_raster_get_band(raster, bandindex - 1);
714 
715  if (!band)
716  elog(NOTICE, "Could not find raster band of index %d. Isnodata flag not set. Returning original raster", bandindex);
717  else {
718  if (!rt_band_get_hasnodata_flag(band)) {
719  elog(NOTICE, "Band of index %d has no NODATA so cannot be NODATA. Returning original raster", bandindex);
720  }
721  /* Set the band's nodata value */
722  else {
723  rt_band_set_isnodata_flag(band, 1);
724  }
725  }
726  }
727 
728  /* Serialize raster again */
729  pgrtn = rt_raster_serialize(raster);
730  rt_raster_destroy(raster);
731  PG_FREE_IF_COPY(pgraster, 0);
732  if (!pgrtn) PG_RETURN_NULL();
733 
734  SET_VARSIZE(pgrtn, pgrtn->size);
735  PG_RETURN_POINTER(pgrtn);
736 }
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_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:
Here is the caller graph for this function: