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 : * Permission is hereby granted, free of charge, to any person obtaining a 12 : * copy of this software and associated documentation files (the "Software"), 13 : * to deal in the Software without restriction, including without limitation 14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 : * and/or sell copies of the Software, and to permit persons to whom the 16 : * Software is furnished to do so, subject to the following conditions: 17 : * 18 : * The above copyright notice and this permission notice shall be included 19 : * in all copies or substantial portions of the Software. 20 : * 21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 : * DEALINGS IN THE SOFTWARE. 28 : ****************************************************************************/ 29 : 30 : #include "cpl_string.h" 31 : #include "cpl_error.h" 32 : #include "commonutils.h" 33 : #include "gdal_version.h" 34 : #include "gdal_utils_priv.h" 35 : #include "gdal_priv.h" 36 : 37 : /************************************************************************/ 38 : /* Usage() */ 39 : /************************************************************************/ 40 : 41 0 : static void Usage() 42 : 43 : { 44 0 : fprintf(stderr, "%s\n", GDALTileIndexAppGetParserUsage().c_str()); 45 0 : exit(1); 46 : } 47 : 48 : /************************************************************************/ 49 : /* main() */ 50 : /************************************************************************/ 51 : 52 7 : MAIN_START(argc, argv) 53 : { 54 : 55 7 : EarlySetConfigOptions(argc, argv); 56 : 57 : /* -------------------------------------------------------------------- */ 58 : /* Register standard GDAL drivers, and process generic GDAL */ 59 : /* command options. */ 60 : /* -------------------------------------------------------------------- */ 61 7 : GDALAllRegister(); 62 7 : argc = GDALGeneralCmdLineProcessor(argc, &argv, 0); 63 7 : if (argc < 1) 64 0 : exit(-argc); 65 : 66 13 : GDALTileIndexOptionsForBinary sOptionsForBinary; 67 : std::unique_ptr<GDALTileIndexOptions, decltype(&GDALTileIndexOptionsFree)> 68 : psOptions{GDALTileIndexOptionsNew(argv + 1, &sOptionsForBinary), 69 7 : GDALTileIndexOptionsFree}; 70 6 : CSLDestroy(argv); 71 : 72 6 : if (!psOptions) 73 : { 74 0 : Usage(); 75 : } 76 : 77 6 : int bUsageError = FALSE; 78 6 : GDALDatasetH hOutDS = GDALTileIndex( 79 : sOptionsForBinary.osDest.c_str(), sOptionsForBinary.aosSrcFiles.size(), 80 6 : sOptionsForBinary.aosSrcFiles.List(), psOptions.get(), &bUsageError); 81 : 82 6 : int nRetCode = (hOutDS) ? 0 : 1; 83 : 84 6 : CPLErrorReset(); 85 : // The flush to disk is only done at that stage, so check if any error has 86 : // happened 87 6 : if (GDALClose(hOutDS) != CE_None) 88 0 : nRetCode = 1; 89 6 : if (CPLGetLastErrorType() != CE_None) 90 0 : nRetCode = 1; 91 : 92 6 : GDALDumpOpenDatasets(stderr); 93 : 94 6 : GDALDestroyDriverManager(); 95 : 96 6 : OGRCleanupAll(); 97 : 98 6 : return nRetCode; 99 : } 100 : 101 0 : MAIN_END