PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_raster_to_gdal()

static void test_raster_to_gdal ( )
static

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

349  {
350  rt_pixtype pixtype = PT_64BF;
351  rt_raster raster = NULL;
352  rt_band band = NULL;
353  uint32_t x;
354  uint32_t width = 100;
355  uint32_t y;
356  uint32_t height = 100;
357  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\"]]";
358 
359  uint64_t gdalSize;
360  uint8_t *gdal = NULL;
361 
362  raster = rt_raster_new(width, height);
363  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
364 
365  band = cu_add_band(raster, pixtype, 1, 0);
366  CU_ASSERT(band != NULL);
367 
368  rt_raster_set_offsets(raster, -500000, 600000);
369  rt_raster_set_scale(raster, 1000, -1000);
370 
371  for (x = 0; x < width; x++) {
372  for (y = 0; y < height; y++) {
373  rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
374  }
375  }
376 
377  gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
378  /*printf("gdalSize: %d\n", (int) gdalSize);*/
379  CU_ASSERT(gdalSize);
380 
381  /*
382  FILE *fh = NULL;
383  fh = fopen("/tmp/out.tif", "w");
384  fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
385  fclose(fh);
386  */
387 
388  if (gdal) CPLFree(gdal);
389 
390  cu_free_raster(raster);
391 
392  raster = rt_raster_new(width, height);
393  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
394 
395  band = cu_add_band(raster, pixtype, 1, 0);
396  CU_ASSERT(band != NULL);
397 
398  rt_raster_set_offsets(raster, -500000, 600000);
399  rt_raster_set_scale(raster, 1000, -1000);
400 
401  for (x = 0; x < width; x++) {
402  for (y = 0; y < height; y++) {
403  rt_band_set_pixel(band, x, y, x, NULL);
404  }
405  }
406 
407  /* add check that band isn't NODATA */
408  CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
409 
410  gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
411  /*printf("gdalSize: %d\n", (int) gdalSize);*/
412  CU_ASSERT(gdalSize);
413 
414  if (gdal) CPLFree(gdal);
415 
416  cu_free_raster(raster);
417 }
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:1619
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:1602
#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:841
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: