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