GDAL
gdalalg_raster_tile.h
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
23
24class GDALDataset;
25class GDALDriver;
26
27typedef struct _CPLSpawnedProcess CPLSpawnedProcess;
28
29/************************************************************************/
30/* GDALRasterTileAlgorithm */
31/************************************************************************/
32
33class 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 bool CanBeLastStep() const override
46 {
47 return true;
48 }
49
50 bool IsNativelyStreamingCompatible() const override
51 {
52 return false;
53 }
54
55 bool SupportsInputMultiThreading() const override
56 {
57 return true;
58 }
59
60 int GetOutputType() const override
61 {
62 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_noIntersectionIsOK = false;
78 int m_minTileX = -1;
79 int m_minTileY = -1;
80 int m_maxTileX = -1;
81 int m_maxTileY = -1;
82 int m_ovrZoomLevel = -1; // Used in spawn mode
83 int m_minOvrTileX = -1; // Used in spawn mode
84 int m_minOvrTileY = -1; // Used in spawn mode
85 int m_maxOvrTileX = -1; // Used in spawn mode
86 int m_maxOvrTileY = -1; // Used in spawn mode
87 int m_tileSize = 0;
88 bool m_addalpha = false;
89 bool m_noalpha = false;
90 double m_dstNoData = 0;
91 bool m_skipBlank = false;
92 bool m_auxXML = false;
93 bool m_resume = false;
94 bool m_kml = false;
95 bool m_spawned = false;
96 bool m_forked = false;
97 bool m_dummy = false;
98 int m_numThreads = 0;
99 std::string m_parallelMethod{};
100
101 std::string m_excludedValues{};
102 double m_excludedValuesPctThreshold = 50;
103 double m_nodataValuesPctThreshold = 100;
104
105 std::vector<std::string> m_webviewers{};
106 std::string m_url{};
107 std::string m_title{};
108 std::string m_copyright{};
109 std::string m_mapmlTemplate{};
110
111 // Work variables
112 std::string m_numThreadsStr{"ALL_CPUS"};
113 std::map<std::string, std::string> m_mapTileMatrixIdentifierToScheme{};
114 GDALDataset *m_poSrcDS = nullptr;
115 GDALDataset *m_poSrcOvrDS = nullptr;
116 bool m_bIsNamedNonMemSrcDS = false;
117 GDALDriver *m_poDstDriver = nullptr;
118 std::string m_osGDALPath{};
119
120 // Private methods
121 bool RunImpl(GDALProgressFunc pfnProgress, void *pProgressData) override;
122 bool RunStep(GDALPipelineStepRunContext &ctxt) override;
123
124 bool ValidateOutputFormat(GDALDataType eSrcDT) const;
125
126 static void ComputeJobChunkSize(int nMaxJobCount, int nTilesPerCol,
127 int nTilesPerRow, double &dfTilesYPerJob,
128 int &nYOuterIterations,
129 double &dfTilesXPerJob,
130 int &nXOuterIterations);
131
132 bool AddArgToArgv(const GDALAlgorithmArg *arg,
133 CPLStringList &aosArgv) const;
134
135 bool IsCompatibleOfSpawn(const char *&pszErrorMsg);
136
137 int GetMaxChildCount(int nMaxJobCount) const;
138
139 void WaitForSpawnedProcesses(
140 bool &bRet, const std::vector<std::string> &asCommandLines,
141 std::vector<CPLSpawnedProcess *> &ahSpawnedProcesses) const;
142 bool GenerateBaseTilesSpawnMethod(
143 int nBaseTilesPerCol, int nBaseTilesPerRow, int nMinTileX,
144 int nMinTileY, int nMaxTileX, int nMaxTileY, uint64_t nTotalTiles,
145 uint64_t nBaseTiles, GDALProgressFunc pfnProgress, void *pProgressData);
146
147 bool GenerateOverviewTilesSpawnMethod(
148 int iZ, int nOvrMinTileX, int nOvrMinTileY, int nOvrMaxTileX,
149 int nOvrMaxTileY, std::atomic<uint64_t> &nCurTile, uint64_t nTotalTiles,
150 GDALProgressFunc pfnProgress, void *pProgressData);
151};
152
153/************************************************************************/
154/* GDALRasterTileAlgorithmStandalone */
155/************************************************************************/
156
157class GDALRasterTileAlgorithmStandalone final : public GDALRasterTileAlgorithm
158{
159 public:
160 GDALRasterTileAlgorithmStandalone()
161 : GDALRasterTileAlgorithm(/* standaloneStep = */ true)
162 {
163 }
164
165 ~GDALRasterTileAlgorithmStandalone() override;
166};
167
169
170#endif
String list class designed around our use of C "char**" string lists.
Definition cpl_string.h:476
Argument of an algorithm.
Definition gdalalgorithm_cpp.h:1270
A set of associated raster bands, usually from one file.
Definition gdal_dataset.h:77
Format specific driver.
Definition gdal_driver.h:63
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:1101
Various convenience functions for working with strings and string lists.
GDALDataType
Definition gdal.h:48