PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
cu_gdal.c
Go to the documentation of this file.
1/*
2 * PostGIS Raster - Raster Types for PostGIS
3 * http://trac.osgeo.org/postgis/wiki/WKTRaster
4 *
5 * Copyright (C) 2012 Regents of the University of California
6 * <bkpark@ucdavis.edu>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 *
22 */
23
24#include "CUnit/Basic.h"
25#include "cu_tester.h"
26
27static void test_gdal_configured() {
28 CU_ASSERT(rt_util_gdal_configured());
29}
30
31static void test_gdal_drivers() {
32 uint32_t i;
33 uint32_t size;
34 rt_gdaldriver drv = NULL;
35
36 drv = (rt_gdaldriver) rt_raster_gdal_drivers(&size, 1);
37 CU_ASSERT(drv != NULL);
38
39 for (i = 0; i < size; i++) {
40 CU_ASSERT(strlen(drv[i].short_name));
41 rtdealloc(drv[i].short_name);
42 rtdealloc(drv[i].long_name);
43 rtdealloc(drv[i].create_options);
44 }
45
46 rtdealloc(drv);
47}
48
49static void test_gdal_rasterize() {
50 rt_raster raster;
51 char srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
52 const char wkb_hex[] = "010300000001000000050000000000000080841ec100000000600122410000000080841ec100000000804f22410000000040e81dc100000000804f22410000000040e81dc100000000600122410000000080841ec10000000060012241";
53 const char *pos = wkb_hex;
54 unsigned char *wkb = NULL;
55 int wkb_len = 0;
56 int i;
57 double scale_x = 100;
58 double scale_y = -100;
59
60 rt_pixtype pixtype[] = {PT_8BUI};
61 double init[] = {0};
62 double value[] = {1};
63 double nodata[] = {0};
64 uint8_t nodata_mask[] = {1};
65
66 /* hex to byte */
67 wkb_len = (int) ceil(((double) strlen(wkb_hex)) / 2);
68 wkb = (unsigned char *) rtalloc(sizeof(unsigned char) * wkb_len);
69 for (i = 0; i < wkb_len; i++) {
70 int b = 0;
71 sscanf(pos, "%2x", &b);
72 wkb[i] = (unsigned char)b;
73 pos += 2;
74 }
75
77 wkb,
78 wkb_len, srs,
79 1, pixtype,
80 init, value,
81 nodata, nodata_mask,
82 NULL, NULL,
83 &scale_x, &scale_y,
84 NULL, NULL,
85 NULL, NULL,
86 NULL, NULL,
87 NULL
88 );
89
90 CU_ASSERT(raster != NULL);
91 CU_ASSERT_EQUAL(rt_raster_get_width(raster), 100);
92 CU_ASSERT_EQUAL(rt_raster_get_height(raster), 100);
93 CU_ASSERT_NOT_EQUAL(rt_raster_get_num_bands(raster), 0);
94 CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_x_offset(raster), -500000, DBL_EPSILON);
95 CU_ASSERT_DOUBLE_EQUAL(rt_raster_get_y_offset(raster), 600000, DBL_EPSILON);
96
97 rtdealloc(wkb);
98 cu_free_raster(raster);
99}
100
101static rt_raster fillRasterToPolygonize(int hasnodata, double nodataval) {
102 rt_band band = NULL;
103 rt_pixtype pixtype = PT_32BF;
104
105 /* Create raster */
106 uint16_t width = 9;
107 uint16_t height = 9;
108
109 rt_raster raster = rt_raster_new(width, height);
110 rt_raster_set_scale(raster, 1, 1);
111
112 band = cu_add_band(raster, pixtype, hasnodata, nodataval);
113 CU_ASSERT(band != NULL);
114
115 {
116 int x, y;
117 for (x = 0; x < rt_band_get_width(band); ++x)
118 for (y = 0; y < rt_band_get_height(band); ++y)
119 rt_band_set_pixel(band, x, y, 0.0, NULL);
120 }
121
122 rt_band_set_pixel(band, 3, 1, 1.8, NULL);
123 rt_band_set_pixel(band, 4, 1, 1.8, NULL);
124 rt_band_set_pixel(band, 5, 1, 2.8, NULL);
125 rt_band_set_pixel(band, 2, 2, 1.8, NULL);
126 rt_band_set_pixel(band, 3, 2, 1.8, NULL);
127 rt_band_set_pixel(band, 4, 2, 1.8, NULL);
128 rt_band_set_pixel(band, 5, 2, 2.8, NULL);
129 rt_band_set_pixel(band, 6, 2, 2.8, NULL);
130 rt_band_set_pixel(band, 1, 3, 1.8, NULL);
131 rt_band_set_pixel(band, 2, 3, 1.8, NULL);
132 rt_band_set_pixel(band, 6, 3, 2.8, NULL);
133 rt_band_set_pixel(band, 7, 3, 2.8, NULL);
134 rt_band_set_pixel(band, 1, 4, 1.8, NULL);
135 rt_band_set_pixel(band, 2, 4, 1.8, NULL);
136 rt_band_set_pixel(band, 6, 4, 2.8, NULL);
137 rt_band_set_pixel(band, 7, 4, 2.8, NULL);
138 rt_band_set_pixel(band, 1, 5, 1.8, NULL);
139 rt_band_set_pixel(band, 2, 5, 1.8, NULL);
140 rt_band_set_pixel(band, 6, 5, 2.8, NULL);
141 rt_band_set_pixel(band, 7, 5, 2.8, NULL);
142 rt_band_set_pixel(band, 2, 6, 1.8, NULL);
143 rt_band_set_pixel(band, 3, 6, 1.8, NULL);
144 rt_band_set_pixel(band, 4, 6, 1.8, NULL);
145 rt_band_set_pixel(band, 5, 6, 2.8, NULL);
146 rt_band_set_pixel(band, 6, 6, 2.8, NULL);
147 rt_band_set_pixel(band, 3, 7, 1.8, NULL);
148 rt_band_set_pixel(band, 4, 7, 1.8, NULL);
149 rt_band_set_pixel(band, 5, 7, 2.8, NULL);
150
151 return raster;
152}
153
154static void test_gdal_polygonize() {
155 int i;
156 rt_raster rt;
157 int nPols = 0;
158 double total_area = 0;
159 double total_val = 0;
160 rt_geomval gv = NULL;
161 LWGEOM *gobserved;
162 //char *wkt = NULL;
163
164 rt = fillRasterToPolygonize(1, -1.0);
165 CU_ASSERT(rt_raster_has_band(rt, 0));
166
167 nPols = 0;
168 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
169 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
170 total_area = 0; total_val = 0;
171 for (i = 0; i < nPols; i++) {
172 total_val += gv[i].val;
173 gobserved = (LWGEOM *) gv[i].geom;
174 total_area += lwgeom_area(gobserved);
175 lwgeom_free((LWGEOM *) gv[i].geom);
176 }
177 printf("total area, total val, nPols = %f, %f, %i\n", total_area, total_val, nPols);
178 CU_ASSERT_DOUBLE_EQUAL(total_val, 1.8 + 0.0 + 2.8 + 0, FLT_EPSILON);
179 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
180
181 rtdealloc(gv);
182 cu_free_raster(rt);
183
184 /* Second test: NODATA value = 1.8 */
185 rt = fillRasterToPolygonize(1, 1.8);
186
187 /* We can check rt_raster_has_band here too */
188 CU_ASSERT(rt_raster_has_band(rt, 0));
189
190 nPols = 0;
191 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
192 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
193 total_area = 0; total_val = 0;
194 for (i = 0; i < nPols; i++) {
195 total_val += gv[i].val;
196 gobserved = (LWGEOM *) gv[i].geom;
197 total_area += lwgeom_area(gobserved);
198 lwgeom_free((LWGEOM *) gv[i].geom);
199 }
200 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
201 CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
202 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
203
204
205 rtdealloc(gv);
206 cu_free_raster(rt);
207
208 /* Third test: NODATA value = 2.8 */
209 rt = fillRasterToPolygonize(1, 2.8);
210
211 /* We can check rt_raster_has_band here too */
212 CU_ASSERT(rt_raster_has_band(rt, 0));
213
214 nPols = 0;
215 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
216 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
217 total_area = 0; total_val = 0;
218 for (i = 0; i < nPols; i++) {
219 total_val += gv[i].val;
220 gobserved = (LWGEOM *) gv[i].geom;
221 total_area += lwgeom_area(gobserved);
222 lwgeom_free((LWGEOM *) gv[i].geom);
223 }
224
225 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
226 CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
227 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
228
229 rtdealloc(gv);
230 cu_free_raster(rt);
231
232 /* Fourth test: NODATA value = 0 */
233 rt = fillRasterToPolygonize(1, 0.0);
234 /* We can check rt_raster_has_band here too */
235 CU_ASSERT(rt_raster_has_band(rt, 0));
236
237 nPols = 0;
238 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
239
240 CU_ASSERT_DOUBLE_EQUAL(nPols, 2, FLT_EPSILON);
241 total_area = 0; total_val = 0;
242 for (i = 0; i < nPols; i++) {
243 total_val += gv[i].val;
244 gobserved = (LWGEOM *) gv[i].geom;
245 total_area += lwgeom_area(gobserved);
246 lwgeom_free((LWGEOM *) gv[i].geom);
247 }
248
249 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
250 CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
251 CU_ASSERT_DOUBLE_EQUAL(total_area, 28, FLT_EPSILON);
252
253 rtdealloc(gv);
254 cu_free_raster(rt);
255
256 /* Last test: There is no NODATA value (all values are valid) */
257 rt = fillRasterToPolygonize(0, 0.0);
258 /* We can check rt_raster_has_band here too */
259 CU_ASSERT(rt_raster_has_band(rt, 0));
260
261 nPols = 0;
262 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
263
264 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
265 total_area = 0; total_val = 0;
266 for (i = 0; i < nPols; i++) {
267 total_val += gv[i].val;
268 gobserved = (LWGEOM *) gv[i].geom;
269 total_area += lwgeom_area(gobserved);
270 lwgeom_free((LWGEOM *) gv[i].geom);
271 }
272
273 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
274 CU_ASSERT_DOUBLE_EQUAL(total_val, 1.8 + 0.0 + 2.8 + 0.0, FLT_EPSILON);
275 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
276 rtdealloc(gv);
277 cu_free_raster(rt);
278}
279
280static void test_raster_to_gdal() {
281 rt_pixtype pixtype = PT_64BF;
282 rt_raster raster = NULL;
283 rt_band band = NULL;
284 uint32_t x;
285 uint32_t width = 100;
286 uint32_t y;
287 uint32_t height = 100;
288 char srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
289
290 uint64_t gdalSize;
291 uint8_t *gdal = NULL;
292
293 raster = rt_raster_new(width, height);
294 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
295
296 band = cu_add_band(raster, pixtype, 1, 0);
297 CU_ASSERT(band != NULL);
298
299 rt_raster_set_offsets(raster, -500000, 600000);
300 rt_raster_set_scale(raster, 1000, -1000);
301
302 for (x = 0; x < width; x++) {
303 for (y = 0; y < height; y++) {
304 rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
305 }
306 }
307
308 gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
309 /*printf("gdalSize: %d\n", (int) gdalSize);*/
310 CU_ASSERT(gdalSize);
311
312 /*
313 FILE *fh = NULL;
314 fh = fopen("/tmp/out.tif", "w");
315 fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
316 fclose(fh);
317 */
318
319 if (gdal) CPLFree(gdal);
320
321 cu_free_raster(raster);
322
323 raster = rt_raster_new(width, height);
324 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
325
326 band = cu_add_band(raster, pixtype, 1, 0);
327 CU_ASSERT(band != NULL);
328
329 rt_raster_set_offsets(raster, -500000, 600000);
330 rt_raster_set_scale(raster, 1000, -1000);
331
332 for (x = 0; x < width; x++) {
333 for (y = 0; y < height; y++) {
334 rt_band_set_pixel(band, x, y, x, NULL);
335 }
336 }
337
338 /* add check that band isn't NODATA */
339 CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
340
341 gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
342 /*printf("gdalSize: %d\n", (int) gdalSize);*/
343 CU_ASSERT(gdalSize);
344
345 if (gdal) CPLFree(gdal);
346
347 gdal = rt_raster_to_gdal(raster, srs, "PCIDSK", NULL, &gdalSize);
348 CU_ASSERT(gdal == NULL);
349
350 cu_free_raster(raster);
351}
352
353static void test_gdal_to_raster() {
354 rt_pixtype pixtype = PT_64BF;
355 rt_band band = NULL;
356
357 rt_raster raster;
358 rt_raster rast;
359 const uint32_t width = 100;
360 const uint32_t height = 100;
361 uint32_t x;
362 uint32_t y;
363 int v;
364 double values[width][height];
365 int rtn = 0;
366 double value;
367
368 GDALDriverH gddrv = NULL;
369 int destroy = 0;
370 GDALDatasetH gdds = NULL;
371
372 raster = rt_raster_new(width, height);
373 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
374
375 band = cu_add_band(raster, pixtype, 1, 0);
376 CU_ASSERT(band != NULL);
377
378 for (x = 0; x < width; x++) {
379 for (y = 0; y < height; y++) {
380 values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1);
381 rt_band_set_pixel(band, x, y, values[x][y], NULL);
382 }
383 }
384
385 gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
386 CU_ASSERT(gddrv != NULL);
387 CU_ASSERT_EQUAL(destroy, 0);
388 CU_ASSERT(gdds != NULL);
389 CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
390 CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
391
392 rast = rt_raster_from_gdal_dataset(gdds);
393 CU_ASSERT(rast != NULL);
394 CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
395
396 band = rt_raster_get_band(rast, 0);
397 CU_ASSERT(band != NULL);
398
399 for (x = 0; x < width; x++) {
400 for (y = 0; y < height; y++) {
401 rtn = rt_band_get_pixel(band, x, y, &value, NULL);
402 CU_ASSERT_EQUAL(rtn, ES_NONE);
403 CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], DBL_EPSILON);
404 }
405 }
406
407 GDALClose(gdds);
408 gdds = NULL;
409 gddrv = NULL;
410
411 cu_free_raster(rast);
412 cu_free_raster(raster);
413
414 raster = rt_raster_new(width, height);
415 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
416
417 pixtype = PT_8BSI;
418 band = cu_add_band(raster, pixtype, 1, 0);
419 CU_ASSERT(band != NULL);
420
421 v = -127;
422 for (x = 0; x < width; x++) {
423 for (y = 0; y < height; y++) {
424 values[x][y] = v++;
425 rt_band_set_pixel(band, x, y, values[x][y], NULL);
426 if (v == 128)
427 v = -127;
428 }
429 }
430
431 gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
432 CU_ASSERT(gddrv != NULL);
433 CU_ASSERT_EQUAL(destroy, 0);
434 CU_ASSERT(gdds != NULL);
435 CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
436 CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
437
438 rast = rt_raster_from_gdal_dataset(gdds);
439 CU_ASSERT(rast != NULL);
440 CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
441
442 band = rt_raster_get_band(rast, 0);
443 CU_ASSERT(band != NULL);
444 CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_16BSI);
445
446 for (x = 0; x < width; x++) {
447 for (y = 0; y < height; y++) {
448 rtn = rt_band_get_pixel(band, x, y, &value, NULL);
449 CU_ASSERT_EQUAL(rtn, ES_NONE);
450 CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], 1.);
451 }
452 }
453
454 GDALClose(gdds);
455 gdds = NULL;
456 gddrv = NULL;
457
458 cu_free_raster(rast);
459 cu_free_raster(raster);
460}
461
462static void test_gdal_warp() {
463 rt_pixtype pixtype = PT_64BF;
464 rt_band band = NULL;
465
466 rt_raster raster;
467 rt_raster rast;
468 uint32_t x;
469 uint32_t width = 100;
470 uint32_t y;
471 uint32_t height = 100;
472 double value = 0;
473
474 char src_srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
475
476 char dst_srs[] = "PROJCS[\"NAD83 / California Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"standard_parallel_1\",34],PARAMETER[\"standard_parallel_2\",40.5],PARAMETER[\"latitude_of_center\",0],PARAMETER[\"longitude_of_center\",-120],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",-4000000],AUTHORITY[\"EPSG\",\"3310\"],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
477
478 raster = rt_raster_new(width, height);
479 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
480
481 band = cu_add_band(raster, pixtype, 1, 0);
482 CU_ASSERT(band != NULL);
483
484 rt_raster_set_offsets(raster, -500000, 600000);
485 rt_raster_set_scale(raster, 1000, -1000);
486
487 for (x = 0; x < width; x++) {
488 for (y = 0; y < height; y++) {
489 rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
490 }
491 }
492
493 rast = rt_raster_gdal_warp(
494 raster,
495 src_srs, dst_srs,
496 NULL, NULL,
497 NULL, NULL,
498 NULL, NULL,
499 NULL, NULL,
500 NULL, NULL,
501 GRA_NearestNeighbour, -1
502 );
503 CU_ASSERT(rast != NULL);
504 CU_ASSERT_EQUAL(rt_raster_get_width(rast), 122);
505 CU_ASSERT_EQUAL(rt_raster_get_height(rast), 116);
506 CU_ASSERT_NOT_EQUAL(rt_raster_get_num_bands(rast), 0);
507
508 band = rt_raster_get_band(rast, 0);
509 CU_ASSERT(band != NULL);
510
511 CU_ASSERT(rt_band_get_hasnodata_flag(band));
512 rt_band_get_nodata(band, &value);
513 CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);
514
515 CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, NULL), ES_NONE);
516 CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);
517
518 cu_free_raster(rast);
519 cu_free_raster(raster);
520}
521
522/* register tests */
523void gdal_suite_setup(void);
525{
526 CU_pSuite suite = CU_add_suite("gdal", NULL, NULL);
534}
535
static rt_raster fillRasterToPolygonize(int hasnodata, double nodataval)
Definition cu_gdal.c:101
static void test_gdal_warp()
Definition cu_gdal.c:462
static void test_gdal_rasterize()
Definition cu_gdal.c:49
static void test_gdal_to_raster()
Definition cu_gdal.c:353
static void test_raster_to_gdal()
Definition cu_gdal.c:280
void gdal_suite_setup(void)
Definition cu_gdal.c:524
static void test_gdal_drivers()
Definition cu_gdal.c:31
static void test_gdal_configured()
Definition cu_gdal.c:27
static void test_gdal_polygonize()
Definition cu_gdal.c:154
#define TRUE
Definition dbfopen.c:169
#define FALSE
Definition dbfopen.c:168
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1138
double lwgeom_area(const LWGEOM *geom)
Definition lwgeom.c:1863
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:171
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition rt_band.c:640
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition rt_raster.c:213
int rt_util_gdal_configured(void)
Definition rt_util.c:317
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition rt_raster.c:1711
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition rt_raster.c:137
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition rt_band.c:674
uint8_t * rt_raster_to_gdal(rt_raster raster, const char *srs, char *format, char **options, uint64_t *gdalsize)
Return formatted GDAL raster from raster.
Definition rt_raster.c:1593
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1221
rt_pixtype
Definition librtcore.h:185
@ PT_32BF
Definition librtcore.h:195
@ PT_8BSI
Definition librtcore.h:189
@ PT_16BSI
Definition librtcore.h:191
@ PT_64BF
Definition librtcore.h:196
@ PT_8BUI
Definition librtcore.h:190
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition rt_raster.c:48
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition rt_raster.c:1342
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition rt_raster.c:2177
rt_geomval rt_raster_gdal_polygonize(rt_raster raster, int nband, int exclude_nodata_value, int *pnElements)
Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided...
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition rt_band.c:1752
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition rt_band.c:974
@ ES_NONE
Definition librtcore.h:180
rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb, uint32_t wkb_len, const char *srs, uint32_t num_bands, rt_pixtype *pixtype, double *init, double *value, double *nodata, uint8_t *hasnodata, int *width, int *height, double *scale_x, double *scale_y, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, char **options)
Return a raster of the provided geometry.
Definition rt_raster.c:2504
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:372
struct rt_gdaldriver_t * rt_gdaldriver
Definition librtcore.h:154
uint16_t rt_raster_get_height(rt_raster raster)
Definition rt_raster.c:129
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:1730
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition rt_band.c:631
uint16_t rt_raster_get_width(rt_raster raster)
Definition rt_raster.c:121
void rtdealloc(void *mem)
Definition rt_context.c:186
rt_raster rt_raster_gdal_warp(rt_raster raster, const char *src_srs, const char *dst_srs, double *scale_x, double *scale_y, int *width, int *height, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, GDALResampleAlg resample_alg, double max_err)
Return a warped raster using GDAL Warp API.
Definition rt_warp.c:178
GDALDatasetH rt_raster_to_gdal_mem(rt_raster raster, const char *srs, uint32_t *bandNums, int *excludeNodataValues, int count, GDALDriverH *rtn_drv, int *destroy_rtn_drv)
Return GDAL dataset using GDAL MEM driver from raster.
Definition rt_raster.c:1821
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition rt_raster.c:199
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition rt_band.c:649
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition rt_raster.c:222
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition rt_raster.c:381
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)