Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "raster tile" subcommand 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef GDALALG_RASTER_TILE_INCLUDED 14 : #define GDALALG_RASTER_TILE_INCLUDED 15 : 16 : #include "gdalrasterpipelinestepalgorithm.h" 17 : 18 : #include "cpl_string.h" 19 : 20 : #include <limits> 21 : 22 : //! @cond Doxygen_Suppress 23 : 24 : class GDALDataset; 25 : class GDALDriver; 26 : 27 : typedef struct _CPLSpawnedProcess CPLSpawnedProcess; 28 : 29 : /************************************************************************/ 30 : /* GDALRasterTileAlgorithm */ 31 : /************************************************************************/ 32 : 33 : class GDALRasterTileAlgorithm /* non final */ 34 : : public GDALRasterPipelineStepAlgorithm 35 : { 36 : public: 37 : static constexpr const char *NAME = "tile"; 38 : static constexpr const char *DESCRIPTION = 39 : "Generate tiles in separate files from a raster dataset."; 40 : static constexpr const char *HELP_URL = "/programs/gdal_raster_tile.html"; 41 : 42 : explicit GDALRasterTileAlgorithm(bool standaloneStep = false); 43 : ~GDALRasterTileAlgorithm() override; 44 : 45 19 : bool CanBeLastStep() const override 46 : { 47 19 : return true; 48 : } 49 : 50 6 : bool IsNativelyStreamingCompatible() const override 51 : { 52 6 : return false; 53 : } 54 : 55 6 : bool SupportsInputMultiThreading() const override 56 : { 57 6 : return true; 58 : } 59 : 60 9 : int GetOutputType() const override 61 : { 62 9 : return 0; 63 : } 64 : 65 : private: 66 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterTileAlgorithm) 67 : 68 : std::string m_outputDir{}; 69 : std::vector<std::string> m_metadata{}; 70 : bool m_copySrcMetadata = false; 71 : std::string m_tilingScheme{}; 72 : std::string m_convention = "xyz"; 73 : std::string m_resampling{}; 74 : std::string m_overviewResampling{}; 75 : int m_minZoomLevel = -1; 76 : int m_maxZoomLevel = -1; 77 : bool m_minZoomLevelSingleTile = false; 78 : bool m_noIntersectionIsOK = false; 79 : int m_minTileX = -1; 80 : int m_minTileY = -1; 81 : int m_maxTileX = -1; 82 : int m_maxTileY = -1; 83 : int m_ovrZoomLevel = -1; // Used in spawn mode 84 : int m_minOvrTileX = -1; // Used in spawn mode 85 : int m_minOvrTileY = -1; // Used in spawn mode 86 : int m_maxOvrTileX = -1; // Used in spawn mode 87 : int m_maxOvrTileY = -1; // Used in spawn mode 88 : int m_tileSize = 0; 89 : bool m_addalpha = false; 90 : bool m_noalpha = false; 91 : double m_dstNoData = 0; 92 : bool m_skipBlank = false; 93 : bool m_auxXML = false; 94 : bool m_resume = false; 95 : bool m_kml = false; 96 : bool m_spawned = false; 97 : bool m_forked = false; 98 : bool m_dummy = false; 99 : int m_numThreads = 0; 100 : std::string m_parallelMethod{}; 101 : 102 : std::string m_excludedValues{}; 103 : double m_excludedValuesPctThreshold = 50; 104 : double m_nodataValuesPctThreshold = 100; 105 : 106 : std::vector<std::string> m_webviewers{}; 107 : std::string m_url{}; 108 : std::string m_title{}; 109 : std::string m_copyright{}; 110 : std::string m_mapmlTemplate{}; 111 : 112 : // Work variables 113 : std::string m_numThreadsStr{"ALL_CPUS"}; 114 : std::map<std::string, std::string> m_mapTileMatrixIdentifierToScheme{}; 115 : GDALDataset *m_poSrcDS = nullptr; 116 : GDALDataset *m_poSrcOvrDS = nullptr; 117 : bool m_bIsNamedNonMemSrcDS = false; 118 : GDALDriver *m_poDstDriver = nullptr; 119 : std::string m_osGDALPath{}; 120 : 121 : // Private methods 122 : bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override; 123 : bool RunStep(GDALPipelineStepRunContext &ctxt) override; 124 : 125 : bool ValidateOutputFormat(GDALDataType eSrcDT) const; 126 : 127 : static void ComputeJobChunkSize(int nMaxJobCount, int nTilesPerCol, 128 : int nTilesPerRow, double &dfTilesYPerJob, 129 : int &nYOuterIterations, 130 : double &dfTilesXPerJob, 131 : int &nXOuterIterations); 132 : 133 : bool AddArgToArgv(const GDALAlgorithmArg *arg, 134 : CPLStringList &aosArgv) const; 135 : 136 : bool IsCompatibleOfSpawn(const char *&pszErrorMsg); 137 : 138 : int GetMaxChildCount(int nMaxJobCount) const; 139 : 140 : void WaitForSpawnedProcesses( 141 : bool &bRet, const std::vector<std::string> &asCommandLines, 142 : std::vector<CPLSpawnedProcess *> &ahSpawnedProcesses) const; 143 : bool GenerateBaseTilesSpawnMethod( 144 : int nBaseTilesPerCol, int nBaseTilesPerRow, int nMinTileX, 145 : int nMinTileY, int nMaxTileX, int nMaxTileY, uint64_t nTotalTiles, 146 : uint64_t nBaseTiles, GDALProgressFunc pfnProgress, void *pProgressData); 147 : 148 : bool GenerateOverviewTilesSpawnMethod( 149 : int iZ, int nOvrMinTileX, int nOvrMinTileY, int nOvrMaxTileX, 150 : int nOvrMaxTileY, std::atomic<uint64_t> &nCurTile, uint64_t nTotalTiles, 151 : GDALProgressFunc pfnProgress, void *pProgressData); 152 : }; 153 : 154 : /************************************************************************/ 155 : /* GDALRasterTileAlgorithmStandalone */ 156 : /************************************************************************/ 157 : 158 512 : class GDALRasterTileAlgorithmStandalone final : public GDALRasterTileAlgorithm 159 : { 160 : public: 161 256 : GDALRasterTileAlgorithmStandalone() 162 256 : : GDALRasterTileAlgorithm(/* standaloneStep = */ true) 163 : { 164 256 : } 165 : 166 : ~GDALRasterTileAlgorithmStandalone() override; 167 : }; 168 : 169 : //! @endcond 170 : 171 : #endif