PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ test_raster_to_gdal()

static void test_raster_to_gdal ( )
static

Definition at line 280 of file cu_gdal.c.

280  {
281  rt_pixtype pixtype = PT_64BF;
282  rt_raster raster = NULL;
283  rt_band band = NULL;
284  uint32_t x;
285  uint32_t width = 100;
286  uint32_t y;
287  uint32_t height = 100;
288  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\"]]";
289 
290  uint64_t gdalSize;
291  uint8_t *gdal = NULL;
292 
293  raster = rt_raster_new(width, height);
294  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
295 
296  band = cu_add_band(raster, pixtype, 1, 0);
297  CU_ASSERT(band != NULL);
298 
299  rt_raster_set_offsets(raster, -500000, 600000);
300  rt_raster_set_scale(raster, 1000, -1000);
301 
302  for (x = 0; x < width; x++) {
303  for (y = 0; y < height; y++) {
304  rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
305  }
306  }
307 
308  gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
309  /*printf("gdalSize: %d\n", (int) gdalSize);*/
310  CU_ASSERT(gdalSize);
311 
312  /*
313  FILE *fh = NULL;
314  fh = fopen("/tmp/out.tif", "w");
315  fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
316  fclose(fh);
317  */
318 
319  if (gdal) CPLFree(gdal);
320 
322 
323  raster = rt_raster_new(width, height);
324  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
325 
326  band = cu_add_band(raster, pixtype, 1, 0);
327  CU_ASSERT(band != NULL);
328 
329  rt_raster_set_offsets(raster, -500000, 600000);
330  rt_raster_set_scale(raster, 1000, -1000);
331 
332  for (x = 0; x < width; x++) {
333  for (y = 0; y < height; y++) {
334  rt_band_set_pixel(band, x, y, x, NULL);
335  }
336  }
337 
338  /* add check that band isn't NODATA */
339  CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
340 
341  gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
342  /*printf("gdalSize: %d\n", (int) gdalSize);*/
343  CU_ASSERT(gdalSize);
344 
345  if (gdal) CPLFree(gdal);
346 
347  gdal = rt_raster_to_gdal(raster, srs, "PCIDSK", NULL, &gdalSize);
348  CU_ASSERT(gdal == NULL);
349 
351 }
#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:1593
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:58
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)

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: