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

◆ test_gdal_warp_preserves_data()

static void test_gdal_warp_preserves_data ( void  )
static

Definition at line 560 of file cu_gdal.c.

560 {
561 const char *filename = POSTGIS_TOP_SRC_DIR "/raster/test/regress/loader/Projected.tif";
562
563 GDALDatasetH hDS_in = NULL;
564 rt_raster rast_in = NULL;
565 rt_raster rast_out = NULL;
566 int band_count_in, band_count_out, i;
567
568 // double scale_x = 0.0, scale_y = 0.0;
569 // double dim_x = 0.0, dim_y = 0.0;
570 // int width = 0, height = 0;
571 // double grid_xw = 0.0, grid_yw = 0.0;
572 // double skew_x = 0.0, skew_y = 0.0;
573
574 double max_err = 0.125;
575 GDALResampleAlg alg = GRA_NearestNeighbour;
576
577 const char *src_srs = "EPSG:4326";
578 const char *dst_srs = "EPSG:3857";
579
580 /* Handle to TIFF */
581 GDALAllRegister();
582 hDS_in = GDALOpen(filename, GA_ReadOnly);
583 CU_ASSERT(hDS_in != NULL);
584
585 /* Read TIFF into memory as rt_raster */
586 rast_in = rt_raster_from_gdal_dataset(hDS_in);
587 CU_ASSERT(rast_in != NULL);
588
589 /* Warp raster using default options */
590 rast_out = rt_raster_gdal_warp(rast_in,
591 src_srs, dst_srs,
592 NULL, NULL, // &scale_x, &scale_y,
593 NULL, NULL, // &dim_x, &dim_y,
594 NULL, NULL, // &width, &height,
595 NULL, NULL, // &grid_xw, &grid_yw,
596 NULL, NULL, // &skew_x, &skew_y,
597 alg, max_err);
598 CU_ASSERT(rast_out != NULL);
599
600 band_count_in = rt_raster_get_num_bands(rast_in);
601 band_count_out = rt_raster_get_num_bands(rast_out);
602 CU_ASSERT_EQUAL(band_count_in, band_count_out);
603
604 for (i = 0; i < band_count_in; i++) {
605 double tolerance = 0.1;
606 rt_bandstats stats_in, stats_out;
607 rt_band band_in = rt_raster_get_band(rast_in, i);
608 rt_band band_out = rt_raster_get_band(rast_out, i);
609
610 CU_ASSERT(band_in != NULL);
611 CU_ASSERT(band_out != NULL);
612
613 stats_in = rt_band_get_summary_stats(band_in, 1, 1, 0, NULL, NULL, NULL);
614 stats_out = rt_band_get_summary_stats(band_out, 1, 1, 0, NULL, NULL, NULL);
615
616 CU_ASSERT_DOUBLE_EQUAL(stats_in->min, stats_out->min, fabs(stats_in->min) * tolerance);
617 CU_ASSERT_DOUBLE_EQUAL(stats_in->max, stats_out->max, fabs(stats_in->max) * tolerance);
618 CU_ASSERT_DOUBLE_EQUAL(stats_in->mean, stats_out->mean, fabs(stats_in->mean) * tolerance);
619 }
620
621 rt_raster_destroy(rast_in);
622 rt_raster_destroy(rast_out);
623 GDALClose(hDS_in);
624}
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition rt_raster.c:86
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition rt_raster.c:2175
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:376
rt_raster rt_raster_gdal_warp(rt_raster raster, const char *src_srs, const char *dst_srs, double *scale_x, double *scale_y, int *width, int *height, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, GDALResampleAlg resample_alg, double max_err)
Return a warped raster using GDAL Warp API.
Definition rt_warp.c:177
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ)
Compute summary statistics for a band.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition rt_raster.c:385

References rt_bandstats_t::max, rt_bandstats_t::mean, rt_bandstats_t::min, rt_band_get_summary_stats(), rt_raster_destroy(), rt_raster_from_gdal_dataset(), rt_raster_gdal_warp(), rt_raster_get_band(), and rt_raster_get_num_bands().

Referenced by gdal_suite_setup().

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