PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_raster_to_gdal()

static void test_raster_to_gdal ( )
static

Definition at line 356 of file cu_gdal.c.

356  {
357  rt_pixtype pixtype = PT_64BF;
358  rt_raster raster = NULL;
359  rt_band band = NULL;
360  uint32_t x;
361  uint32_t width = 100;
362  uint32_t y;
363  uint32_t height = 100;
364  char srs[] = "PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
365 
366  uint64_t gdalSize;
367  uint8_t *gdal = NULL;
368 
369  raster = rt_raster_new(width, height);
370  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
371 
372  band = cu_add_band(raster, pixtype, 1, 0);
373  CU_ASSERT(band != NULL);
374 
375  rt_raster_set_offsets(raster, -500000, 600000);
376  rt_raster_set_scale(raster, 1000, -1000);
377 
378  for (x = 0; x < width; x++) {
379  for (y = 0; y < height; y++) {
380  rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
381  }
382  }
383 
384  gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
385  /*printf("gdalSize: %d\n", (int) gdalSize);*/
386  CU_ASSERT(gdalSize);
387 
388  /*
389  FILE *fh = NULL;
390  fh = fopen("/tmp/out.tif", "w");
391  fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
392  fclose(fh);
393  */
394 
395  if (gdal) CPLFree(gdal);
396 
398 
399  raster = rt_raster_new(width, height);
400  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
401 
402  band = cu_add_band(raster, pixtype, 1, 0);
403  CU_ASSERT(band != NULL);
404 
405  rt_raster_set_offsets(raster, -500000, 600000);
406  rt_raster_set_scale(raster, 1000, -1000);
407 
408  for (x = 0; x < width; x++) {
409  for (y = 0; y < height; y++) {
410  rt_band_set_pixel(band, x, y, x, NULL);
411  }
412  }
413 
414  /* add check that band isn't NODATA */
415  CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
416 
417  gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
418  /*printf("gdalSize: %d\n", (int) gdalSize);*/
419  CU_ASSERT(gdalSize);
420 
421  if (gdal) CPLFree(gdal);
422 
423  gdal = rt_raster_to_gdal(raster, srs, "PCIDSK", NULL, &gdalSize);
424  CU_ASSERT(gdal == NULL);
425 
427 }
#define FALSE
Definition: dbfopen.c:168
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
uint8_t * rt_raster_to_gdal(rt_raster raster, const char *srs, char *format, char **options, uint64_t *gdalsize)
Return formatted GDAL raster from raster.
Definition: rt_raster.c:1598
rt_pixtype
Definition: librtcore.h:185
@ 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
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1752
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
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
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
unsigned char uint8_t
Definition: uthash.h:79

References ovdump::band, cu_add_band(), cu_free_raster(), FALSE, PT_64BF, rtrowdump::raster, rt_band_check_is_nodata(), rt_band_set_pixel(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rt_raster_to_gdal(), 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: