24 #include "CUnit/Basic.h"
40 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
48 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 0, DBL_EPSILON);
49 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
56 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 24, DBL_EPSILON);
57 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
64 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
71 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 12, DBL_EPSILON);
72 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
79 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 8, DBL_EPSILON);
80 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
87 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 1, DBL_EPSILON);
88 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
100 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
108 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 0, DBL_EPSILON);
109 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
111 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
118 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 24, DBL_EPSILON);
119 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
121 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 118, DBL_EPSILON);
122 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
129 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
131 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 100, DBL_EPSILON);
132 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
139 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 12, DBL_EPSILON);
140 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
142 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 106, DBL_EPSILON);
143 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
150 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 8, DBL_EPSILON);
151 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
153 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 102, DBL_EPSILON);
154 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
161 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 1, DBL_EPSILON);
162 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
164 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
171 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 16, DBL_EPSILON);
172 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
174 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
181 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
183 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
195 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
203 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
205 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 100, DBL_EPSILON);
206 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
213 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 21, DBL_EPSILON);
214 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
216 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 115, DBL_EPSILON);
217 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
224 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 9, DBL_EPSILON);
225 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
227 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 103, DBL_EPSILON);
228 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
235 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 24, DBL_EPSILON);
236 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
238 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 118, DBL_EPSILON);
239 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
246 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 16, DBL_EPSILON);
247 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
249 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
261 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
269 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 0, DBL_EPSILON);
270 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
272 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
279 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 24, DBL_EPSILON);
280 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
282 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 118, DBL_EPSILON);
283 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
290 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 9, DBL_EPSILON);
291 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
293 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 103, DBL_EPSILON);
294 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
301 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 4, DBL_EPSILON);
302 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
304 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
316 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
324 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
326 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 100, DBL_EPSILON);
327 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
334 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
336 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 124, DBL_EPSILON);
337 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
344 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 1);
346 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 109, DBL_EPSILON);
347 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
354 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 16, DBL_EPSILON);
355 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
357 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
369 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
377 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 16, DBL_EPSILON);
378 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
380 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
387 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 17, DBL_EPSILON);
388 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
390 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 111, DBL_EPSILON);
391 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
398 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 21, DBL_EPSILON);
399 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
401 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 115, DBL_EPSILON);
402 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
409 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 22, DBL_EPSILON);
410 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
412 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][0][0], 116, DBL_EPSILON);
413 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 0);
425 CU_ASSERT_EQUAL(arg->
rows, _userarg->
rows);
433 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][1][1], 16, DBL_EPSILON);
434 CU_ASSERT_EQUAL(arg->
nodata[0][1][1], 0);
436 CU_ASSERT_EQUAL(arg->
nodata[1][1][1], 1);
438 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 10, DBL_EPSILON);
439 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
441 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
448 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][1][1], 17, DBL_EPSILON);
449 CU_ASSERT_EQUAL(arg->
nodata[0][1][1], 0);
451 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][1][1], 111, DBL_EPSILON);
452 CU_ASSERT_EQUAL(arg->
nodata[1][1][1], 0);
454 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][2][2], 23, DBL_EPSILON);
455 CU_ASSERT_EQUAL(arg->
nodata[0][2][2], 0);
457 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][2][2], 117, DBL_EPSILON);
458 CU_ASSERT_EQUAL(arg->
nodata[1][2][2], 0);
465 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][1][1], 21, DBL_EPSILON);
466 CU_ASSERT_EQUAL(arg->
nodata[0][1][1], 0);
468 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][1][1], 115, DBL_EPSILON);
469 CU_ASSERT_EQUAL(arg->
nodata[1][1][1], 0);
471 CU_ASSERT_EQUAL(arg->
nodata[0][2][0], 1);
473 CU_ASSERT_EQUAL(arg->
nodata[1][2][0], 1);
480 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][1][1], 22, DBL_EPSILON);
481 CU_ASSERT_EQUAL(arg->
nodata[0][1][1], 0);
483 CU_ASSERT_DOUBLE_EQUAL(arg->
values[1][1][1], 116, DBL_EPSILON);
484 CU_ASSERT_EQUAL(arg->
nodata[1][1][1], 0);
486 CU_ASSERT_DOUBLE_EQUAL(arg->
values[0][0][0], 16, DBL_EPSILON);
487 CU_ASSERT_EQUAL(arg->
nodata[0][0][0], 0);
489 CU_ASSERT_EQUAL(arg->
nodata[1][0][0], 1);
513 CU_ASSERT(rast1 != NULL);
519 CU_ASSERT(
band != NULL);
521 for (
y = 0;
y < maxY;
y++) {
522 for (
x = 0;
x < maxX;
x++) {
528 CU_ASSERT(rast2 != NULL);
534 CU_ASSERT(
band != NULL);
536 for (
y = 0;
y < maxY;
y++) {
537 for (
x = 0;
x < maxX;
x++) {
543 CU_ASSERT(rast3 != NULL);
550 CU_ASSERT(userargs != NULL);
554 CU_ASSERT(itrset != NULL);
578 CU_ASSERT_EQUAL(noerr,
ES_NONE);
608 CU_ASSERT_EQUAL(noerr,
ES_NONE);
638 CU_ASSERT_EQUAL(noerr,
ES_NONE);
664 CU_ASSERT_EQUAL(noerr,
ES_NONE);
690 CU_ASSERT_EQUAL(noerr,
ES_NONE);
716 CU_ASSERT_EQUAL(noerr,
ES_NONE);
742 CU_ASSERT_EQUAL(noerr,
ES_NONE);
772 CU_ASSERT_EQUAL(noerr,
ES_NONE);
811 CU_ASSERT(
raster != NULL);
813 CU_ASSERT(
band != NULL);
816 for (
x = 0;
x < 100;
x++) {
817 for (
y = 0;
y < 10;
y++) {
823 CU_ASSERT_DOUBLE_EQUAL(nodata, 0, DBL_EPSILON);
826 CU_ASSERT(exprset != NULL);
828 for (i = 0; i < cnt; i++) {
830 CU_ASSERT(exprset[i] != NULL);
851 exprset[i]->
src.
max = 1000;
856 exprset[i]->
dst.
max = 255;
861 CU_ASSERT(newband != NULL);
865 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
869 CU_ASSERT_DOUBLE_EQUAL(val, 77, DBL_EPSILON);
873 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
875 for (i = cnt - 1; i >= 0; i--)
rtdealloc(exprset[i]);
893 CU_ASSERT(
raster != NULL);
895 CU_ASSERT(
band != NULL);
898 for (
y = 0;
y < 9;
y++) {
899 for (
x = 0;
x < 9;
x++) {
905 CU_ASSERT(colormap != NULL);
908 CU_ASSERT(colormap->
entry != NULL);
933 colormap->
method = CM_INTERPOLATE;
939 CU_ASSERT(rtn != NULL);
943 CU_ASSERT(
band != NULL);
945 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
947 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
949 CU_ASSERT_DOUBLE_EQUAL(
value, 255, DBL_EPSILON);
960 CU_ASSERT(rtn != NULL);
965 colormap->
method = CM_EXACT;
971 CU_ASSERT(rtn != NULL);
975 CU_ASSERT(
band != NULL);
977 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
979 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
981 CU_ASSERT_DOUBLE_EQUAL(
value, 255, DBL_EPSILON);
983 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
985 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
990 colormap->
method = CM_NEAREST;
996 CU_ASSERT(rtn != NULL);
1000 CU_ASSERT(
band != NULL);
1002 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
1004 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1006 CU_ASSERT_DOUBLE_EQUAL(
value, 255, DBL_EPSILON);
1008 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
1010 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1012 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1014 CU_ASSERT_DOUBLE_EQUAL(
value, 255, DBL_EPSILON);
1020 colormap->
method = CM_NEAREST;
1026 CU_ASSERT(rtn != NULL);
1030 CU_ASSERT(
band != NULL);
1032 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1034 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1036 CU_ASSERT_DOUBLE_EQUAL(
value, 255, DBL_EPSILON);
1038 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1040 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1042 CU_ASSERT_DOUBLE_EQUAL(
value, 127, DBL_EPSILON);
1044 CU_ASSERT_DOUBLE_EQUAL(
value, 255, DBL_EPSILON);
1055 CU_ASSERT(
raster != NULL);
1057 CU_ASSERT(
band != NULL);
1060 for (
y = 0;
y < 10;
y++) {
1061 for (
x = 0;
x < 10;
x++) {
1067 CU_ASSERT(colormap != NULL);
1070 CU_ASSERT(colormap->
entry != NULL);
1144 colormap->
method = CM_INTERPOLATE;
1150 CU_ASSERT(rtn != NULL);
1154 CU_ASSERT(
band != NULL);
1156 CU_ASSERT_DOUBLE_EQUAL(
value, 0, DBL_EPSILON);
1158 CU_ASSERT_DOUBLE_EQUAL(
value, 14, DBL_EPSILON);
1160 CU_ASSERT_DOUBLE_EQUAL(
value, 17, DBL_EPSILON);
1162 CU_ASSERT_DOUBLE_EQUAL(
value, 25, DBL_EPSILON);
1165 CU_ASSERT_DOUBLE_EQUAL(
value, 28, DBL_EPSILON);
1167 CU_ASSERT_DOUBLE_EQUAL(
value, 43, DBL_EPSILON);
1169 CU_ASSERT_DOUBLE_EQUAL(
value, 57, DBL_EPSILON);
1172 CU_ASSERT_DOUBLE_EQUAL(
value, 170, DBL_EPSILON);
1174 CU_ASSERT_DOUBLE_EQUAL(
value, 198, DBL_EPSILON);
1176 CU_ASSERT_DOUBLE_EQUAL(
value, 227, DBL_EPSILON);
1190 CU_pSuite suite = CU_add_suite(
"mapalgebra", NULL, NULL);
static void test_raster_iterator()
static int testRasterIterator5_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static int testRasterIterator7_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static void test_raster_colormap()
static int testRasterIterator2_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
void mapalgebra_suite_setup(void)
static int testRasterIterator1_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
struct _callback_userargs_t * _callback_userargs
static int testRasterIterator3_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static int testRasterIterator4_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static int testRasterIterator6_callback(rt_iterator_arg arg, void *userarg, double *value, int *nodata)
static void test_band_reclass()
#define PG_ADD_TEST(suite, testfunc)
rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, rt_reclassexpr *exprset, int exprcount)
Returns new band with values reclassified.
void * rtalloc(size_t size)
Wrappers used for managing memory.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
rt_raster rt_raster_colormap(rt_raster raster, int nband, rt_colormap colormap)
Returns a new raster with up to four 8BUI bands (RGBA) from applying a colormap to the user-specified...
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
struct rt_colormap_entry_t * rt_colormap_entry
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata 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.
uint16_t rt_raster_get_num_bands(rt_raster raster)
uint16_t rt_raster_get_height(rt_raster raster)
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
uint16_t rt_raster_get_width(rt_raster raster)
void rtdealloc(void *mem)
struct rt_colormap_t * rt_colormap
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)
enum rt_colormap_t::@9 method
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst