PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ RASTER_setBandIsNoData()

Datum RASTER_setBandIsNoData ( PG_FUNCTION_ARGS  )

Definition at line 701 of file rtpg_band_properties.c.

References ovdump::band, FALSE, PG_FUNCTION_INFO_V1(), rtrowdump::raster, RASTER_setBandPath(), 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().

702 {
703  rt_pgraster *pgraster = NULL;
704  rt_pgraster *pgrtn = NULL;
705  rt_raster raster = NULL;
706  rt_band band = NULL;
707  int32_t bandindex;
708 
709  if (PG_ARGISNULL(0))
710  PG_RETURN_NULL();
711  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
712 
713  raster = rt_raster_deserialize(pgraster, FALSE);
714  if (!raster) {
715  PG_FREE_IF_COPY(pgraster, 0);
716  elog(ERROR, "RASTER_setBandIsNoData: Could not deserialize raster");
717  PG_RETURN_NULL();
718  }
719 
720  /* Check index is not NULL or smaller than 1 */
721  if (PG_ARGISNULL(1))
722  bandindex = -1;
723  else
724  bandindex = PG_GETARG_INT32(1);
725 
726  if (bandindex < 1)
727  elog(NOTICE, "Invalid band index (must use 1-based). Isnodata flag not set. Returning original raster");
728  else {
729  /* Fetch requested band */
730  band = rt_raster_get_band(raster, bandindex - 1);
731 
732  if (!band)
733  elog(NOTICE, "Could not find raster band of index %d. Isnodata flag not set. Returning original raster", bandindex);
734  else {
735  if (!rt_band_get_hasnodata_flag(band)) {
736  elog(NOTICE, "Band of index %d has no NODATA so cannot be NODATA. Returning original raster", bandindex);
737  }
738  /* Set the band's nodata value */
739  else {
740  rt_band_set_isnodata_flag(band, 1);
741  }
742  }
743  }
744 
745  /* Serialize raster again */
746  pgrtn = rt_raster_serialize(raster);
747  rt_raster_destroy(raster);
748  PG_FREE_IF_COPY(pgraster, 0);
749  if (!pgrtn) PG_RETURN_NULL();
750 
751  SET_VARSIZE(pgrtn, pgrtn->size);
752  PG_RETURN_POINTER(pgrtn);
753 }
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:626
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:647
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2230
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: