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 "gdalalg_raster_pipeline.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 : 44 15 : bool CanBeLastStep() const override 45 : { 46 15 : return true; 47 : } 48 : 49 2 : bool IsNativelyStreamingCompatible() const override 50 : { 51 2 : return false; 52 : } 53 : 54 3 : bool SupportsInputMultiThreading() const override 55 : { 56 3 : return true; 57 : } 58 : 59 : private: 60 : CPL_DISALLOW_COPY_ASSIGN(GDALRasterTileAlgorithm) 61 : 62 : std::vector<std::string> m_metadata{}; 63 : bool m_copySrcMetadata = false; 64 : std::string m_tilingScheme{}; 65 : std::string m_convention = "xyz"; 66 : std::string m_resampling{}; 67 : std::string m_overviewResampling{}; 68 : int m_minZoomLevel = -1; 69 : int m_maxZoomLevel = -1; 70 : bool m_minZoomLevelSingleTile = false; 71 : bool m_noIntersectionIsOK = false; 72 : int m_minTileX = -1; 73 : int m_minTileY = -1; 74 : int m_maxTileX = -1; 75 : int m_maxTileY = -1; 76 : int m_ovrZoomLevel = -1; // Used in spawn mode 77 : int m_minOvrTileX = -1; // Used in spawn mode 78 : int m_minOvrTileY = -1; // Used in spawn mode 79 : int m_maxOvrTileX = -1; // Used in spawn mode 80 : int m_maxOvrTileY = -1; // Used in spawn mode 81 : int m_tileSize = 0; 82 : bool m_addalpha = false; 83 : bool m_noalpha = false; 84 : double m_dstNoData = 0; 85 : bool m_skipBlank = false; 86 : bool m_auxXML = false; 87 : bool m_resume = false; 88 : bool m_kml = false; 89 : bool m_spawned = false; 90 : bool m_forked = false; 91 : bool m_dummy = false; 92 : int m_numThreads = 0; 93 : std::string m_parallelMethod{}; 94 : 95 : std::string m_excludedValues{}; 96 : double m_excludedValuesPctThreshold = 50; 97 : double m_nodataValuesPctThreshold = 100; 98 : 99 : std::vector<std::string> m_webviewers{}; 100 : std::string m_url{}; 101 : std::string m_title{}; 102 : std::string m_copyright{}; 103 : std::string m_mapmlTemplate{}; 104 : 105 : // Work variables 106 : std::string m_numThreadsStr{"ALL_CPUS"}; 107 : std::map<std::string, std::string> m_mapTileMatrixIdentifierToScheme{}; 108 : GDALDataset *m_poSrcDS = nullptr; 109 : bool m_bIsNamedNonMemSrcDS = false; 110 : GDALDriver *m_poDstDriver = nullptr; 111 : std::string m_osGDALPath{}; 112 : 113 : // Private methods 114 : bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override; 115 : bool RunStep(GDALPipelineStepRunContext &ctxt) override; 116 : 117 : bool ValidateOutputFormat(GDALDataType eSrcDT) const; 118 : 119 : static void ComputeJobChunkSize(int nMaxJobCount, int nTilesPerCol, 120 : int nTilesPerRow, double &dfTilesYPerJob, 121 : int &nYOuterIterations, 122 : double &dfTilesXPerJob, 123 : int &nXOuterIterations); 124 : 125 : bool AddArgToArgv(const GDALAlgorithmArg *arg, 126 : CPLStringList &aosArgv) const; 127 : 128 : bool IsCompatibleOfSpawn(const char *&pszErrorMsg); 129 : 130 : int GetMaxChildCount(int nMaxJobCount) const; 131 : 132 : void WaitForSpawnedProcesses( 133 : bool &bRet, const std::vector<std::string> &asCommandLines, 134 : std::vector<CPLSpawnedProcess *> &ahSpawnedProcesses) const; 135 : bool GenerateBaseTilesSpawnMethod( 136 : int nBaseTilesPerCol, int nBaseTilesPerRow, int nMinTileX, 137 : int nMinTileY, int nMaxTileX, int nMaxTileY, uint64_t nTotalTiles, 138 : uint64_t nBaseTiles, GDALProgressFunc pfnProgress, void *pProgressData); 139 : 140 : bool GenerateOverviewTilesSpawnMethod( 141 : int iZ, int nOvrMinTileX, int nOvrMinTileY, int nOvrMaxTileX, 142 : int nOvrMaxTileY, std::atomic<uint64_t> &nCurTile, uint64_t nTotalTiles, 143 : GDALProgressFunc pfnProgress, void *pProgressData); 144 : }; 145 : 146 : /************************************************************************/ 147 : /* GDALRasterTileAlgorithmStandalone */ 148 : /************************************************************************/ 149 : 150 510 : class GDALRasterTileAlgorithmStandalone final : public GDALRasterTileAlgorithm 151 : { 152 : public: 153 255 : GDALRasterTileAlgorithmStandalone() 154 255 : : GDALRasterTileAlgorithm(/* standaloneStep = */ true) 155 : { 156 255 : } 157 : 158 : ~GDALRasterTileAlgorithmStandalone() override; 159 : }; 160 : 161 : //! @endcond 162 : 163 : #endif