Skip to content

Commit

Permalink
Merge pull request OSGeo#8671 from rouault/gdal_create_gcps
Browse files Browse the repository at this point in the history
gdal_create: copy GCPs present in the input file
  • Loading branch information
rouault authored Nov 7, 2023
2 parents 79a868b + 8f17a33 commit 4d94400
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/gdal_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ MAIN_START(argc, argv)
exit(1);
}
}
else if (poInputDS && poInputDS->GetGCPCount() > 0)
{
GDALDataset::FromHandle(hDS)->SetGCPs(poInputDS->GetGCPCount(),
poInputDS->GetGCPs(),
poInputDS->GetGCPSpatialRef());
}

if (!aosMetadata.empty())
{
GDALSetMetadata(hDS, aosMetadata.List(), nullptr);
Expand Down
21 changes: 21 additions & 0 deletions autotest/utilities/test_gdal_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,24 @@ def test_gdal_create_input_file_overrrides(gdal_create_path, tmp_path):
assert ds.GetGeoTransform() == ref_ds.GetGeoTransform()
assert ds.GetProjectionRef() == ref_ds.GetProjectionRef()
ds = None


###############################################################################


def test_gdal_create_input_file_gcps(gdal_create_path, tmp_path):

output_tif = str(tmp_path / "tmp.tif")

(_, err) = gdaltest.runexternal_out_and_err(
gdal_create_path + f" {output_tif} -if ../gcore/data/gcps.vrt"
)
assert err is None or err == "", "got error/warning"

assert os.path.exists(output_tif)

ds = gdal.Open(output_tif)
ref_ds = gdal.Open("../gcore/data/gcps.vrt")
assert ds.GetGCPCount() == ref_ds.GetGCPCount()
assert ds.GetGCPSpatialRef().IsSame(ref_ds.GetGCPSpatialRef())
ds = None

0 comments on commit 4d94400

Please sign in to comment.