PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_gdal_to_raster()

static void test_gdal_to_raster ( )
static

Definition at line 429 of file cu_gdal.c.

429  {
430  rt_pixtype pixtype = PT_64BF;
431  rt_band band = NULL;
432 
434  rt_raster rast;
435  const uint32_t width = 100;
436  const uint32_t height = 100;
437  uint32_t x;
438  uint32_t y;
439  int v;
440  double values[width][height];
441  int rtn = 0;
442  double value;
443 
444  GDALDriverH gddrv = NULL;
445  int destroy = 0;
446  GDALDatasetH gdds = NULL;
447 
448  raster = rt_raster_new(width, height);
449  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
450 
451  band = cu_add_band(raster, pixtype, 1, 0);
452  CU_ASSERT(band != NULL);
453 
454  for (x = 0; x < width; x++) {
455  for (y = 0; y < height; y++) {
456  values[x][y] = (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1);
457  rt_band_set_pixel(band, x, y, values[x][y], NULL);
458  }
459  }
460 
461  gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
462  CU_ASSERT(gddrv != NULL);
463  CU_ASSERT_EQUAL(destroy, 0);
464  CU_ASSERT(gdds != NULL);
465  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
466  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
467 
469  CU_ASSERT(rast != NULL);
470  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
471 
473  CU_ASSERT(band != NULL);
474 
475  for (x = 0; x < width; x++) {
476  for (y = 0; y < height; y++) {
477  rtn = rt_band_get_pixel(band, x, y, &value, NULL);
478  CU_ASSERT_EQUAL(rtn, ES_NONE);
479  CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], DBL_EPSILON);
480  }
481  }
482 
483  GDALClose(gdds);
484  gdds = NULL;
485  gddrv = NULL;
486 
489 
490  raster = rt_raster_new(width, height);
491  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
492 
493  pixtype = PT_8BSI;
494  band = cu_add_band(raster, pixtype, 1, 0);
495  CU_ASSERT(band != NULL);
496 
497  v = -127;
498  for (x = 0; x < width; x++) {
499  for (y = 0; y < height; y++) {
500  values[x][y] = v++;
501  rt_band_set_pixel(band, x, y, values[x][y], NULL);
502  if (v == 128)
503  v = -127;
504  }
505  }
506 
507  gdds = rt_raster_to_gdal_mem(raster, NULL, NULL, NULL, 0, &gddrv, &destroy);
508  CU_ASSERT(gddrv != NULL);
509  CU_ASSERT_EQUAL(destroy, 0);
510  CU_ASSERT(gdds != NULL);
511  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterXSize(gdds), width);
512  CU_ASSERT_EQUAL((uint32_t)GDALGetRasterYSize(gdds), height);
513 
515  CU_ASSERT(rast != NULL);
516  CU_ASSERT_EQUAL(rt_raster_get_num_bands(rast), 1);
517 
519  CU_ASSERT(band != NULL);
520  CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_16BSI);
521 
522  for (x = 0; x < width; x++) {
523  for (y = 0; y < height; y++) {
524  rtn = rt_band_get_pixel(band, x, y, &value, NULL);
525  CU_ASSERT_EQUAL(rtn, ES_NONE);
526  CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], 1.);
527  }
528  }
529 
530  GDALClose(gdds);
531  gdds = NULL;
532  gddrv = NULL;
533 
536 }
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:2182
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:1826
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:61
band
Definition: ovdump.py:57
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)
unsigned int uint32_t
Definition: uthash.h:78

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: