PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ RASTER_setBandNoDataValue()

Datum RASTER_setBandNoDataValue ( PG_FUNCTION_ARGS  )

Definition at line 778 of file rtpg_band_properties.c.

779{
780 rt_pgraster *pgraster = NULL;
781 rt_pgraster *pgrtn = NULL;
782 rt_raster raster = NULL;
783 rt_band band = NULL;
784 double nodata;
785 int32_t bandindex;
786 bool forcechecking = FALSE;
787 bool skipset = FALSE;
788
789 /* Deserialize raster */
790 if (PG_ARGISNULL(0))
791 PG_RETURN_NULL();
792 pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
793
794 /* Check index is not NULL or smaller than 1 */
795 if (PG_ARGISNULL(1))
796 bandindex = -1;
797 else
798 bandindex = PG_GETARG_INT32(1);
799 if (bandindex < 1) {
800 elog(NOTICE, "Invalid band index (must use 1-based). Nodata value not set. Returning original raster");
801 skipset = TRUE;
802 }
803
805 if (!raster) {
806 PG_FREE_IF_COPY(pgraster, 0);
807 elog(ERROR, "RASTER_setBandNoDataValue: Could not deserialize raster");
808 PG_RETURN_NULL();
809 }
810
811 if (!skipset) {
812 /* Fetch requested band */
813 band = rt_raster_get_band(raster, bandindex - 1);
814 if (!band) {
815 elog(NOTICE, "Could not find raster band of index %d when setting pixel value. Nodata value not set. Returning original raster", bandindex);
816 }
817 else {
818 if (!PG_ARGISNULL(3))
819 forcechecking = PG_GETARG_BOOL(3);
820
821 if (PG_ARGISNULL(2)) {
822 /* Set the hasnodata flag to FALSE */
824 POSTGIS_RT_DEBUGF(3, "Raster band %d does not have a nodata value", bandindex);
825 }
826 else {
827 /* Get the nodata value */
828 nodata = PG_GETARG_FLOAT8(2);
829
830 /* Set the band's nodata value */
831 rt_band_set_nodata(band, nodata, NULL);
832
833 /* Recheck all pixels if requested */
834 if (forcechecking)
836 }
837 }
838 }
839
840 pgrtn = rt_raster_serialize(raster);
841 rt_raster_destroy(raster);
842 PG_FREE_IF_COPY(pgraster, 0);
843 if (!pgrtn)
844 PG_RETURN_NULL();
845
846 SET_VARSIZE(pgrtn, pgrtn->size);
847 PG_RETURN_POINTER(pgrtn);
848}
#define TRUE
Definition dbfopen.c:169
#define FALSE
Definition dbfopen.c:168
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition rt_band.c:681
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition rt_raster.c:82
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition rt_band.c:1752
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:733
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition rt_raster.c:381
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition rtrowdump.py:121
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition rtpostgis.h:65
Struct definitions.
Definition librtcore.h:2251

References FALSE, POSTGIS_RT_DEBUGF, 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.

Here is the call graph for this function: