569{
574 double pixvalue = 0;
575 int32_t bandindex = 0;
578 bool skipset =
FALSE;
579
580 if (PG_ARGISNULL(0))
581 PG_RETURN_NULL();
582
583
584 if (PG_ARGISNULL(1))
585 bandindex = -1;
586 else
587 bandindex = PG_GETARG_INT32(1);
588
589 if (bandindex < 1) {
590 elog(NOTICE, "Invalid band index (must use 1-based). Value not set. Returning original raster");
592 }
593
594
595 if (PG_ARGISNULL(2)) {
596 elog(NOTICE, "X coordinate can not be NULL when setting pixel value. Value not set. Returning original raster");
598 }
599 else
600 x = PG_GETARG_INT32(2);
601
602 if (PG_ARGISNULL(3)) {
603 elog(NOTICE, "Y coordinate can not be NULL when setting pixel value. Value not set. Returning original raster");
605 }
606 else
607 y = PG_GETARG_INT32(3);
608
610
611
612 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
613
615 if (!raster) {
616 PG_FREE_IF_COPY(pgraster, 0);
617 elog(ERROR, "RASTER_setPixelValue: Could not deserialize raster");
618 PG_RETURN_NULL();
619 }
620
621 if (!skipset) {
622
624 if (!band) {
625 elog(NOTICE, "Could not find raster band of index %d when setting "
626 "pixel value. Value not set. Returning original raster",
627 bandindex);
628 PG_RETURN_POINTER(pgraster);
629 }
630 else {
631
632 if (PG_ARGISNULL(4)) {
634 elog(NOTICE, "Raster do not have a nodata value defined. "
635 "Set band nodata value first. Nodata value not set. "
636 "Returning original raster");
637 PG_RETURN_POINTER(pgraster);
638 }
639 else {
642 }
643 }
644 else {
645 pixvalue = PG_GETARG_FLOAT8(4);
647 }
648 }
649 }
650
653 PG_FREE_IF_COPY(pgraster, 0);
654 if (!pgrtn)
655 PG_RETURN_NULL();
656
657 SET_VARSIZE(pgrtn, pgrtn->
size);
658 PG_RETURN_POINTER(pgrtn);
659}
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
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.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
#define POSTGIS_RT_DEBUGF(level, msg,...)