Set single pixel's value.
- Parameters
-
| band | : the band to set value to |
| x | : x ordinate (0-based) |
| y | : y ordinate (0-based) |
| val | : the pixel value |
| converted | : (optional) non-zero if value truncated/clamped/converted |
- Returns
- ES_NONE on success, ES_ERROR on error
Definition at line 1125 of file rt_band.c.
1130 {
1132 uint8_t *
data = NULL;
1133 uint32_t offset = 0;
1134
1135 int32_t checkvalint = 0;
1136 uint32_t checkvaluint = 0;
1137 float checkvalfloat = 0;
1138 double checkvaldouble = 0;
1139
1140 assert(NULL != band);
1141
1142 if (converted != NULL)
1143 *converted = 0;
1144
1145 if (
band->offline) {
1146 rterror(
"rt_band_set_pixel not implemented yet for OFFDB bands");
1148 }
1149
1150 pixtype =
band->pixtype;
1151
1152 if (
1153 x < 0 || x >=
band->width ||
1154 y < 0 || y >=
band->height
1155 ) {
1156 rterror(
"rt_band_set_pixel: Coordinates out of range");
1158 }
1159
1160
1162 double newval;
1163 int corrected;
1164
1166
1167 if (corrected) {
1168#if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
1169 rtwarn(
"Value for pixel %d x %d has been corrected as clamped value becomes NODATA", x, y);
1170#endif
1171 val = newval;
1172
1173 if (converted != NULL)
1174 *converted = 1;
1175 }
1176 }
1177
1179 offset =
x + (
y *
band->width);
1180
1181 switch (pixtype) {
1184 checkvalint =
data[offset];
1185 break;
1186 }
1189 checkvalint =
data[offset];
1190 break;
1191 }
1194 checkvalint =
data[offset];
1195 break;
1196 }
1199 checkvalint = (int8_t) data[offset];
1200 break;
1201 }
1204 checkvalint =
data[offset];
1205 break;
1206 }
1208 int16_t *ptr = (int16_t*) data;
1210 checkvalint = (int16_t) ptr[offset];
1211 break;
1212 }
1214 uint16_t *ptr = (uint16_t*) data;
1216 checkvalint = ptr[offset];
1217 break;
1218 }
1220 int32_t *ptr = (int32_t*) data;
1222 checkvalint = (int32_t) ptr[offset];
1223 break;
1224 }
1226 uint32_t *ptr = (uint32_t*) data;
1228 checkvaluint = ptr[offset];
1229 break;
1230 }
1232 float *ptr = (float*) data;
1234 checkvalfloat = ptr[offset];
1235 break;
1236 }
1238 double *ptr = (double*) data;
1239 ptr[offset] = val;
1240 checkvaldouble = ptr[offset];
1241 break;
1242 }
1243 default: {
1244 rterror(
"rt_band_set_pixel: Unknown pixeltype %d", pixtype);
1246 }
1247 }
1248
1249
1251 RASTER_DEBUG(3,
"Band has a value that is not NODATA. Setting isnodata to FALSE");
1253 }
1254
1255
1257 val,
1258 checkvalint, checkvaluint,
1259 checkvalfloat, checkvaldouble,
1260 pixtype
1261 ) && converted != NULL) {
1262 *converted = 1;
1263 }
1264
1266}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
int8_t rt_util_clamp_to_8BSI(double value)
uint8_t rt_util_clamp_to_1BB(double value)
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
int32_t rt_util_clamp_to_32BSI(double value)
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
uint8_t rt_util_clamp_to_2BUI(double value)
uint8_t rt_util_clamp_to_8BUI(double value)
int16_t rt_util_clamp_to_16BSI(double value)
uint8_t rt_util_clamp_to_4BUI(double value)
uint16_t rt_util_clamp_to_16BUI(double value)
uint32_t rt_util_clamp_to_32BUI(double value)
float rt_util_clamp_to_32F(double value)
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
rt_errorstate rt_band_corrected_clamped_value(rt_band band, double val, double *newval, int *corrected)
Correct value when clamped value is equal to clamped NODATA value.
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
References ES_ERROR, ES_NONE, FALSE, 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_DEBUG, rt_band_clamped_value_is_nodata(), rt_band_corrected_clamped_value(), rt_band_get_data(), rt_util_clamp_to_16BSI(), rt_util_clamp_to_16BUI(), rt_util_clamp_to_1BB(), rt_util_clamp_to_2BUI(), rt_util_clamp_to_32BSI(), rt_util_clamp_to_32BUI(), rt_util_clamp_to_32F(), rt_util_clamp_to_4BUI(), rt_util_clamp_to_8BSI(), rt_util_clamp_to_8BUI(), rt_util_dbl_trunc_warning(), rterror(), and rtwarn().
Referenced by fillRasterToPolygonize(), RASTER_clip(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_mapAlgebraFct(), RASTER_mapAlgebraFctNgb(), RASTER_setPixelValue(), RASTER_setPixelValuesArray(), RASTER_setPixelValuesGeomval(), rt_band_reclass(), rt_band_reclass_exact(), rt_raster_gdal_rasterize(), rt_raster_iterator(), test_band_get_nearest_pixel(), test_band_get_pixel_line(), test_band_get_pixel_of_value(), test_band_pixtype_16BSI(), test_band_pixtype_16BUI(), test_band_pixtype_1BB(), test_band_pixtype_2BUI(), test_band_pixtype_32BF(), test_band_pixtype_32BSI(), test_band_pixtype_32BUI(), test_band_pixtype_4BUI(), test_band_pixtype_64BF(), test_band_pixtype_8BSI(), test_band_pixtype_8BUI(), test_band_reclass(), test_band_stats(), test_band_value_count(), test_gdal_to_raster(), test_gdal_warp(), test_pixel_set_to_array(), test_raster_colormap(), test_raster_fully_within_distance(), test_raster_geos_contains(), test_raster_geos_contains_properly(), test_raster_geos_covered_by(), test_raster_geos_covers(), test_raster_geos_overlaps(), test_raster_geos_touches(), test_raster_get_pixel_bilinear(), test_raster_intersects(), test_raster_iterator(), test_raster_perimeter(), test_raster_pixel_as_polygon(), test_raster_surface(), test_raster_to_gdal(), and test_raster_within_distance().