Returns new band with values reclassified.
73 {
75 uint32_t width = 0;
76 uint32_t height = 0;
77 int numval = 0;
78 int memsize = 0;
79 void *mem = NULL;
80 uint32_t src_hasnodata = 0;
81 double src_nodataval = 0.0;
82 int isnodata = 0;
83
84 int rtn;
87 int i;
88 double or = 0;
89 double ov = 0;
90 double nr = 0;
91 double nv = 0;
92 int do_nv = 0;
94
95 assert(NULL != srcband);
96 assert(NULL != exprset && exprcount > 0);
99
100
102 if (src_hasnodata)
104
105
108 numval = width * height;
110 mem = (
int *)
rtalloc(memsize);
111 if (!mem) {
112 rterror(
"rt_band_reclass: Could not allocate memory for band");
113 return 0;
114 }
115
117 if (!band) {
118 rterror(
"rt_band_reclass: Could not create new band");
120 return 0;
121 }
124
126
127 for (x = 0;
x < width;
x++) {
128 for (y = 0;
y < height;
y++) {
130
131
134 continue;
135 }
136 RASTER_DEBUGF(4,
"(x, y, ov, isnodata) = (%d, %d, %f, %d)", x, y, ov, isnodata);
137
138 do {
139 do_nv = 0;
140
141
142 if (hasnodata && isnodata) {
143 do_nv = 1;
144 break;
145 }
146
147 for (i = 0; i < exprcount; i++) {
148 expr = exprset[i];
149
150
151 if (
154 ) {
155 do_nv = 1;
156 break;
157 }
158
159
160 if ((
164 )) || (
168 )) || (
170 )) {
171
172 if ((
176 )) || (
178 ov < expr->src.max ||
180 )) || (
181 ov < expr->src.max
182 )) {
183 do_nv = 1;
184 break;
185 }
186 }
187 }
188 }
189 while (0);
190
191
192 if (!do_nv) continue;
194
195
196
197
198
199
200
201
202 if (hasnodata && isnodata) {
203 nv = nodataval;
204 }
205
206
207
208
211 }
212 else {
215 nv = (((ov - expr->
src.
min) * nr) / or) + expr->
dst.
min;
216
217
221 else if (nv < expr->dst.max)
223 }
224
225 else {
226 if (nv < expr->dst.min)
228 else if (nv > expr->
dst.
max)
230 }
231 }
232
233
235
236 RASTER_DEBUGF(4,
"(%d, %d) ov: %f or: %f - %f nr: %f - %f nv: %f"
237 , x
238 , y
239 , ov
240 , (NULL != expr) ? expr->
src.
min : 0
241 , (NULL != expr) ? expr->src.max : 0
242 , (NULL != expr) ? expr->dst.min : 0
243 , (NULL != expr) ? expr->dst.max : 0
244 , nv
245 );
247 rterror(
"rt_band_reclass: Could not assign value to new band");
250 return 0;
251 }
252
253 expr = NULL;
254 }
255 }
256
258}
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.
#define RASTER_DEBUGF(level, msg,...)
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 double rt_band_reclass_round_integer(rt_pixtype pixtype, double nv)
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst