PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_raster_to_gdal()

static void test_raster_to_gdal ( )
static

Definition at line 304 of file cu_gdal.c.

304 {
305 rt_pixtype pixtype = PT_64BF;
306 rt_raster raster = NULL;
307 rt_band band = NULL;
308 uint32_t x;
309 uint32_t width = 100;
310 uint32_t y;
311 uint32_t height = 100;
312 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\"]]";
313
314 uint64_t gdalSize;
315 uint8_t *gdal = NULL;
316
317 raster = rt_raster_new(width, height);
318 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
319
320 band = cu_add_band(raster, pixtype, 1, 0);
321 CU_ASSERT(band != NULL);
322
323 rt_raster_set_offsets(raster, -500000, 600000);
324 rt_raster_set_scale(raster, 1000, -1000);
325
326 for (x = 0; x < width; x++) {
327 for (y = 0; y < height; y++) {
328 rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
329 }
330 }
331
332 gdal = rt_raster_to_gdal(raster, srs, "GTiff", NULL, &gdalSize);
333 /*printf("gdalSize: %d\n", (int) gdalSize);*/
334 CU_ASSERT(gdalSize);
335
336 /*
337 FILE *fh = NULL;
338 fh = fopen("/tmp/out.tif", "w");
339 fwrite(gdal, sizeof(uint8_t), gdalSize, fh);
340 fclose(fh);
341 */
342
343 if (gdal) CPLFree(gdal);
344
345 cu_free_raster(raster);
346
347 raster = rt_raster_new(width, height);
348 CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
349
350 band = cu_add_band(raster, pixtype, 1, 0);
351 CU_ASSERT(band != NULL);
352
353 rt_raster_set_offsets(raster, -500000, 600000);
354 rt_raster_set_scale(raster, 1000, -1000);
355
356 for (x = 0; x < width; x++) {
357 for (y = 0; y < height; y++) {
358 rt_band_set_pixel(band, x, y, x, NULL);
359 }
360 }
361
362 /* add check that band isn't NODATA */
363 CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
364
365 gdal = rt_raster_to_gdal(raster, srs, "PNG", NULL, &gdalSize);
366 /*printf("gdalSize: %d\n", (int) gdalSize);*/
367 CU_ASSERT(gdalSize);
368
369 if (gdal) CPLFree(gdal);
370
371 gdal = rt_raster_to_gdal(raster, srs, "PCIDSK", NULL, &gdalSize);
372 CU_ASSERT(gdal == NULL);
373
374 cu_free_raster(raster);
375}
#define FALSE
Definition dbfopen.c:72
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition rt_raster.c:141
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:188
@ PT_64BF
Definition librtcore.h:200
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition rt_raster.c:52
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition rt_band.c:2089
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:1140
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition rt_raster.c:203
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition rtrowdump.py:125
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)

References cu_add_band(), cu_free_raster(), FALSE, PT_64BF, rt_band_check_is_nodata(), rt_band_set_pixel(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), and rt_raster_to_gdal().

Referenced by gdal_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: