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

◆ rt_band_set_pixel_line()

rt_errorstate rt_band_set_pixel_line ( rt_band  band,
int  x,
int  y,
void *  vals,
uint32_t  len 
)

Set values of multiple pixels.

Unlike rt_band_set_pixel, values in vals are expected to be of the band's pixel type as this function uses memcpy.

It is important to be careful when using this function as the number of values being set may exceed a pixel "row". Remember that the band values are stored in a stream (1-D array) regardless of what the raster's width and height might be. So, setting a number of values may cross multiple pixel "rows".

Parameters
band: the band to set value to
x: pixel column (0-based)
y: pixel row (0-based)
vals: the pixel values to apply
len: # of elements in vals
Returns
ES_NONE on success, ES_ERROR on error

Unlike rt_band_set_pixel, values in vals are expected to be of the band's pixel type as this function uses memcpy.

It is important to be careful when using this function as the number of values being set may exceed a pixel "row". Remember that the band values are stored in a stream (1-D array) regardless of what the raster's width and height might be. So, setting a number of values may cross multiple pixel "rows".

Parameters
band: the band to set value to
x: X coordinate (0-based)
y: Y coordinate (0-based)
vals: the pixel values to apply
len: # of elements in vals
Returns
ES_NONE on success, ES_ERROR on error

Definition at line 1019 of file rt_band.c.

1023 {
1024 rt_pixtype pixtype = PT_END;
1025 int size = 0;
1026 uint8_t *data = NULL;
1027 uint32_t offset = 0;
1028
1029 assert(NULL != band);
1030 assert(vals != NULL && len > 0);
1031
1032 RASTER_DEBUGF(3, "length of values = %d", len);
1033
1034 if (band->offline) {
1035 rterror("rt_band_set_pixel_line not implemented yet for OFFDB bands");
1036 return ES_ERROR;
1037 }
1038
1039 pixtype = band->pixtype;
1040 size = rt_pixtype_size(pixtype);
1041
1042 if (
1043 x < 0 || x >= band->width ||
1044 y < 0 || y >= band->height
1045 ) {
1046 rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
1047 return ES_ERROR;
1048 }
1049
1050 data = rt_band_get_data(band);
1051 offset = x + (y * band->width);
1052 RASTER_DEBUGF(4, "offset = %d", offset);
1053
1054 /* make sure len of values to copy don't exceed end of data */
1055 if (len > (band->width * band->height) - offset) {
1056 rterror("rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
1057 return ES_ERROR;
1058 }
1059
1060 switch (pixtype) {
1061 case PT_1BB:
1062 case PT_2BUI:
1063 case PT_4BUI:
1064 case PT_8BUI:
1065 case PT_8BSI: {
1066 uint8_t *ptr = data;
1067 ptr += offset;
1068 memcpy(ptr, vals, (size_t)size * len);
1069 break;
1070 }
1071 case PT_16BUI: {
1072 uint16_t *ptr = (uint16_t *) data;
1073 ptr += offset;
1074 memcpy(ptr, vals, (size_t)size * len);
1075 break;
1076 }
1077 case PT_16BSI: {
1078 int16_t *ptr = (int16_t *) data;
1079 ptr += offset;
1080 memcpy(ptr, vals, (size_t)size * len);
1081 break;
1082 }
1083 case PT_32BUI: {
1084 uint32_t *ptr = (uint32_t *) data;
1085 ptr += offset;
1086 memcpy(ptr, vals, (size_t)size * len);
1087 break;
1088 }
1089 case PT_32BSI: {
1090 int32_t *ptr = (int32_t *) data;
1091 ptr += offset;
1092 memcpy(ptr, vals, (size_t)size * len);
1093 break;
1094 }
1095 case PT_32BF: {
1096 float *ptr = (float *) data;
1097 ptr += offset;
1098 memcpy(ptr, vals, (size_t)size * len);
1099 break;
1100 }
1101 case PT_64BF: {
1102 double *ptr = (double *) data;
1103 ptr += offset;
1104 memcpy(ptr, vals, (size_t)size * len);
1105 break;
1106 }
1107 default: {
1108 rterror("rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
1109 return ES_ERROR;
1110 }
1111 }
1112
1113#if POSTGIS_DEBUG_LEVEL > 0
1114 {
1115 double value;
1116 rt_band_get_pixel(band, x, y, &value, NULL);
1117 RASTER_DEBUGF(4, "pixel at (%d, %d) = %f", x, y, value);
1118 }
1119#endif
1120
1121 /* set band's isnodata flag to FALSE */
1124
1125 return ES_NONE;
1126}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
#define RASTER_DEBUGF(level, msg,...)
Definition librtcore.h:308
rt_pixtype
Definition librtcore.h:188
@ PT_32BUI
Definition librtcore.h:197
@ PT_2BUI
Definition librtcore.h:190
@ PT_32BSI
Definition librtcore.h:196
@ PT_END
Definition librtcore.h:201
@ PT_4BUI
Definition librtcore.h:191
@ PT_32BF
Definition librtcore.h:199
@ PT_1BB
Definition librtcore.h:189
@ PT_16BUI
Definition librtcore.h:195
@ PT_8BSI
Definition librtcore.h:192
@ PT_16BSI
Definition librtcore.h:194
@ PT_64BF
Definition librtcore.h:200
@ PT_8BUI
Definition librtcore.h:193
@ ES_NONE
Definition librtcore.h:182
@ ES_ERROR
Definition librtcore.h:183
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition rt_pixel.c:40
int value
Definition genraster.py:62
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition rt_band.c:854
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition rt_band.c:833
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition rt_band.c:559
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1551

References ES_ERROR, ES_NONE, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, PT_END, RASTER_DEBUGF, rt_band_get_data(), rt_band_get_hasnodata_flag(), rt_band_get_pixel(), rt_band_set_isnodata_flag(), rt_pixtype_size(), and rterror().

Referenced by RASTER_InterpolateRaster(), RASTER_tile(), RASTER_union_transfn(), and rt_raster_from_gdal_dataset().

Here is the call graph for this function:
Here is the caller graph for this function: