@@ -56,7 +56,9 @@ struct GDALTileIndexRasterMetadata
5656
5757struct GDALTileIndexOptions
5858{
59+ bool bInvokedFromGdalRasterIndex = false ;
5960 bool bOverwrite = false ;
61+ bool bSkipErrors = false ;
6062 std::string osFormat{};
6163 std::string osIndexLayerName{};
6264 std::string osLocationField = " location" ;
@@ -106,6 +108,16 @@ static std::unique_ptr<GDALArgumentParser> GDALTileIndexAppOptionsGetParser(
106108 _ (" For more details, see the full documentation for gdaltindex at\n "
107109 " https://gdal.org/programs/gdaltindex.html" ));
108110
111+ // Hidden as used by gdal raster index
112+ argParser->add_argument (" --invoked-from-gdal-raster-index" )
113+ .store_into (psOptions->bInvokedFromGdalRasterIndex )
114+ .hidden ();
115+
116+ // Hidden as used by gdal raster index
117+ argParser->add_argument (" -skip_errors" )
118+ .store_into (psOptions->bSkipErrors )
119+ .hidden ();
120+
109121 argParser->add_argument (" -overwrite" )
110122 .flag ()
111123 .store_into (psOptions->bOverwrite )
@@ -605,6 +617,10 @@ GDALDatasetH GDALTileIndexInternal(const char *pszDest,
605617 : nullptr ;
606618 const int nMaxFieldSize = pszVal ? atoi (pszVal) : 0 ;
607619
620+ const bool bFailOnErrors =
621+ psOptions->bInvokedFromGdalRasterIndex && !psOptions->bSkipErrors ;
622+ bool bSkipFirstTile = false ;
623+
608624 if (poLayer)
609625 {
610626 bExistingLayer = true ;
@@ -665,15 +681,30 @@ GDALDatasetH GDALTileIndexInternal(const char *pszDest,
665681 return nullptr ;
666682 }
667683 oGDALTileIndexTileIterator.reset ();
684+ std::unique_ptr<CPLTurnFailureIntoWarningBackuper>
685+ poFailureIntoWarning;
686+ if (!bFailOnErrors)
687+ poFailureIntoWarning =
688+ std::make_unique<CPLTurnFailureIntoWarningBackuper>();
689+ CPL_IGNORE_RET_VAL (poFailureIntoWarning);
668690 auto poSrcDS = std::unique_ptr<GDALDataset>(GDALDataset::Open (
669691 osFilename.c_str (), GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR,
670692 nullptr , nullptr , nullptr ));
671693 if (!poSrcDS)
672- return nullptr ;
673-
674- auto poSrcSRS = poSrcDS->GetSpatialRef ();
675- if (poSrcSRS)
676- oSRS = *poSrcSRS;
694+ {
695+ CPLError (bFailOnErrors ? CE_Failure : CE_Warning,
696+ CPLE_AppDefined, " Unable to open %s%s." ,
697+ osFilename.c_str (), bFailOnErrors ? " " : " , skipping" );
698+ if (bFailOnErrors)
699+ return nullptr ;
700+ bSkipFirstTile = true ;
701+ }
702+ else
703+ {
704+ auto poSrcSRS = poSrcDS->GetSpatialRef ();
705+ if (poSrcSRS)
706+ oSRS = *poSrcSRS;
707+ }
677708 }
678709
679710 poLayer = poTileIndexDS->CreateLayer (
@@ -964,6 +995,11 @@ GDALDatasetH GDALTileIndexInternal(const char *pszDest,
964995 const std::string osSrcFilename = oGDALTileIndexTileIterator.next ();
965996 if (osSrcFilename.empty ())
966997 break ;
998+ if (bSkipFirstTile)
999+ {
1000+ bSkipFirstTile = false ;
1001+ continue ;
1002+ }
9671003
9681004 std::string osFileNameToWrite;
9691005 VSIStatBuf sStatBuf ;
@@ -991,23 +1027,39 @@ GDALDatasetH GDALTileIndexInternal(const char *pszDest,
9911027 continue ;
9921028 }
9931029
994- auto poSrcDS = std::unique_ptr<GDALDataset>(GDALDataset::Open (
995- osSrcFilename.c_str (), GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR,
996- nullptr , nullptr , nullptr ));
997- if (poSrcDS == nullptr )
1030+ std::unique_ptr<GDALDataset> poSrcDS;
9981031 {
999- CPLError (CE_Warning, CPLE_AppDefined,
1000- " Unable to open %s, skipping." , osSrcFilename.c_str ());
1001- continue ;
1032+ std::unique_ptr<CPLTurnFailureIntoWarningBackuper>
1033+ poFailureIntoWarning;
1034+ if (!bFailOnErrors)
1035+ poFailureIntoWarning =
1036+ std::make_unique<CPLTurnFailureIntoWarningBackuper>();
1037+ CPL_IGNORE_RET_VAL (poFailureIntoWarning);
1038+
1039+ poSrcDS.reset (GDALDataset::Open (
1040+ osSrcFilename.c_str (), GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR,
1041+ nullptr , nullptr , nullptr ));
1042+ if (poSrcDS == nullptr )
1043+ {
1044+ CPLError (bFailOnErrors ? CE_Failure : CE_Warning,
1045+ CPLE_AppDefined, " Unable to open %s%s." ,
1046+ osSrcFilename.c_str (),
1047+ bFailOnErrors ? " " : " , skipping" );
1048+ if (bFailOnErrors)
1049+ return nullptr ;
1050+ continue ;
1051+ }
10021052 }
10031053
10041054 GDALGeoTransform gt;
10051055 if (poSrcDS->GetGeoTransform (gt) != CE_None)
10061056 {
1007- CPLError (CE_Warning, CPLE_AppDefined,
1057+ CPLError (bFailOnErrors ? CE_Failure : CE_Warning, CPLE_AppDefined,
10081058 " It appears no georeferencing is available for\n "
1009- " `%s', skipping." ,
1010- osSrcFilename.c_str ());
1059+ " `%s'%s." ,
1060+ osSrcFilename.c_str (), bFailOnErrors ? " " : " , skipping" );
1061+ if (bFailOnErrors)
1062+ return nullptr ;
10111063 continue ;
10121064 }
10131065
@@ -1049,9 +1101,11 @@ GDALDatasetH GDALTileIndexInternal(const char *pszDest,
10491101 const int nYSize = poSrcDS->GetRasterYSize ();
10501102 if (nXSize == 0 || nYSize == 0 )
10511103 {
1052- CPLError (CE_Warning, CPLE_AppDefined,
1053- " %s has 0 width or height. Skipping" ,
1054- osSrcFilename.c_str ());
1104+ CPLError (bFailOnErrors ? CE_Failure : CE_Warning, CPLE_AppDefined,
1105+ " %s has 0 width or height%s" , osSrcFilename.c_str (),
1106+ bFailOnErrors ? " " : " , skipping" );
1107+ if (bFailOnErrors)
1108+ return nullptr ;
10551109 continue ;
10561110 }
10571111
@@ -1081,13 +1135,16 @@ GDALDatasetH GDALTileIndexInternal(const char *pszDest,
10811135 OGRCreateCoordinateTransformation (poSrcSRS, &oTargetSRS));
10821136 if (!poCT || !poCT->Transform (5 , adfX, adfY, nullptr ))
10831137 {
1084- CPLError (CE_Warning, CPLE_AppDefined,
1138+ CPLError (bFailOnErrors ? CE_Failure : CE_Warning,
1139+ CPLE_AppDefined,
10851140 " unable to transform points from source "
1086- " SRS `%s' to target SRS `%s' for file `%s' - file "
1087- " skipped" ,
1141+ " SRS `%s' to target SRS `%s' for file `%s'%s" ,
10881142 poSrcDS->GetProjectionRef (),
10891143 psOptions->osTargetSRS .c_str (),
1090- osFileNameToWrite.c_str ());
1144+ osFileNameToWrite.c_str (),
1145+ bFailOnErrors ? " " : " , skipping" );
1146+ if (bFailOnErrors)
1147+ return nullptr ;
10911148 continue ;
10921149 }
10931150 }
0 commit comments