@@ -260,61 +260,19 @@ void validateArgs(Options &localOpts, const GDALArgumentParser &argParser)
260260
261261} // unnamed namespace
262262
263- struct ScopedDataset
264- {
265- ScopedDataset () : m_ds(nullptr )
266- {
267- }
268-
269- ScopedDataset (GDALDatasetH ds) : m_ds(ds)
270- {
271- }
272-
273- ~ScopedDataset ()
274- {
275- if (m_ds)
276- GDALClose (m_ds);
277- }
278-
279- ScopedDataset &operator =(GDALDatasetH ds)
280- {
281- if (m_ds)
282- GDALClose (m_ds);
283- m_ds = ds;
284- return *this ;
285- }
286-
287- operator GDALDatasetH () const
288- {
289- return m_ds;
290- }
291-
292- operator bool () const
293- {
294- return m_ds != nullptr ;
295- }
296-
297- bool operator !() const
298- {
299- return m_ds == nullptr ;
300- }
301-
302- GDALDatasetH m_ds;
303- };
304-
305263bool run (gdal::Options &localOpts, bool adjustCurveCoeff)
306264{
307265 viewshed::Options &opts = localOpts.opts ;
308266
309267 /* -------------------------------------------------------------------- */
310268 /* Open source raster file. */
311269 /* -------------------------------------------------------------------- */
312- ScopedDataset srcDs =
313- GDALOpen ( localOpts.osSrcFilename .c_str (), GA_ReadOnly );
270+ std::unique_ptr<GDALDataset> srcDs ( GDALDataset::Open (
271+ localOpts.osSrcFilename .c_str (), GDAL_OF_RASTER | GDAL_OF_READONLY) );
314272 if (!srcDs)
315273 exit (2 );
316274
317- GDALRasterBandH hBand = GDALGetRasterBand ( srcDs, localOpts.nBandIn );
275+ GDALRasterBand * hBand = srcDs-> GetRasterBand ( localOpts.nBandIn );
318276 if (hBand == nullptr )
319277 {
320278 CPLError (CE_Failure, CPLE_AppDefined,
@@ -325,16 +283,17 @@ bool run(gdal::Options &localOpts, bool adjustCurveCoeff)
325283 /* -------------------------------------------------------------------- */
326284 /* Open source SD raster file. */
327285 /* -------------------------------------------------------------------- */
328- ScopedDataset sdDs;
329- GDALRasterBandH hSdBand = nullptr ;
286+ std::unique_ptr<GDALDataset> sdDs;
287+ GDALRasterBand * hSdBand = nullptr ;
330288
331289 if (localOpts.osSdFilename .size ())
332290 {
333- sdDs = GDALOpen (localOpts.osSdFilename .c_str (), GA_ReadOnly);
291+ sdDs.reset (GDALDataset::Open (localOpts.osSdFilename .c_str (),
292+ GDAL_OF_RASTER | GDAL_OF_READONLY));
334293 if (!sdDs)
335294 exit (2 );
336295
337- hSdBand = GDALGetRasterBand ( sdDs, 1 );
296+ hSdBand = sdDs-> GetRasterBand ( 1 );
338297 if (hSdBand == nullptr )
339298 {
340299 CPLError (CE_Failure, CPLE_AppDefined,
@@ -344,7 +303,8 @@ bool run(gdal::Options &localOpts, bool adjustCurveCoeff)
344303 }
345304
346305 if (adjustCurveCoeff)
347- opts.curveCoeff = viewshed::adjustCurveCoeff (opts.curveCoeff , srcDs);
306+ opts.curveCoeff = viewshed::adjustCurveCoeff (
307+ opts.curveCoeff , GDALDataset::ToHandle (srcDs.get ()));
348308
349309 /* -------------------------------------------------------------------- */
350310 /* Invoke. */
@@ -369,9 +329,8 @@ bool run(gdal::Options &localOpts, bool adjustCurveCoeff)
369329 else
370330 bSuccess = oViewshed.run (
371331 hBand, localOpts.bQuiet ? GDALDummyProgress : GDALTermProgress);
372- ScopedDataset dstDs =
373- GDALDataset::FromHandle (oViewshed.output ().release ());
374- bSuccess = dstDs;
332+ std::unique_ptr<GDALDataset> dstDs = oViewshed.output ();
333+ bSuccess = (dstDs->Close () == CE_None);
375334 }
376335 return bSuccess;
377336}
0 commit comments