@@ -255,7 +255,8 @@ static GDALDatasetH GDALWarpCreateOutput(
255255 int nSrcCount, GDALDatasetH *pahSrcDS, const char *pszFilename,
256256 const char *pszFormat, char **papszTO, CSLConstList papszCreateOptions,
257257 GDALDataType eDT, GDALTransformerArgUniquePtr &hTransformArg,
258- bool bSetColorInterpretation, GDALWarpAppOptions *psOptions);
258+ bool bSetColorInterpretation, GDALWarpAppOptions *psOptions,
259+ bool bUpdateTransformerWithDestGT);
259260
260261static void RemoveConflictingMetadata (GDALMajorObjectH hObj,
261262 CSLConstList papszMetadata,
@@ -1161,17 +1162,18 @@ static bool DealWithCOGOptions(CPLStringList &aosCreateOptions, int nSrcCount,
11611162 return true ;
11621163 };
11631164
1165+ CPLString osTargetSRS;
1166+ if (COGGetTargetSRS (aosCreateOptions.List (), osTargetSRS))
1167+ {
1168+ if (!SetDstSRS (osTargetSRS))
1169+ return false ;
1170+ }
1171+
11641172 if (!(psOptions->dfMinX == 0 && psOptions->dfMinY == 0 &&
11651173 psOptions->dfMaxX == 0 && psOptions->dfMaxY == 0 &&
11661174 psOptions->dfXRes == 0 && psOptions->dfYRes == 0 &&
11671175 psOptions->nForcePixels == 0 && psOptions->nForceLines == 0 ))
11681176 {
1169- CPLString osTargetSRS;
1170- if (COGGetTargetSRS (aosCreateOptions.List (), osTargetSRS))
1171- {
1172- if (!SetDstSRS (osTargetSRS))
1173- return false ;
1174- }
11751177 if (!psOptions->bResampleAlgSpecifiedByUser && nSrcCount > 0 )
11761178 {
11771179 GDALGetWarpResampleAlg (
@@ -1196,15 +1198,14 @@ static bool DealWithCOGOptions(CPLStringList &aosCreateOptions, int nSrcCount,
11961198 nSrcCount, pahSrcDS, osTmpFilename, " GTiff" ,
11971199 oClonedOptions.aosTransformerOptions .List (),
11981200 aosTmpGTiffCreateOptions.List (), oClonedOptions.eOutputType ,
1199- hUniqueTransformArg, false , &oClonedOptions);
1200-
1201+ hUniqueTransformArg, false , &oClonedOptions,
1202+ /* bUpdateTransformerWithDestGT = */ false );
12011203 if (hTmpDS == nullptr )
12021204 {
12031205 return false ;
12041206 }
12051207
12061208 CPLString osResampling;
1207- CPLString osTargetSRS;
12081209 int nXSize = 0 ;
12091210 int nYSize = 0 ;
12101211 double dfMinX = 0 ;
@@ -1219,8 +1220,6 @@ static bool DealWithCOGOptions(CPLStringList &aosCreateOptions, int nSrcCount,
12191220 {
12201221 if (!psOptions->bResampleAlgSpecifiedByUser )
12211222 GDALGetWarpResampleAlg (osResampling, psOptions->eResampleAlg );
1222- if (!SetDstSRS (osTargetSRS))
1223- bRet = false ;
12241223 psOptions->dfMinX = dfMinX;
12251224 psOptions->dfMinY = dfMinY;
12261225 psOptions->dfMaxX = dfMaxX;
@@ -1742,7 +1741,8 @@ CreateOutput(const char *pszDest, int nSrcCount, GDALDatasetH *pahSrcDS,
17421741 nSrcCount, pahSrcDS, pszDest, psOptions->osFormat .c_str (),
17431742 psOptions->aosTransformerOptions .List (),
17441743 psOptions->aosCreateOptions .List (), psOptions->eOutputType ,
1745- hUniqueTransformArg, psOptions->bSetColorInterpretation , psOptions);
1744+ hUniqueTransformArg, psOptions->bSetColorInterpretation , psOptions,
1745+ /* bUpdateTransformerWithDestGT = */ true );
17461746 if (hDstDS == nullptr )
17471747 {
17481748 return nullptr ;
@@ -3507,7 +3507,8 @@ static GDALDatasetH GDALWarpCreateOutput(
35073507 int nSrcCount, GDALDatasetH *pahSrcDS, const char *pszFilename,
35083508 const char *pszFormat, char **papszTO, CSLConstList papszCreateOptions,
35093509 GDALDataType eDT, GDALTransformerArgUniquePtr &hUniqueTransformArg,
3510- bool bSetColorInterpretation, GDALWarpAppOptions *psOptions)
3510+ bool bSetColorInterpretation, GDALWarpAppOptions *psOptions,
3511+ bool bUpdateTransformerWithDestGT)
35113512
35123513{
35133514 GDALDriverH hDriver;
@@ -4855,7 +4856,7 @@ static GDALDatasetH GDALWarpCreateOutput(
48554856 adfDstGeoTransform[5 ] = fabs (adfDstGeoTransform[5 ]);
48564857 }
48574858
4858- if (hUniqueTransformArg)
4859+ if (hUniqueTransformArg && bUpdateTransformerWithDestGT )
48594860 {
48604861 GDALSetGenImgProjTransformerDstGeoTransform (hUniqueTransformArg.get (),
48614862 adfDstGeoTransform);
0 commit comments