Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Contour Generator 4 : * Purpose: Contour Generator mainline. 5 : * Author: Frank Warmerdam <warmerdam@pobox.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2003, Applied Coherent Technology (www.actgate.com). 9 : * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com> 10 : * Copyright (c) 2018, Oslandia <infos at oslandia dot com> 11 : * 12 : * SPDX-License-Identifier: MIT 13 : ****************************************************************************/ 14 : 15 : #include "cpl_conv.h" 16 : #include "cpl_string.h" 17 : #include "gdal_version.h" 18 : #include "gdal.h" 19 : #include "gdal_alg.h" 20 : #include "gdalargumentparser.h" 21 : #include "ogr_api.h" 22 : #include "ogr_srs_api.h" 23 : #include "commonutils.h" 24 : #include "gdal_utils.h" 25 : #include "gdal_utils_priv.h" 26 : 27 : /************************************************************************/ 28 : /* Usage() */ 29 : /************************************************************************/ 30 : 31 1 : static void Usage() 32 : 33 : { 34 1 : fprintf(stderr, "%s\n", GDALContourGetParserUsage().c_str()); 35 1 : exit(1); 36 : } 37 : 38 : /************************************************************************/ 39 : /* main() */ 40 : /************************************************************************/ 41 : 42 21 : MAIN_START(argc, argv) 43 : { 44 : 45 : /* Check strict compilation and runtime library version as we use C++ API */ 46 21 : if (!GDAL_CHECK_VERSION(argv[0])) 47 0 : exit(1); 48 : 49 21 : EarlySetConfigOptions(argc, argv); 50 : 51 : /* -------------------------------------------------------------------- */ 52 : /* Register standard GDAL drivers, and process generic GDAL */ 53 : /* command options. */ 54 : /* -------------------------------------------------------------------- */ 55 21 : GDALAllRegister(); 56 21 : argc = GDALGeneralCmdLineProcessor(argc, &argv, 0); 57 21 : if (argc < 1) 58 1 : exit(-argc); 59 : 60 : /* -------------------------------------------------------------------- */ 61 : /* Generic arg processing. */ 62 : /* -------------------------------------------------------------------- */ 63 : 64 39 : GDALContourOptionsForBinary sOptionsForBinary; 65 : std::unique_ptr<GDALContourOptions, decltype(&GDALContourOptionsFree)> 66 : psOptions{GDALContourOptionsNew(argv + 1, &sOptionsForBinary), 67 20 : GDALContourOptionsFree}; 68 : 69 20 : CSLDestroy(argv); 70 : 71 20 : if (!psOptions) 72 : { 73 1 : Usage(); 74 : } 75 : 76 19 : GDALProgressFunc pfnProgress = nullptr; 77 : 78 19 : if (!sOptionsForBinary.bQuiet) 79 19 : pfnProgress = GDALTermProgress; 80 : 81 19 : char **papszStringOptions = nullptr; 82 : 83 19 : GDALDatasetH hSrcDS{nullptr}; 84 19 : GDALRasterBandH hBand{nullptr}; 85 19 : GDALDatasetH hDstDS{nullptr}; 86 19 : OGRLayerH hLayer{nullptr}; 87 : CPLErr eErr = 88 19 : GDALContourProcessOptions(psOptions.get(), &papszStringOptions, &hSrcDS, 89 : &hBand, &hDstDS, &hLayer); 90 : 91 19 : if (eErr == CE_None) 92 : { 93 19 : eErr = GDALContourGenerateEx(hBand, hLayer, papszStringOptions, 94 : pfnProgress, nullptr); 95 : } 96 : 97 19 : if (GDALClose(hSrcDS) != CE_None) 98 0 : eErr = CE_Failure; 99 : 100 19 : GDALClose(hDstDS); 101 : 102 19 : CSLDestroy(papszStringOptions); 103 19 : GDALDestroyDriverManager(); 104 19 : OGRCleanupAll(); 105 : 106 19 : return (eErr == CE_None) ? 0 : 1; 107 : } 108 : 109 0 : MAIN_END