PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ RASTER_setBandIsNoData()

Datum RASTER_setBandIsNoData ( PG_FUNCTION_ARGS  )

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

852 {
853  rt_pgraster *pgraster = NULL;
854  rt_pgraster *pgrtn = NULL;
855  rt_raster raster = NULL;
856  rt_band band = NULL;
857  int32_t bandindex;
858 
859  if (PG_ARGISNULL(0))
860  PG_RETURN_NULL();
861  pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
862 
863  raster = rt_raster_deserialize(pgraster, FALSE);
864  if (!raster) {
865  PG_FREE_IF_COPY(pgraster, 0);
866  elog(ERROR, "RASTER_setBandIsNoData: Could not deserialize raster");
867  PG_RETURN_NULL();
868  }
869 
870  /* Check index is not NULL or smaller than 1 */
871  if (PG_ARGISNULL(1))
872  bandindex = -1;
873  else
874  bandindex = PG_GETARG_INT32(1);
875 
876  if (bandindex < 1)
877  elog(NOTICE, "Invalid band index (must use 1-based). Isnodata flag not set. Returning original raster");
878  else {
879  /* Fetch requested band */
880  band = rt_raster_get_band(raster, bandindex - 1);
881 
882  if (!band)
883  elog(NOTICE, "Could not find raster band of index %d. Isnodata flag not set. Returning original raster", bandindex);
884  else {
885  if (!rt_band_get_hasnodata_flag(band)) {
886  elog(NOTICE, "Band of index %d has no NODATA so cannot be NODATA. Returning original raster", bandindex);
887  }
888  /* Set the band's nodata value */
889  else {
890  rt_band_set_isnodata_flag(band, 1);
891  }
892  }
893  }
894 
895  /* Serialize raster again */
896  pgrtn = rt_raster_serialize(raster);
897  rt_raster_destroy(raster);
898  PG_FREE_IF_COPY(pgraster, 0);
899  if (!pgrtn) PG_RETURN_NULL();
900 
901  SET_VARSIZE(pgrtn, pgrtn->size);
902  PG_RETURN_POINTER(pgrtn);
903 }
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:674
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:695
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2250
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:715
Here is the call graph for this function:
Here is the caller graph for this function: