@@ -794,6 +794,8 @@ GDALDatasetH GDALGrid(const char *pszDest, GDALDatasetH hSrcDataset,
794794 bool bIsYExtentSet = psOptions->bIsYExtentSet ;
795795 CPLErr eErr = CE_None;
796796
797+ const bool bCloseReportsProgress = poDstDS->GetCloseReportsProgress ();
798+
797799 /* -------------------------------------------------------------------- */
798800 /* Process SQL request. */
799801 /* -------------------------------------------------------------------- */
@@ -808,14 +810,21 @@ GDALDatasetH GDALGrid(const char *pszDest, GDALDatasetH hSrcDataset,
808810 return nullptr ;
809811 }
810812
813+ std::unique_ptr<void , decltype (&GDALDestroyScaledProgress)>
814+ pScaledProgressArg (
815+ GDALCreateScaledProgress (0.0 , bCloseReportsProgress ? 0.5 : 1.0 ,
816+ psOptions->pfnProgress ,
817+ psOptions->pProgressData ),
818+ GDALDestroyScaledProgress);
819+
811820 // Custom layer will be rasterized in the first band.
812821 eErr = ProcessLayer (
813822 poLayer, poDstDS.get (), psOptions->poSpatialFilter .get (), nXSize,
814823 nYSize, 1 , bIsXExtentSet, bIsYExtentSet, dfXMin, dfXMax, dfYMin,
815824 dfYMax, psOptions->osBurnAttribute , psOptions->dfIncreaseBurnValue ,
816825 psOptions->dfMultiplyBurnValue , psOptions->eOutputType ,
817826 psOptions->eAlgorithm , psOptions->pOptions .get (), psOptions->bQuiet ,
818- psOptions-> pfnProgress , psOptions-> pProgressData );
827+ GDALScaledProgress, pScaledProgressArg. get () );
819828
820829 poSrcDS->ReleaseResultSet (poLayer);
821830 }
@@ -861,14 +870,21 @@ GDALDatasetH GDALGrid(const char *pszDest, GDALDatasetH hSrcDataset,
861870 osOutputSRS = poSRS->exportToWkt ();
862871 }
863872
873+ std::unique_ptr<void , decltype (&GDALDestroyScaledProgress)>
874+ pScaledProgressArg (
875+ GDALCreateScaledProgress (0.0 , bCloseReportsProgress ? 0.5 : 1.0 ,
876+ psOptions->pfnProgress ,
877+ psOptions->pProgressData ),
878+ GDALDestroyScaledProgress);
879+
864880 eErr = ProcessLayer (
865881 poLayer, poDstDS.get (), psOptions->poSpatialFilter .get (), nXSize,
866882 nYSize, i + 1 + nBands - nLayerCount, bIsXExtentSet, bIsYExtentSet,
867883 dfXMin, dfXMax, dfYMin, dfYMax, psOptions->osBurnAttribute ,
868884 psOptions->dfIncreaseBurnValue , psOptions->dfMultiplyBurnValue ,
869885 psOptions->eOutputType , psOptions->eAlgorithm ,
870- psOptions->pOptions .get (), psOptions->bQuiet ,
871- psOptions-> pfnProgress , psOptions-> pProgressData );
886+ psOptions->pOptions .get (), psOptions->bQuiet , GDALScaledProgress,
887+ pScaledProgressArg. get () );
872888 if (eErr != CE_None)
873889 break ;
874890 }
@@ -897,6 +913,46 @@ GDALDatasetH GDALGrid(const char *pszDest, GDALDatasetH hSrcDataset,
897913 return nullptr ;
898914 }
899915
916+ if (bCloseReportsProgress)
917+ {
918+ std::unique_ptr<void , decltype (&GDALDestroyScaledProgress)>
919+ pScaledProgressArg (
920+ GDALCreateScaledProgress (0.5 , 1.0 , psOptions->pfnProgress ,
921+ psOptions->pProgressData ),
922+ GDALDestroyScaledProgress);
923+
924+ const bool bCanReopenWithCurrentDescription =
925+ poDstDS->CanReopenWithCurrentDescription ();
926+
927+ eErr = poDstDS->Close (GDALScaledProgress, pScaledProgressArg.get ());
928+ poDstDS.reset ();
929+ if (eErr != CE_None)
930+ return nullptr ;
931+
932+ if (bCanReopenWithCurrentDescription)
933+ {
934+ {
935+ CPLErrorStateBackuper oBackuper (CPLQuietErrorHandler);
936+ poDstDS.reset (GDALDataset::Open (pszDest,
937+ GDAL_OF_RASTER | GDAL_OF_UPDATE,
938+ nullptr , nullptr , nullptr ));
939+ }
940+ if (!poDstDS)
941+ poDstDS.reset (GDALDataset::Open (
942+ pszDest, GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR, nullptr ,
943+ nullptr , nullptr ));
944+ }
945+ else
946+ {
947+ struct DummyDataset final : public GDALDataset
948+ {
949+ DummyDataset () = default ;
950+ };
951+
952+ poDstDS = std::make_unique<DummyDataset>();
953+ }
954+ }
955+
900956 return GDALDataset::ToHandle (poDstDS.release ());
901957}
902958
0 commit comments