Skip to content

Commit

Permalink
GDALGCPsToGeoTransform(): return FALSE when invalid geotransform is g…
Browse files Browse the repository at this point in the history
…enerated

Fixes case of OSGeo#11618
  • Loading branch information
rouault committed Jan 10, 2025
1 parent 87d8e06 commit 55e1428
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
31 changes: 31 additions & 0 deletions autotest/gcore/gcps2geotransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,34 @@ def test_gcps2gt_8():
1.596921026218e-05,
)
gdaltest.check_geotransform(gt, gt_expected, 0.00001)


###############################################################################
# Test case of https://github.com/OSGeo/gdal/issues/11618


def test_gcps2gt_broken_hour_glass():

gt = gdal.GCPsToGeoTransform(
_list2gcps(
[
(0, 0, 0, 0),
(0, 10, 0, 10),
(10, 0, 10, 10),
(10, 10, 10, 0),
]
)
)
assert gt is None

gt = gdal.GCPsToGeoTransform(
_list2gcps(
[
(0, 0, 0, 0),
(0, 10, 10, 0),
(10, 0, 0, 10),
(10, 10, 10, 10),
]
)
)
assert gt is None
7 changes: 7 additions & 0 deletions gcore/gdal_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3265,6 +3265,13 @@ int CPL_STDCALL GDALGCPsToGeoTransform(int nGCPCount, const GDAL_GCP *pasGCPs,
GDALComposeGeoTransforms(pl_normalize, gt_normalized, gt1p2);
GDALComposeGeoTransforms(gt1p2, inv_geo_normalize, padfGeoTransform);

// "Hour-glass" like shape of GCPs. Cf https://github.com/OSGeo/gdal/issues/11618
if (std::abs(padfGeoTransform[1]) <= 1e-15 ||
std::abs(padfGeoTransform[5]) <= 1e-15)
{
return FALSE;
}

/* -------------------------------------------------------------------- */
/* Now check if any of the input points fit this poorly. */
/* -------------------------------------------------------------------- */
Expand Down

0 comments on commit 55e1428

Please sign in to comment.