PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ test_gdal_warp_preserves_data()

static void test_gdal_warp_preserves_data ( void  )
static

Definition at line 536 of file cu_gdal.c.

536  {
537  const char *filename = POSTGIS_TOP_SRC_DIR "/raster/test/regress/loader/Projected.tif";
538 
539  GDALDatasetH hDS_in = NULL;
540  rt_raster rast_in = NULL;
541  rt_raster rast_out = NULL;
542  int band_count_in, band_count_out, i;
543 
544  // double scale_x = 0.0, scale_y = 0.0;
545  // double dim_x = 0.0, dim_y = 0.0;
546  // int width = 0, height = 0;
547  // double grid_xw = 0.0, grid_yw = 0.0;
548  // double skew_x = 0.0, skew_y = 0.0;
549 
550  double max_err = 0.125;
551  GDALResampleAlg alg = GRA_NearestNeighbour;
552 
553  const char *src_srs = "EPSG:4326";
554  const char *dst_srs = "EPSG:3857";
555 
556  /* Handle to TIFF */
557  GDALAllRegister();
558  hDS_in = GDALOpen(filename, GA_ReadOnly);
559  CU_ASSERT(hDS_in != NULL);
560 
561  /* Read TIFF into memory as rt_raster */
562  rast_in = rt_raster_from_gdal_dataset(hDS_in);
563  CU_ASSERT(rast_in != NULL);
564 
565  /* Warp raster using default options */
566  rast_out = rt_raster_gdal_warp(rast_in,
567  src_srs, dst_srs,
568  NULL, NULL, // &scale_x, &scale_y,
569  NULL, NULL, // &dim_x, &dim_y,
570  NULL, NULL, // &width, &height,
571  NULL, NULL, // &grid_xw, &grid_yw,
572  NULL, NULL, // &skew_x, &skew_y,
573  alg, max_err);
574  CU_ASSERT(rast_out != NULL);
575 
576  band_count_in = rt_raster_get_num_bands(rast_in);
577  band_count_out = rt_raster_get_num_bands(rast_out);
578  CU_ASSERT_EQUAL(band_count_in, band_count_out);
579 
580  for (i = 0; i < band_count_in; i++) {
581  double tolerance = 0.1;
582  rt_bandstats stats_in, stats_out;
583  rt_band band_in = rt_raster_get_band(rast_in, i);
584  rt_band band_out = rt_raster_get_band(rast_out, i);
585 
586  CU_ASSERT(band_in != NULL);
587  CU_ASSERT(band_out != NULL);
588 
589  stats_in = rt_band_get_summary_stats(band_in, 1, 1, 0, NULL, NULL, NULL);
590  stats_out = rt_band_get_summary_stats(band_out, 1, 1, 0, NULL, NULL, NULL);
591 
592  CU_ASSERT_DOUBLE_EQUAL(stats_in->min, stats_out->min, fabs(stats_in->min) * tolerance);
593  CU_ASSERT_DOUBLE_EQUAL(stats_in->max, stats_out->max, fabs(stats_in->max) * tolerance);
594  CU_ASSERT_DOUBLE_EQUAL(stats_in->mean, stats_out->mean, fabs(stats_in->mean) * tolerance);
595  }
596 
597  rt_raster_destroy(rast_in);
598  rt_raster_destroy(rast_out);
599  GDALClose(hDS_in);
600 }
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: