/src/gdal/frmts/stacta/stactadataset.h
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /******************************************************************************  | 
2  |  |  *  | 
3  |  |  * Project:  GDAL  | 
4  |  |  * Purpose:  STACTA (Spatio-Temporal Asset Catalog Tiled Assets) driver  | 
5  |  |  * Author:   Even Rouault, <even dot rouault at spatialys.com>  | 
6  |  |  *  | 
7  |  |  ******************************************************************************  | 
8  |  |  * Copyright (c) 2020, Even Rouault <even dot rouault at spatialys.com>  | 
9  |  |  *  | 
10  |  |  * SPDX-License-Identifier: MIT  | 
11  |  |  ****************************************************************************/  | 
12  |  |  | 
13  |  | #ifndef STACTADATASET_H  | 
14  |  | #define STACTADATASET_H  | 
15  |  |  | 
16  |  | #include "cpl_mem_cache.h"  | 
17  |  | #include "cpl_string.h"  | 
18  |  | #include "gdal_pam.h"  | 
19  |  | #include "memdataset.h"  | 
20  |  | #include "tilematrixset.hpp"  | 
21  |  |  | 
22  |  | #include <array>  | 
23  |  | #include <map>  | 
24  |  | #include <memory>  | 
25  |  | #include <vector>  | 
26  |  |  | 
27  |  | namespace  | 
28  |  | { | 
29  |  | struct Limits  | 
30  |  | { | 
31  |  |     int min_tile_col = 0;  | 
32  |  |     int max_tile_col = 0;  | 
33  |  |     int min_tile_row = 0;  | 
34  |  |     int max_tile_row = 0;  | 
35  |  | };  | 
36  |  | }  // namespace  | 
37  |  | /************************************************************************/  | 
38  |  | /* ==================================================================== */  | 
39  |  | /*                          STACTADataset                               */  | 
40  |  | /* ==================================================================== */  | 
41  |  | /************************************************************************/  | 
42  |  |  | 
43  |  | class STACTARawDataset;  | 
44  |  |  | 
45  |  | class STACTADataset final : public GDALPamDataset  | 
46  |  | { | 
47  |  |     friend class STACTARasterBand;  | 
48  |  |     friend class STACTARawDataset;  | 
49  |  |     friend class STACTARawRasterBand;  | 
50  |  |  | 
51  |  |     std::array<double, 6> m_adfGeoTransform = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}}; | 
52  |  |     OGRSpatialReference m_oSRS{}; | 
53  |  |     std::unique_ptr<GDALDataset> m_poDS{}; | 
54  |  |     // Array of overview datasets, that are guaranteed to have the same  | 
55  |  |     // georeferenced extent as m_poDS (and this dataset), for compliance  | 
56  |  |     // with the GDAL data model. They are thus possibly VRT subsets of  | 
57  |  |     // the STACTARawDataset stored in m_apoIntermediaryDS  | 
58  |  |     std::vector<std::unique_ptr<GDALDataset>> m_apoOverviewDS{}; | 
59  |  |     std::vector<std::unique_ptr<GDALDataset>> m_apoIntermediaryDS{}; | 
60  |  |  | 
61  |  |     // Cache of tile datasets  | 
62  |  |     lru11::Cache<std::string, std::unique_ptr<GDALDataset>> m_oCacheTileDS{32}; | 
63  |  |  | 
64  |  |     bool m_bDownloadWholeMetaTile = false;  | 
65  |  |     bool m_bSkipMissingMetaTile = false;  | 
66  |  |  | 
67  |  |     bool Open(GDALOpenInfo *poOpenInfo);  | 
68  |  |  | 
69  |  |   public:  | 
70  |  |     static int Identify(GDALOpenInfo *poOpenInfo);  | 
71  |  |     static GDALDataset *OpenStatic(GDALOpenInfo *poOpenInfo);  | 
72  |  |  | 
73  |  |     ~STACTADataset() override;  | 
74  |  |  | 
75  |  |     const OGRSpatialReference *GetSpatialRef() const override;  | 
76  |  |     CPLErr GetGeoTransform(double *padfGeoTransform) override;  | 
77  |  |     CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,  | 
78  |  |                      int nYSize, void *pData, int nBufXSize, int nBufYSize,  | 
79  |  |                      GDALDataType eBufType, int nBandCount,  | 
80  |  |                      BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,  | 
81  |  |                      GSpacing nLineSpace, GSpacing nBandSpace,  | 
82  |  |                      GDALRasterIOExtraArg *psExtraArg) override;  | 
83  |  |     CPLErr FlushCache(bool bAtClosing) override;  | 
84  |  | };  | 
85  |  |  | 
86  |  | /************************************************************************/  | 
87  |  | /* ==================================================================== */  | 
88  |  | /*                        STACTARasterBand                              */  | 
89  |  | /* ==================================================================== */  | 
90  |  | /************************************************************************/  | 
91  |  |  | 
92  |  | class STACTARasterBand final : public GDALRasterBand  | 
93  |  | { | 
94  |  |     friend class STACTADataset;  | 
95  |  |     GDALColorInterp m_eColorInterp = GCI_Undefined;  | 
96  |  |     int m_bHasNoDataValue = false;  | 
97  |  |     double m_dfNoData = 0;  | 
98  |  |     double m_dfScale = 1.0;  | 
99  |  |     double m_dfOffset = 0.0;  | 
100  |  |     std::string m_osUnit{}; | 
101  |  |  | 
102  |  |   public:  | 
103  |  |     STACTARasterBand(STACTADataset *poDSIn, int nBandIn,  | 
104  |  |                      GDALRasterBand *poProtoBand);  | 
105  |  |     CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;  | 
106  |  |     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,  | 
107  |  |                      GDALDataType, GSpacing, GSpacing,  | 
108  |  |                      GDALRasterIOExtraArg *psExtraArg) override;  | 
109  |  |  | 
110  |  |     GDALColorInterp GetColorInterpretation() override  | 
111  | 0  |     { | 
112  | 0  |         return m_eColorInterp;  | 
113  | 0  |     }  | 
114  |  |  | 
115  |  |     int GetOverviewCount() override;  | 
116  |  |     GDALRasterBand *GetOverview(int nIdx) override;  | 
117  |  |     double GetNoDataValue(int *pbHasNoData = nullptr) override;  | 
118  |  |  | 
119  |  |     const char *GetUnitType() override  | 
120  | 4  |     { | 
121  | 4  |         return m_osUnit.c_str();  | 
122  | 4  |     }  | 
123  |  |  | 
124  |  |     double GetScale(int *pbHasValue = nullptr) override  | 
125  | 4  |     { | 
126  | 4  |         if (pbHasValue)  | 
127  | 4  |             *pbHasValue = m_dfScale != 1.0;  | 
128  | 4  |         return m_dfScale;  | 
129  | 4  |     }  | 
130  |  |  | 
131  |  |     double GetOffset(int *pbHasValue = nullptr) override  | 
132  | 4  |     { | 
133  | 4  |         if (pbHasValue)  | 
134  | 4  |             *pbHasValue = m_dfOffset != 0.0;  | 
135  | 4  |         return m_dfOffset;  | 
136  | 4  |     }  | 
137  |  | };  | 
138  |  |  | 
139  |  | /************************************************************************/  | 
140  |  | /* ==================================================================== */  | 
141  |  | /*                        STACTARawDataset                              */  | 
142  |  | /* ==================================================================== */  | 
143  |  | /************************************************************************/  | 
144  |  |  | 
145  |  | class STACTARawDataset final : public GDALDataset  | 
146  |  | { | 
147  |  |     friend class STACTADataset;  | 
148  |  |     friend class STACTARawRasterBand;  | 
149  |  |  | 
150  |  |     CPLString m_osURLTemplate{}; | 
151  |  |     int m_nMinMetaTileCol = 0;  | 
152  |  |     int m_nMinMetaTileRow = 0;  | 
153  |  |     int m_nMetaTileWidth = 0;  | 
154  |  |     int m_nMetaTileHeight = 0;  | 
155  |  |     STACTADataset *m_poMasterDS = nullptr;  | 
156  |  |  | 
157  |  |     std::array<double, 6> m_adfGeoTransform = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}}; | 
158  |  |     OGRSpatialReference m_oSRS{}; | 
159  |  |  | 
160  |  |   public:  | 
161  |  |     bool InitRaster(GDALDataset *poProtoDS,  | 
162  |  |                     const std::vector<GDALDataType> &aeDT,  | 
163  |  |                     const std::vector<bool> &abSetNoData,  | 
164  |  |                     const std::vector<double> &adfNoData,  | 
165  |  |                     const gdal::TileMatrixSet *poTMS, const std::string &osTMId,  | 
166  |  |                     const gdal::TileMatrixSet::TileMatrix &oTM,  | 
167  |  |                     const std::map<CPLString, Limits> &oMapLimits);  | 
168  |  |  | 
169  |  |     const OGRSpatialReference *GetSpatialRef() const override  | 
170  | 0  |     { | 
171  | 0  |         return &m_oSRS;  | 
172  | 0  |     }  | 
173  |  |  | 
174  |  |     CPLErr GetGeoTransform(double *padfGeoTransform) override;  | 
175  |  |     CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,  | 
176  |  |                      int nYSize, void *pData, int nBufXSize, int nBufYSize,  | 
177  |  |                      GDALDataType eBufType, int nBandCount,  | 
178  |  |                      BANDMAP_TYPE panBandMap, GSpacing nPixelSpace,  | 
179  |  |                      GSpacing nLineSpace, GSpacing nBandSpace,  | 
180  |  |                      GDALRasterIOExtraArg *psExtraArg) override;  | 
181  |  | };  | 
182  |  |  | 
183  |  | /************************************************************************/  | 
184  |  | /* ==================================================================== */  | 
185  |  | /*                        STACTARawRasterBand                           */  | 
186  |  | /* ==================================================================== */  | 
187  |  | /************************************************************************/  | 
188  |  |  | 
189  |  | class STACTARawRasterBand final : public GDALRasterBand  | 
190  |  | { | 
191  |  |     GDALColorInterp m_eColorInterp = GCI_Undefined;  | 
192  |  |     int m_bHasNoDataValue = false;  | 
193  |  |     double m_dfNoData = 0;  | 
194  |  |  | 
195  |  |   public:  | 
196  |  |     STACTARawRasterBand(STACTARawDataset *poDSIn, int nBandIn,  | 
197  |  |                         GDALRasterBand *poProtoBand);  | 
198  |  |  | 
199  |  |     STACTARawRasterBand(STACTARawDataset *poDSIn, int nBandIn, GDALDataType eDT,  | 
200  |  |                         bool bSetNoData, double dfNoData);  | 
201  |  |  | 
202  |  |     CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;  | 
203  |  |     CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,  | 
204  |  |                      int nYSize, void *pData, int nBufXSize, int nBufYSize,  | 
205  |  |                      GDALDataType eBufType, GSpacing nPixelSpace,  | 
206  |  |                      GSpacing nLineSpace,  | 
207  |  |                      GDALRasterIOExtraArg *psExtraArg) override;  | 
208  |  |  | 
209  |  |     GDALColorInterp GetColorInterpretation() override  | 
210  | 24  |     { | 
211  | 24  |         return m_eColorInterp;  | 
212  | 24  |     }  | 
213  |  |  | 
214  |  |     double GetNoDataValue(int *pbHasNoData = nullptr) override;  | 
215  |  | };  | 
216  |  |  | 
217  |  | #endif  // STACTADATASET_H  |