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 1004 of file rt_band.c.
1008 {
1010 int size = 0;
1011 uint8_t *
data = NULL;
1012 uint32_t offset = 0;
1013
1014 assert(NULL != band);
1015 assert(vals != NULL && len > 0);
1016
1018
1019 if (
band->offline) {
1020 rterror(
"rt_band_set_pixel_line not implemented yet for OFFDB bands");
1022 }
1023
1024 pixtype =
band->pixtype;
1026
1027 if (
1028 x < 0 || x >=
band->width ||
1029 y < 0 || y >=
band->height
1030 ) {
1031 rterror(
"rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y,
band->width,
band->height);
1033 }
1034
1036 offset =
x + (
y *
band->width);
1038
1039
1040 if (len > (
band->width *
band->height) - offset) {
1041 rterror(
"rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
1043 }
1044
1045 switch (pixtype) {
1051 uint8_t *ptr =
data;
1052 ptr += offset;
1053 memcpy(ptr, vals, (size_t)size * len);
1054 break;
1055 }
1057 uint16_t *ptr = (uint16_t *) data;
1058 ptr += offset;
1059 memcpy(ptr, vals, (size_t)size * len);
1060 break;
1061 }
1063 int16_t *ptr = (int16_t *) data;
1064 ptr += offset;
1065 memcpy(ptr, vals, (size_t)size * len);
1066 break;
1067 }
1069 uint32_t *ptr = (uint32_t *) data;
1070 ptr += offset;
1071 memcpy(ptr, vals, (size_t)size * len);
1072 break;
1073 }
1075 int32_t *ptr = (int32_t *) data;
1076 ptr += offset;
1077 memcpy(ptr, vals, (size_t)size * len);
1078 break;
1079 }
1081 float *ptr = (float *) data;
1082 ptr += offset;
1083 memcpy(ptr, vals, (size_t)size * len);
1084 break;
1085 }
1087 double *ptr = (double *) data;
1088 ptr += offset;
1089 memcpy(ptr, vals, (size_t)size * len);
1090 break;
1091 }
1092 default: {
1093 rterror(
"rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
1095 }
1096 }
1097
1098#if POSTGIS_DEBUG_LEVEL > 0
1099 {
1103 }
1104#endif
1105
1106
1109
1111}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
#define RASTER_DEBUGF(level, msg,...)
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
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().