LCOV - code coverage report
Current view: top level - apps - gdaltindex_bin.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 23 30 76.7 %
Date: 2025-05-15 13:16:46 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  MapServer
       4             :  * Purpose:  Commandline App to build tile index for raster files.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2001, Frank Warmerdam, DM Solutions Group Inc
       9             :  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "cpl_string.h"
      15             : #include "cpl_error.h"
      16             : #include "commonutils.h"
      17             : #include "gdal_version.h"
      18             : #include "gdal_utils_priv.h"
      19             : #include "gdal_priv.h"
      20             : 
      21             : /************************************************************************/
      22             : /*                               Usage()                                */
      23             : /************************************************************************/
      24             : 
      25           0 : static void Usage()
      26             : 
      27             : {
      28           0 :     fprintf(stderr, "%s\n", GDALTileIndexAppGetParserUsage().c_str());
      29           0 :     exit(1);
      30             : }
      31             : 
      32             : /************************************************************************/
      33             : /*                                main()                                */
      34             : /************************************************************************/
      35             : 
      36           7 : MAIN_START(argc, argv)
      37             : {
      38             : 
      39           7 :     EarlySetConfigOptions(argc, argv);
      40             : 
      41             :     /* -------------------------------------------------------------------- */
      42             :     /*      Register standard GDAL drivers, and process generic GDAL        */
      43             :     /*      command options.                                                */
      44             :     /* -------------------------------------------------------------------- */
      45           7 :     GDALAllRegister();
      46           7 :     argc = GDALGeneralCmdLineProcessor(argc, &argv, 0);
      47           7 :     if (argc < 1)
      48           1 :         exit(-argc);
      49             : 
      50          12 :     GDALTileIndexOptionsForBinary sOptionsForBinary;
      51             :     std::unique_ptr<GDALTileIndexOptions, decltype(&GDALTileIndexOptionsFree)>
      52             :         psOptions{GDALTileIndexOptionsNew(argv + 1, &sOptionsForBinary),
      53           6 :                   GDALTileIndexOptionsFree};
      54           6 :     CSLDestroy(argv);
      55             : 
      56           6 :     if (!psOptions)
      57             :     {
      58           0 :         Usage();
      59             :     }
      60             : 
      61           6 :     if (!(sOptionsForBinary.bQuiet))
      62             :     {
      63           6 :         GDALTileIndexOptionsSetProgress(psOptions.get(), GDALTermProgress,
      64             :                                         nullptr);
      65             :     }
      66             : 
      67           6 :     int bUsageError = FALSE;
      68           6 :     GDALDatasetH hOutDS = GDALTileIndex(
      69             :         sOptionsForBinary.osDest.c_str(), sOptionsForBinary.aosSrcFiles.size(),
      70           6 :         sOptionsForBinary.aosSrcFiles.List(), psOptions.get(), &bUsageError);
      71             : 
      72           6 :     int nRetCode = (hOutDS) ? 0 : 1;
      73             : 
      74           6 :     CPLErrorReset();
      75             :     // The flush to disk is only done at that stage, so check if any error has
      76             :     // happened
      77           6 :     if (GDALClose(hOutDS) != CE_None)
      78           0 :         nRetCode = 1;
      79           6 :     if (CPLGetLastErrorType() != CE_None)
      80           0 :         nRetCode = 1;
      81             : 
      82           6 :     GDALDumpOpenDatasets(stderr);
      83             : 
      84           6 :     GDALDestroyDriverManager();
      85             : 
      86           6 :     OGRCleanupAll();
      87             : 
      88           6 :     return nRetCode;
      89             : }
      90             : 
      91           0 : MAIN_END

Generated by: LCOV version 1.14