Skip to content

Commit

Permalink
GTiff: unset geotransform from non-PAM source if PAM defines GCPs, an…
Browse files Browse the repository at this point in the history
…d PAM is the prioritary source
  • Loading branch information
rouault committed Mar 22, 2022
1 parent 1ad18eb commit acbd907
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions frmts/gtiff/geotiff.cpp
Expand Up @@ -13955,6 +13955,8 @@ void GTiffDataset::LookForProjection()
void GTiffDataset::ApplyPamInfo()

{
bool bGotGTFromPAM = false;

if( m_nPAMGeorefSrcIndex >= 0 &&
((m_bGeoTransformValid &&
m_nPAMGeorefSrcIndex < m_nGeoTransformGeorefSrcIndex) ||
Expand All @@ -13970,6 +13972,7 @@ void GTiffDataset::ApplyPamInfo()
}
memcpy(m_adfGeoTransform, adfPamGeoTransform, sizeof(double) * 6);
m_bGeoTransformValid = true;
bGotGTFromPAM = true;
}
}

Expand Down Expand Up @@ -14022,6 +14025,13 @@ void GTiffDataset::ApplyPamInfo()
m_nGCPCount = nPamGCPCount;
m_pasGCPList = GDALDuplicateGCPs(m_nGCPCount, GDALPamDataset::GetGCPs());

// Invalidate Geotransorm got from less prioritary sources
if( m_nGCPCount > 0 && m_bGeoTransformValid && !bGotGTFromPAM &&
m_nPAMGeorefSrcIndex == 0 )
{
m_bGeoTransformValid = false;
}

// m_nProjectionGeorefSrcIndex = m_nPAMGeorefSrcIndex;

const auto* poPamGCPSRS = GDALPamDataset::GetGCPSpatialRef();
Expand Down Expand Up @@ -14090,6 +14100,7 @@ void GTiffDataset::ApplyPamInfo()
m_pasGCPList = nullptr;
m_nGCPCount = 0;
}

m_nGCPCount = static_cast<int>(
adfSourceGCPs.size() / 2);
m_pasGCPList = static_cast<GDAL_GCP *>(
Expand All @@ -14107,6 +14118,14 @@ void GTiffDataset::ApplyPamInfo()
m_pasGCPList[i].dfGCPX = adfTargetGCPs[2*i];
m_pasGCPList[i].dfGCPY = adfTargetGCPs[2*i+1];
}

// Invalidate Geotransorm got from less prioritary sources
if( m_nGCPCount > 0 && m_bGeoTransformValid && !bGotGTFromPAM &&
m_nPAMGeorefSrcIndex == 0 )
{
m_bGeoTransformValid = false;
}

}
}
}
Expand Down

0 comments on commit acbd907

Please sign in to comment.