PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum RASTER_setPixelValue ( PG_FUNCTION_ARGS  )

Definition at line 3218 of file rt_pg.c.

References ovdump::band, FALSE, POSTGIS_RT_DEBUGF, rtrowdump::raster, rt_band_get_hasnodata_flag(), rt_band_get_nodata(), rt_band_set_pixel(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_band(), rt_raster_serialize(), rt_raster_serialized_t::size, TRUE, pixval::x, and pixval::y.

3219 {
3220  rt_pgraster *pgraster = NULL;
3221  rt_pgraster *pgrtn = NULL;
3222  rt_raster raster = NULL;
3223  rt_band band = NULL;
3224  double pixvalue = 0;
3225  int32_t bandindex = 0;
3226  int32_t x = 0;
3227  int32_t y = 0;
3228  bool skipset = FALSE;
3229 
3230  if (PG_ARGISNULL(0))
3231  PG_RETURN_NULL();
3232 
3233  /* Check index is not NULL or < 1 */
3234  if (PG_ARGISNULL(1))
3235  bandindex = -1;
3236  else
3237  bandindex = PG_GETARG_INT32(1);
3238 
3239  if (bandindex < 1) {
3240  elog(NOTICE, "Invalid band index (must use 1-based). Value not set. Returning original raster");
3241  skipset = TRUE;
3242  }
3243 
3244  /* Validate pixel coordinates are not null */
3245  if (PG_ARGISNULL(2)) {
3246  elog(NOTICE, "X coordinate can not be NULL when setting pixel value. Value not set. Returning original raster");
3247  skipset = TRUE;
3248  }
3249  else
3250  x = PG_GETARG_INT32(2);
3251 
3252  if (PG_ARGISNULL(3)) {
3253  elog(NOTICE, "Y coordinate can not be NULL when setting pixel value. Value not set. Returning original raster");
3254  skipset = TRUE;
3255  }
3256  else
3257  y = PG_GETARG_INT32(3);
3258 
3259  POSTGIS_RT_DEBUGF(3, "Pixel coordinates (%d, %d)", x, y);
3260 
3261  /* Deserialize raster */
3262  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
3263 
3264  raster = rt_raster_deserialize(pgraster, FALSE);
3265  if (!raster) {
3266  PG_FREE_IF_COPY(pgraster, 0);
3267  elog(ERROR, "RASTER_setPixelValue: Could not deserialize raster");
3268  PG_RETURN_NULL();
3269  }
3270 
3271  if (!skipset) {
3272  /* Fetch requested band */
3273  band = rt_raster_get_band(raster, bandindex - 1);
3274  if (!band) {
3275  elog(NOTICE, "Could not find raster band of index %d when setting "
3276  "pixel value. Value not set. Returning original raster",
3277  bandindex);
3278  PG_RETURN_POINTER(pgraster);
3279  }
3280  else {
3281  /* Set the pixel value */
3282  if (PG_ARGISNULL(4)) {
3283  if (!rt_band_get_hasnodata_flag(band)) {
3284  elog(NOTICE, "Raster do not have a nodata value defined. "
3285  "Set band nodata value first. Nodata value not set. "
3286  "Returning original raster");
3287  PG_RETURN_POINTER(pgraster);
3288  }
3289  else {
3290  rt_band_get_nodata(band, &pixvalue);
3291  rt_band_set_pixel(band, x - 1, y - 1, pixvalue, NULL);
3292  }
3293  }
3294  else {
3295  pixvalue = PG_GETARG_FLOAT8(4);
3296  rt_band_set_pixel(band, x - 1, y - 1, pixvalue, NULL);
3297  }
3298  }
3299  }
3300 
3301  pgrtn = rt_raster_serialize(raster);
3302  rt_raster_destroy(raster);
3303  PG_FREE_IF_COPY(pgraster, 0);
3304  if (!pgrtn)
3305  PG_RETURN_NULL();
3306 
3307  SET_VARSIZE(pgrtn, pgrtn->size);
3308  PG_RETURN_POINTER(pgrtn);
3309 }
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_api.c:8158
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
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:123
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_api.c:3058
tuple x
Definition: pixval.py:53
rt_band rt_raster_get_band(rt_raster raster, int n)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rt_pg.h:62
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
#define TRUE
Definition: dbfopen.c:170
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_api.c:2002
tuple y
Definition: pixval.py:54
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302

Here is the call graph for this function: