PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_gdal_to_raster()

static void test_gdal_to_raster ( )
static

Definition at line 419 of file cu_gdal.c.

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().

419  {
420  rt_pixtype pixtype = PT_64BF;
421  rt_band band = NULL;
422 
424  rt_raster rast;
425  const uint32_t width = 100;
426  const uint32_t height = 100;
427  uint32_t x;
428  uint32_t y;
429  int v;
430  double values[width][height];
431  int rtn = 0;
432  double value;
433 
434  GDALDriverH gddrv = NULL;
435  int destroy = 0;
436  GDALDatasetH gdds = NULL;
437 
438  raster = rt_raster_new(width, height);
439  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
440 
441  band = cu_add_band(raster, pixtype, 1, 0);
442  CU_ASSERT(band != NULL);
443 
444  for (x = 0; x < width; x++) {
445  for (y = 0; y < height; y++) {
446  values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1);
447  rt_band_set_pixel(band, x, y, values[x][y], NULL);
448  }
449  }
450 
451  gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
452  CU_ASSERT(gddrv != NULL);
453  CU_ASSERT_EQUAL(destroy, 0);
454  CU_ASSERT(gdds != NULL);
455  CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
456  CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);
457 
458  rast = rt_raster_from_gdal_dataset(gdds);
459  CU_ASSERT(rast != NULL);
460  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
461 
462  band = rt_raster_get_band(rast, 0);
463  CU_ASSERT(band != NULL);
464 
465  for (x = 0; x < width; x++) {
466  for (y = 0; y < height; y++) {
467  rtn = rt_band_get_pixel(band, x, y, &value, NULL);
468  CU_ASSERT_EQUAL(rtn, ES_NONE);
469  CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], DBL_EPSILON);
470  }
471  }
472 
473  GDALClose(gdds);
474  gdds = NULL;
475  gddrv = NULL;
476 
477  cu_free_raster(rast);
478  cu_free_raster(raster);
479 
480  raster = rt_raster_new(width, height);
481  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
482 
483  pixtype = PT_8BSI;
484  band = cu_add_band(raster, pixtype, 1, 0);
485  CU_ASSERT(band != NULL);
486 
487  v = -127;
488  for (x = 0; x < width; x++) {
489  for (y = 0; y < height; y++) {
490  values[x][y] = v++;
491  rt_band_set_pixel(band, x, y, values[x][y], NULL);
492  if (v == 128)
493  v = -127;
494  }
495  }
496 
497  gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
498  CU_ASSERT(gddrv != NULL);
499  CU_ASSERT_EQUAL(destroy, 0);
500  CU_ASSERT(gdds != NULL);
501  CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
502  CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);
503 
504  rast = rt_raster_from_gdal_dataset(gdds);
505  CU_ASSERT(rast != NULL);
506  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
507 
508  band = rt_raster_get_band(rast, 0);
509  CU_ASSERT(band != NULL);
510  CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_16BSI);
511 
512  for (x = 0; x < width; x++) {
513  for (y = 0; y < height; y++) {
514  rtn = rt_band_get_pixel(band, x, y, &value, NULL);
515  CU_ASSERT_EQUAL(rtn, ES_NONE);
516  CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], 1.);
517  }
518  }
519 
520  GDALClose(gdds);
521  gdds = NULL;
522  gddrv = NULL;
523 
524  cu_free_raster(rast);
525  cu_free_raster(raster);
526 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
band
Definition: ovdump.py:57
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:1809
rt_pixtype
Definition: librtcore.h:185
unsigned int uint32_t
Definition: uthash.h:78
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1088
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:498
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:841
int value
Definition: genraster.py:61
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition: rt_raster.c:2165
Here is the call graph for this function:
Here is the caller graph for this function: