PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ test_gdal_to_raster()

static void test_gdal_to_raster ( )
static

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

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