PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ test_gdal_to_raster()

static void test_gdal_to_raster ( )
static

Definition at line 353 of file cu_gdal.c.

353  {
354  rt_pixtype pixtype = PT_64BF;
355  rt_band band = NULL;
356 
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 
393  CU_ASSERT(rast != NULL);
394  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
395 
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 
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 
439  CU_ASSERT(rast != NULL);
440  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
441 
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 
460 }
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_8BSI
Definition: librtcore.h:189
@ PT_16BSI
Definition: librtcore.h:191
@ PT_64BF
Definition: librtcore.h:196
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition: rt_raster.c:2177
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
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:631
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
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
int value
Definition: genraster.py:62
band
Definition: ovdump.py:58
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)

References ovdump::band, cu_add_band(), cu_free_raster(), ES_NONE, PT_16BSI, PT_64BF, PT_8BSI, rtpixdump::rast, rtrowdump::raster, rt_band_get_pixel(), rt_band_get_pixtype(), rt_band_set_pixel(), rt_raster_from_gdal_dataset(), rt_raster_get_band(), rt_raster_get_num_bands(), rt_raster_new(), rt_raster_to_gdal_mem(), genraster::value, pixval::x, and pixval::y.

Referenced by gdal_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: