Skip to content

Commit fa46d2a

Browse files
authored
IH5Dataset: Fix API changes to Get/SetGeoTransform methods in GDAL 3.12 (#196)
* `IH5Dataset`: Fix changes to `GeoTransform` methods in GDAL 3.12 GDAL 3.12 introduced a breaking API change: `GetGeoTransform()` and `SetGeoTransform()` methods now use a `GDALGeoTransform` class instead of raw double* arrays. This patch adds conditional compilation to support both the new GDAL 3.12+ API and older versions. See https://gdal.org/en/stable/user/migration_guide.html * Relax thresholds for geocodeCov checkStatsReal
1 parent 5b2d6f6 commit fa46d2a

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

cxx/isce3/io/IH5Dataset.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,27 +385,56 @@ void * IH5Dataset::GetInternalHandle(const char *)
385385
/* GetGeoTransform() */
386386
/************************************************************************/
387387

388-
CPLErr IH5Dataset::GetGeoTransform( double *padfGeoTransform )
388+
#if GDAL_VERSION_MAJOR >= 4 || (GDAL_VERSION_MAJOR == 3 && GDAL_VERSION_MINOR >= 12)
389+
// GDAL 3.12+ API using GDALGeoTransform class
390+
CPLErr IH5Dataset::GetGeoTransform( GDALGeoTransform &gt ) const
389391
{
390-
memcpy( padfGeoTransform, adfGeoTransform, sizeof(double) * 6 );
392+
gt = GDALGeoTransform(adfGeoTransform);
391393
if( bGeoTransformSet )
392394
return CE_None;
393395

394396
return CE_Failure;
395397
}
398+
#else
399+
// GDAL < 3.12 API using double array
400+
CPLErr IH5Dataset::GetGeoTransform( double *padfTransform )
401+
{
402+
memcpy(padfTransform, adfGeoTransform, sizeof(double) * 6);
403+
if( bGeoTransformSet )
404+
return CE_None;
405+
406+
return CE_Failure;
407+
}
408+
#endif
396409

397410
/************************************************************************/
398411
/* SetGeoTransform() */
399412
/************************************************************************/
400413

401-
CPLErr IH5Dataset::SetGeoTransform( double *padfGeoTransform )
414+
#if GDAL_VERSION_MAJOR >= 4 || (GDAL_VERSION_MAJOR == 3 && GDAL_VERSION_MINOR >= 12)
415+
// GDAL 3.12+ API using GDALGeoTransform class
416+
CPLErr IH5Dataset::SetGeoTransform( const GDALGeoTransform &gt )
417+
{
418+
adfGeoTransform[0] = gt.xorig;
419+
adfGeoTransform[1] = gt.xscale;
420+
adfGeoTransform[2] = gt.xrot;
421+
adfGeoTransform[3] = gt.yorig;
422+
adfGeoTransform[4] = gt.yrot;
423+
adfGeoTransform[5] = gt.yscale;
424+
bGeoTransformSet = TRUE;
402425

426+
return CE_None;
427+
}
428+
#else
429+
// GDAL < 3.12 API using double array
430+
CPLErr IH5Dataset::SetGeoTransform( double *padfTransform )
403431
{
404-
memcpy( adfGeoTransform, padfGeoTransform, sizeof(double) * 6 );
432+
memcpy(adfGeoTransform, padfTransform, sizeof(double) * 6);
405433
bGeoTransformSet = TRUE;
406434

407435
return CE_None;
408436
}
437+
#endif
409438

410439
/************************************************************************/
411440
/* GetGCPCount() */

cxx/isce3/io/IH5Dataset.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <gdal_pam.h>
1212
#include <gdal_priv.h>
1313
#include <gdal_rat.h>
14+
#include <gdal_version.h>
1415
#include "IH5.h"
1516

1617

@@ -62,8 +63,13 @@ class IH5Dataset final: public GDALDataset
6263

6364
void *GetInternalHandle (const char *) override;
6465

66+
#if GDAL_VERSION_MAJOR >= 4 || (GDAL_VERSION_MAJOR == 3 && GDAL_VERSION_MINOR >= 12)
67+
virtual CPLErr GetGeoTransform( GDALGeoTransform &gt ) const override;
68+
virtual CPLErr SetGeoTransform( const GDALGeoTransform &gt ) override;
69+
#else
6570
virtual CPLErr GetGeoTransform( double *padfTransform ) override;
66-
virtual CPLErr SetGeoTransform( double * ) override;
71+
virtual CPLErr SetGeoTransform( double *padfTransform ) override;
72+
#endif
6773
static GDALDataset *Open(GDALOpenInfo *info);
6874
static int Identify(GDALOpenInfo *info);
6975
};

tests/cxx/isce3/geocode/geocodeCov.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,10 @@ void checkStatsReal(isce3::math::Stats<T> computed_stats,
630630
std::cout << "n_valid: " << isce3_stats.n_valid << ", " << computed_stats.n_valid << std::endl;
631631

632632
// Compare Stats struct values with GDAL metadata saved by GeocodeCov
633-
ASSERT_NEAR(isce3_stats.min, raster_min, 1.0e-15);
634-
ASSERT_NEAR(isce3_stats.mean, raster_mean, 1.0e-15);
635-
ASSERT_NEAR(isce3_stats.max, raster_max, 1.0e-15);
636-
ASSERT_NEAR(isce3_stats.sample_stddev(), raster_sample_stddev, 1.0e-15);
633+
ASSERT_NEAR(isce3_stats.min, raster_min, 1.0e-12);
634+
ASSERT_NEAR(isce3_stats.mean, raster_mean, 1.0e-12);
635+
ASSERT_NEAR(isce3_stats.max, raster_max, 1.0e-12);
636+
ASSERT_NEAR(isce3_stats.sample_stddev(), raster_sample_stddev, 1.0e-12);
637637

638638
// Compare Stats struct values with unitest values
639639
ASSERT_NEAR(isce3_stats.min, computed_stats.min, 1.0e-7);

0 commit comments

Comments
 (0)