Returns new band with values reclassified.
291 {
293 uint32_t width = 0;
294 uint32_t height = 0;
295 int numval = 0;
296 int memsize = 0;
297 void *mem = NULL;
298 uint32_t src_hasnodata = 0;
300
301 assert(NULL != srcband);
302 assert(NULL != map);
303
304
306 rterror(
"%s: reclassification map must contain at least one class pair", __func__);
307
308
310 if (!(src_hasnodata || hasnodata))
311 rterror(
"%s: source band missing nodata value and nodata value not supplied", __func__);
312
313
314
315
316
317 if (!hasnodata && src_hasnodata) {
319 hasnodata = src_hasnodata;
320 }
321
322
325 numval = width * height;
328 mem = (
int *)
rtalloc(memsize);
329 if (!mem)
330 rterror(
"%s: Could not allocate memory for band", __func__);
331
333 if (! band) {
334 rterror(
"%s: Could not add band to raster. Aborting", __func__);
336 return NULL;
337 }
339
340
341
342
343
345
346
347
348
349
351
352 for (uint32_t x = 0;
x < width;
x++) {
353 for (uint32_t y = 0;
y < height;
y++) {
354 int isnodata;
355 double nv = nodataval;
358
359
361 continue;
362
363
364 if (isnodata)
365 continue;
366
367
368
369
370
372 if (!rslt)
373 continue;
374 else
376
377
379
381 rterror(
"%s: Could not assign value to new band", __func__);
384 return NULL;
385 }
386 }
387 }
388
390}
void rt_band_init_value(rt_band band, double initval)
Fill in the cells of a band with a starting value frequently used to init with nodata value.
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
void rt_band_set_ownsdata_flag(rt_band band, int flag)
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
void rt_band_destroy(rt_band band)
Destroy a raster band.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
void rtdealloc(void *mem)
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
static int rt_classpair_cmp(const void *aptr, const void *bptr)
static double rt_band_reclass_round_integer(rt_pixtype pixtype, double nv)
struct rt_classpair_t * pairs