Skip to content

Commit

Permalink
Merge pull request #4593 from rouault/gtiff_baseline
Browse files Browse the repository at this point in the history
GTiff: write georeferencing info to PAM .aux.xml when using PROFILE=BASELINE
  • Loading branch information
rouault authored Oct 5, 2021
2 parents a8c25e3 + 1e4d7f0 commit 2b253b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
22 changes: 12 additions & 10 deletions autotest/gcore/tiff_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ def test_tiff_write_16():
ds.SetMetadata({'test': 'testvalue'})
ds.GetRasterBand(1).SetMetadata({'testBand': 'testvalueBand'})

srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
ds.SetSpatialRef(srs)
ds.SetGeoTransform((10, 5, 0, 30, 0, -5))

data = ds_in.ReadRaster(0, 0, 20, 20)
Expand All @@ -449,9 +452,12 @@ def test_tiff_write_16():
ds_in = None
ds = None

# Check first from PAM
assert gdal.VSIStatL('tmp/tw_16.tif.aux.xml') is not None
ds = gdal.Open('tmp/tw_16.tif')
assert ds.GetGeoTransform() == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0), \
'Got wrong geotransform, profile ignored?'
assert ds.GetGeoTransform() == (10, 5, 0, 30, 0, -5)
assert ds.GetSpatialRef() is not None
assert ds.GetSpatialRef().GetAuthorityCode(None) == '4326'

md = ds.GetMetadata()
assert 'test' in md, 'Metadata absent from .aux.xml file.'
Expand All @@ -460,16 +466,12 @@ def test_tiff_write_16():
assert 'testBand' in md, 'Metadata absent from .aux.xml file.'

ds = None

try:
os.remove('tmp/tw_16.tif.aux.xml')
except OSError:
try:
os.stat('tmp/tw_16.tif.aux.xml')
except OSError:
pytest.fail('No .aux.xml file.')
gdal.Unlink('tmp/tw_16.tif.aux.xml')

ds = gdal.Open('tmp/tw_16.tif')
assert ds.GetGeoTransform() == (0.0, 1.0, 0.0, 0.0, 0.0, 1.0), \
'Got wrong geotransform, profile ignored?'
assert ds.GetSpatialRef() is None

md = ds.GetMetadata()
assert 'test' not in md, 'Metadata written to BASELINE file.'
Expand Down
20 changes: 20 additions & 0 deletions gdal/frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18765,6 +18765,12 @@ CPLErr GTiffDataset::SetSpatialRef( const OGRSpatialReference * poSRS )

m_bGeoTIFFInfoChanged = true;

if( (m_eProfile == GTiffProfile::BASELINE) &&
(GetPamFlags() & GPF_DISABLED) == 0 )
{
GDALPamDataset::SetSpatialRef(poSRS);
}

return CE_None;
}

Expand Down Expand Up @@ -18848,6 +18854,14 @@ CPLErr GTiffDataset::SetGeoTransform( double * padfTransform )
m_bGeoTransformValid = true;
m_bGeoTIFFInfoChanged = true;

if( (m_eProfile == GTiffProfile::BASELINE) &&
!CPLFetchBool( m_papszCreationOptions, "TFW", false ) &&
!CPLFetchBool( m_papszCreationOptions, "WORLDFILE", false ) &&
(GetPamFlags() & GPF_DISABLED) == 0 )
{
GDALPamDataset::SetGeoTransform(padfTransform);
}

return CE_None;
}
else
Expand Down Expand Up @@ -18957,6 +18971,12 @@ CPLErr GTiffDataset::SetGCPs( int nGCPCountIn, const GDAL_GCP *pasGCPListIn,

m_bGeoTIFFInfoChanged = true;

if( (m_eProfile == GTiffProfile::BASELINE) &&
(GetPamFlags() & GPF_DISABLED) == 0 )
{
GDALPamDataset::SetGCPs(nGCPCountIn, pasGCPListIn, poGCPSRS);
}

return CE_None;
}
else
Expand Down

0 comments on commit 2b253b9

Please sign in to comment.