PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ RASTER_setPixelValue()

Datum RASTER_setPixelValue ( PG_FUNCTION_ARGS  )

Definition at line 567 of file rtpg_pixel.c.

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

Referenced by RASTER_dumpValues().

568 {
569  rt_pgraster *pgraster = NULL;
570  rt_pgraster *pgrtn = NULL;
571  rt_raster raster = NULL;
572  rt_band band = NULL;
573  double pixvalue = 0;
574  int32_t bandindex = 0;
575  int32_t x = 0;
576  int32_t y = 0;
577  bool skipset = FALSE;
578 
579  if (PG_ARGISNULL(0))
580  PG_RETURN_NULL();
581 
582  /* Check index is not NULL or < 1 */
583  if (PG_ARGISNULL(1))
584  bandindex = -1;
585  else
586  bandindex = PG_GETARG_INT32(1);
587 
588  if (bandindex < 1) {
589  elog(NOTICE, "Invalid band index (must use 1-based). Value not set. Returning original raster");
590  skipset = TRUE;
591  }
592 
593  /* Validate pixel coordinates are not null */
594  if (PG_ARGISNULL(2)) {
595  elog(NOTICE, "X coordinate can not be NULL when setting pixel value. Value not set. Returning original raster");
596  skipset = TRUE;
597  }
598  else
599  x = PG_GETARG_INT32(2);
600 
601  if (PG_ARGISNULL(3)) {
602  elog(NOTICE, "Y coordinate can not be NULL when setting pixel value. Value not set. Returning original raster");
603  skipset = TRUE;
604  }
605  else
606  y = PG_GETARG_INT32(3);
607 
608  POSTGIS_RT_DEBUGF(3, "Pixel coordinates (%d, %d)", x, y);
609 
610  /* Deserialize raster */
611  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
612 
613  raster = rt_raster_deserialize(pgraster, FALSE);
614  if (!raster) {
615  PG_FREE_IF_COPY(pgraster, 0);
616  elog(ERROR, "RASTER_setPixelValue: Could not deserialize raster");
617  PG_RETURN_NULL();
618  }
619 
620  if (!skipset) {
621  /* Fetch requested band */
622  band = rt_raster_get_band(raster, bandindex - 1);
623  if (!band) {
624  elog(NOTICE, "Could not find raster band of index %d when setting "
625  "pixel value. Value not set. Returning original raster",
626  bandindex);
627  PG_RETURN_POINTER(pgraster);
628  }
629  else {
630  /* Set the pixel value */
631  if (PG_ARGISNULL(4)) {
632  if (!rt_band_get_hasnodata_flag(band)) {
633  elog(NOTICE, "Raster do not have a nodata value defined. "
634  "Set band nodata value first. Nodata value not set. "
635  "Returning original raster");
636  PG_RETURN_POINTER(pgraster);
637  }
638  else {
639  rt_band_get_nodata(band, &pixvalue);
640  rt_band_set_pixel(band, x - 1, y - 1, pixvalue, NULL);
641  }
642  }
643  else {
644  pixvalue = PG_GETARG_FLOAT8(4);
645  rt_band_set_pixel(band, x - 1, y - 1, pixvalue, NULL);
646  }
647  }
648  }
649 
650  pgrtn = rt_raster_serialize(raster);
651  rt_raster_destroy(raster);
652  PG_FREE_IF_COPY(pgraster, 0);
653  if (!pgrtn)
654  PG_RETURN_NULL();
655 
656  SET_VARSIZE(pgrtn, pgrtn->size);
657  PG_RETURN_POINTER(pgrtn);
658 }
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
#define POSTGIS_RT_DEBUGF(level, msg,...)
Definition: rtpostgis.h:65
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
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
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2250
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:974
#define TRUE
Definition: dbfopen.c:169
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: