PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ test_raster_to_gdal()

static void test_raster_to_gdal ( )
static

Definition at line 407 of file cu_gdal.c.

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

407  {
408  rt_pixtype pixtype = PT_64BF;
409  rt_raster raster = NULL;
410  rt_band band = NULL;
411  uint32_t x;
412  uint32_t width = 100;
413  uint32_t y;
414  uint32_t height = 100;
415  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\"]]";
416 
417  uint64_t gdalSize;
418  uint8_t *gdal = NULL;
419 
420  raster = rt_raster_new(width, height);
421  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
422 
423  band = cu_add_band(raster, pixtype, 1, 0);
424  CU_ASSERT(band != NULL);
425 
426  rt_raster_set_offsets(raster, -500000, 600000);
427  rt_raster_set_scale(raster, 1000, -1000);
428 
429  for (x = 0; x < width; x++) {
430  for (y = 0; y < height; y++) {
431  rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
432  }
433  }
434 
435  gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
436  /*printf("gdalSize: %d\n", (int) gdalSize);*/
437  CU_ASSERT(gdalSize);
438 
439  /*
440  FILE *fh = NULL;
441  fh = fopen("/tmp/out.tif", "w");
442  fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
443  fclose(fh);
444  */
445 
446  if (gdal) CPLFree(gdal);
447 
448  cu_free_raster(raster);
449 
450  raster = rt_raster_new(width, height);
451  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
452 
453  band = cu_add_band(raster, pixtype, 1, 0);
454  CU_ASSERT(band != NULL);
455 
456  rt_raster_set_offsets(raster, -500000, 600000);
457  rt_raster_set_scale(raster, 1000, -1000);
458 
459  for (x = 0; x < width; x++) {
460  for (y = 0; y < height; y++) {
461  rt_band_set_pixel(band, x, y, x, NULL);
462  }
463  }
464 
465  /* add check that band isn't NODATA */
466  CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
467 
468  gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
469  /*printf("gdalSize: %d\n", (int) gdalSize);*/
470  CU_ASSERT(gdalSize);
471 
472  if (gdal) CPLFree(gdal);
473 
474  gdal = rt_raster_to_gdal(raster, srs, "PCIDSK", NULL, &gdalSize);
475  CU_ASSERT(gdal == NULL);
476 
477  cu_free_raster(raster);
478 }
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
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)
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1752
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
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
#define FALSE
Definition: dbfopen.c:168
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
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: