PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ test_gdal_to_raster()

static void test_gdal_to_raster ( )
static

Definition at line 480 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().

480  {
481  rt_pixtype pixtype = PT_64BF;
482  rt_band band = NULL;
483 
485  rt_raster rast;
486  const uint32_t width = 100;
487  const uint32_t height = 100;
488  uint32_t x;
489  uint32_t y;
490  int v;
491  double values[width][height];
492  int rtn = 0;
493  double value;
494 
495  GDALDriverH gddrv = NULL;
496  int destroy = 0;
497  GDALDatasetH gdds = NULL;
498 
499  raster = rt_raster_new(width, height);
500  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
501 
502  band = cu_add_band(raster, pixtype, 1, 0);
503  CU_ASSERT(band != NULL);
504 
505  for (x = 0; x < width; x++) {
506  for (y = 0; y < height; y++) {
507  values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1);
508  rt_band_set_pixel(band, x, y, values[x][y], NULL);
509  }
510  }
511 
512  gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
513  CU_ASSERT(gddrv != NULL);
514  CU_ASSERT_EQUAL(destroy, 0);
515  CU_ASSERT(gdds != NULL);
516  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
517  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
518 
519  rast = rt_raster_from_gdal_dataset(gdds);
520  CU_ASSERT(rast != NULL);
521  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
522 
523  band = rt_raster_get_band(rast, 0);
524  CU_ASSERT(band != NULL);
525 
526  for (x = 0; x < width; x++) {
527  for (y = 0; y < height; y++) {
528  rtn = rt_band_get_pixel(band, x, y, &value, NULL);
529  CU_ASSERT_EQUAL(rtn, ES_NONE);
530  CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], DBL_EPSILON);
531  }
532  }
533 
534  GDALClose(gdds);
535  gdds = NULL;
536  gddrv = NULL;
537 
538  cu_free_raster(rast);
539  cu_free_raster(raster);
540 
541  raster = rt_raster_new(width, height);
542  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
543 
544  pixtype = PT_8BSI;
545  band = cu_add_band(raster, pixtype, 1, 0);
546  CU_ASSERT(band != NULL);
547 
548  v = -127;
549  for (x = 0; x < width; x++) {
550  for (y = 0; y < height; y++) {
551  values[x][y] = v++;
552  rt_band_set_pixel(band, x, y, values[x][y], NULL);
553  if (v == 128)
554  v = -127;
555  }
556  }
557 
558  gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
559  CU_ASSERT(gddrv != NULL);
560  CU_ASSERT_EQUAL(destroy, 0);
561  CU_ASSERT(gdds != NULL);
562  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
563  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
564 
565  rast = rt_raster_from_gdal_dataset(gdds);
566  CU_ASSERT(rast != NULL);
567  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
568 
569  band = rt_raster_get_band(rast, 0);
570  CU_ASSERT(band != NULL);
571  CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_16BSI);
572 
573  for (x = 0; x < width; x++) {
574  for (y = 0; y < height; y++) {
575  rtn = rt_band_get_pixel(band, x, y, &value, NULL);
576  CU_ASSERT_EQUAL(rtn, ES_NONE);
577  CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], 1.);
578  }
579  }
580 
581  GDALClose(gdds);
582  gdds = NULL;
583  gddrv = NULL;
584 
585  cu_free_raster(rast);
586  cu_free_raster(raster);
587 }
uint16_t 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:1826
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:1221
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:631
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:974
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:2182
Here is the call graph for this function:
Here is the caller graph for this function: