LCOV - code coverage report
Current view: top level - apps - gdal_grid_bin.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 25 34 73.5 %
Date: 2024-05-03 15:49:35 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL Utilities
       4             :  * Purpose:  GDAL scattered data gridding (interpolation) tool
       5             :  * Authors:  Even Rouault, <even dot rouault at spatialys dot com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2015, Even Rouault <even dot rouault at spatialys dot com>
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "cpl_string.h"
      30             : #include "gdal_version.h"
      31             : #include "commonutils.h"
      32             : #include "gdal_utils_priv.h"
      33             : 
      34             : /************************************************************************/
      35             : /*                               Usage()                                */
      36             : /************************************************************************/
      37             : 
      38           0 : static void Usage()
      39             : 
      40             : {
      41           0 :     fprintf(stderr, "%s\n", GDALGridGetParserUsage().c_str());
      42           0 :     exit(1);
      43             : }
      44             : 
      45             : /************************************************************************/
      46             : /*                                main()                                */
      47             : /************************************************************************/
      48             : 
      49          55 : MAIN_START(argc, argv)
      50             : {
      51             :     /* Check strict compilation and runtime library version as we use C++ API */
      52          55 :     if (!GDAL_CHECK_VERSION(argv[0]))
      53           0 :         exit(1);
      54             : 
      55          55 :     EarlySetConfigOptions(argc, argv);
      56             : 
      57             :     /* -------------------------------------------------------------------- */
      58             :     /*      Generic arg processing.                                         */
      59             :     /* -------------------------------------------------------------------- */
      60          55 :     GDALAllRegister();
      61          55 :     argc = GDALGeneralCmdLineProcessor(argc, &argv, 0);
      62          55 :     if (argc < 1)
      63           0 :         exit(-argc);
      64             : 
      65          55 :     GDALGridOptionsForBinary sOptionsForBinary;
      66             :     /* coverity[tainted_data] */
      67             :     GDALGridOptions *psOptions =
      68          55 :         GDALGridOptionsNew(argv + 1, &sOptionsForBinary);
      69          54 :     CSLDestroy(argv);
      70             : 
      71          54 :     if (psOptions == nullptr)
      72             :     {
      73           0 :         Usage();
      74             :     }
      75             : 
      76          54 :     if (!(sOptionsForBinary.bQuiet))
      77             :     {
      78          54 :         GDALGridOptionsSetProgress(psOptions, GDALTermProgress, nullptr);
      79             :     }
      80             : 
      81             :     /* -------------------------------------------------------------------- */
      82             :     /*      Open input file.                                                */
      83             :     /* -------------------------------------------------------------------- */
      84          54 :     GDALDatasetH hInDS = GDALOpenEx(sOptionsForBinary.osSource.c_str(),
      85             :                                     GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR,
      86             :                                     /*papszAllowedDrivers=*/nullptr,
      87          54 :                                     sOptionsForBinary.aosOpenOptions.List(),
      88             :                                     /*papszSiblingFiles=*/nullptr);
      89          54 :     if (hInDS == nullptr)
      90           0 :         exit(1);
      91             : 
      92          54 :     int bUsageError = FALSE;
      93          54 :     GDALDatasetH hOutDS = GDALGrid(sOptionsForBinary.osDest.c_str(), hInDS,
      94             :                                    psOptions, &bUsageError);
      95          54 :     if (bUsageError == TRUE)
      96           0 :         Usage();
      97          54 :     int nRetCode = hOutDS ? 0 : 1;
      98             : 
      99          54 :     GDALClose(hInDS);
     100          54 :     GDALClose(hOutDS);
     101          54 :     GDALGridOptionsFree(psOptions);
     102             : 
     103          54 :     OGRCleanupAll();
     104          54 :     GDALDestroyDriverManager();
     105             : 
     106          54 :     return nRetCode;
     107             : }
     108             : 
     109           0 : MAIN_END

Generated by: LCOV version 1.14