Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: WCS Client Driver
4 : * Purpose: Implementation of Dataset class for WCS.
5 : * Author: Frank Warmerdam, warmerdam@pobox.com
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2006, Frank Warmerdam
9 : * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
10 : * Copyright (c) 2017, Ari Jolma
11 : * Copyright (c) 2017, Finnish Environment Institute
12 : *
13 : * SPDX-License-Identifier: MIT
14 : ****************************************************************************/
15 :
16 : #ifndef WCSDATASET_H_INCLUDED
17 : #define WCSDATASET_H_INCLUDED
18 :
19 : /************************************************************************/
20 : /* ==================================================================== */
21 : /* WCSDataset */
22 : /* ==================================================================== */
23 : /************************************************************************/
24 :
25 : #include "cpl_string.h"
26 : #include "gdal_pam.h"
27 :
28 : class WCSRasterBand;
29 :
30 : class WCSDataset CPL_NON_FINAL : public GDALPamDataset
31 : {
32 : friend class WCSRasterBand;
33 : friend class WCSDataset100;
34 : friend class WCSDataset110;
35 : friend class WCSDataset201;
36 :
37 : std::string m_cache_dir;
38 : bool bServiceDirty;
39 : CPLXMLNode *psService;
40 :
41 : char *apszCoverageOfferingMD[2];
42 :
43 : char **papszSDSModifiers;
44 :
45 : int m_Version; // eg 100 for 1.0.0, 110 for 1.1.0
46 : const char *Version() const;
47 :
48 : std::string osCRS; // name of the CRS
49 : OGRSpatialReference m_oSRS{};
50 : bool native_crs; // the CRS is the native CRS of the server
51 : bool axis_order_swap; // the CRS requires x and y coordinates to be swapped
52 : // for requests
53 : GDALGeoTransform m_gt{};
54 : bool SetCRS(const std::string &crs, bool native);
55 : void SetGeometry(const std::vector<int> &size,
56 : const std::vector<double> &origin,
57 : const std::vector<std::vector<double>> &offsets);
58 :
59 : std::string osBandIdentifier;
60 :
61 : std::string osDefaultTime;
62 : std::vector<std::string> aosTimePositions;
63 :
64 : int TestUseBlockIO(int, int, int, int, int, int) const;
65 : CPLErr DirectRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
66 : GDALDataType, int, const int *, GSpacing nPixelSpace,
67 : GSpacing nLineSpace, GSpacing nBandSpace,
68 : GDALRasterIOExtraArg *psExtraArg);
69 :
70 : CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
71 : GDALDataType, int, BANDMAP_TYPE, GSpacing nPixelSpace,
72 : GSpacing nLineSpace, GSpacing nBandSpace,
73 : GDALRasterIOExtraArg *psExtraArg) override;
74 :
75 : virtual std::vector<double> GetNativeExtent(int nXOff, int nYOff,
76 : int nXSize, int nYSize,
77 : int nBufXSize,
78 : int nBufYSize) = 0;
79 :
80 : virtual std::string GetCoverageRequest(bool scaled, int nBufXSize,
81 : int nBufYSize,
82 : const std::vector<double> &extent,
83 : const std::string &osBandList) = 0;
84 :
85 : CPLErr GetCoverage(int nXOff, int nYOff, int nXSize, int nYSize,
86 : int nBufXSize, int nBufYSize, int nBandCount,
87 : const int *panBandList, GDALRasterIOExtraArg *psExtraArg,
88 : CPLHTTPResult **ppsResult);
89 :
90 0 : virtual std::string DescribeCoverageRequest()
91 : {
92 0 : return "";
93 : }
94 :
95 : virtual CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) = 0;
96 :
97 : int DescribeCoverage();
98 :
99 : virtual bool ExtractGridInfo() = 0;
100 :
101 : int EstablishRasterDetails();
102 :
103 : virtual CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) = 0;
104 : virtual void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
105 : CPLXMLNode *) = 0;
106 :
107 : GDALDataset *GDALOpenResult(CPLHTTPResult *psResult);
108 :
109 : void FlushMemoryResult();
110 :
111 : std::string osResultFilename;
112 :
113 : GByte *pabySavedDataBuffer;
114 :
115 : char **papszHttpOptions;
116 :
117 : int nMaxCols;
118 : int nMaxRows;
119 :
120 : public:
121 : WCSDataset(int version, const char *cache_dir);
122 : ~WCSDataset() override;
123 :
124 : static WCSDataset *CreateFromMetadata(const std::string &,
125 : const std::string &);
126 : static WCSDataset *CreateFromCapabilities(const std::string &,
127 : const std::string &,
128 : const std::string &);
129 :
130 : static GDALDataset *Open(GDALOpenInfo *);
131 : static int Identify(GDALOpenInfo *);
132 :
133 : CPLErr GetGeoTransform(GDALGeoTransform >) const override;
134 : const OGRSpatialReference *GetSpatialRef() const override;
135 : char **GetFileList(void) override;
136 :
137 : char **GetMetadataDomainList() override;
138 : char **GetMetadata(const char *pszDomain) override;
139 : };
140 :
141 : class WCSDataset100 final : public WCSDataset
142 : {
143 : std::vector<double> GetNativeExtent(int nXOff, int nYOff, int nXSize,
144 : int nYSize, int nBufXSize,
145 : int nBufYSize) override;
146 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
147 : const std::vector<double> &extent,
148 : const std::string &osBandList) override;
149 : std::string DescribeCoverageRequest() override;
150 : CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
151 : bool ExtractGridInfo() override;
152 : CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
153 : void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
154 : CPLXMLNode *) override;
155 :
156 : public:
157 26 : explicit WCSDataset100(const char *cache_dir) : WCSDataset(100, cache_dir)
158 : {
159 26 : }
160 : };
161 :
162 : class WCSDataset110 CPL_NON_FINAL : public WCSDataset
163 : {
164 : std::vector<double> GetNativeExtent(int nXOff, int nYOff, int nXSize,
165 : int nYSize, int nBufXSize,
166 : int nBufYSize) override;
167 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
168 : const std::vector<double> &extent,
169 : const std::string &) override;
170 : std::string DescribeCoverageRequest() override;
171 : CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
172 : bool ExtractGridInfo() override;
173 : CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
174 : void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
175 : CPLXMLNode *) override;
176 :
177 : public:
178 95 : WCSDataset110(int version, const char *cache_dir)
179 95 : : WCSDataset(version, cache_dir)
180 : {
181 95 : }
182 : };
183 :
184 : class WCSDataset201 final : public WCSDataset110
185 : {
186 : std::vector<double> GetNativeExtent(int nXOff, int nYOff, int nXSize,
187 : int nYSize, int nBufXSize,
188 : int nBufYSize) override;
189 : std::string GetSubdataset(const std::string &coverage);
190 : bool SetFormat(CPLXMLNode *coverage);
191 : static bool ParseGridFunction(CPLXMLNode *coverage,
192 : std::vector<int> &axisOrder);
193 : int ParseRange(CPLXMLNode *coverage, const std::string &range_subset,
194 : char ***metadata);
195 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
196 : const std::vector<double> &extent,
197 : const std::string &osBandList) override;
198 : std::string DescribeCoverageRequest() override;
199 : bool GridOffsets(CPLXMLNode *grid, const std::string &subtype,
200 : bool swap_grid_axis, std::vector<double> &origin,
201 : std::vector<std::vector<double>> &offset,
202 : std::vector<std::string> labels, char ***metadata);
203 : bool Offset2GeoTransform(const std::vector<double> &origin,
204 : const std::vector<std::vector<double>> &offset);
205 : bool ExtractGridInfo() override;
206 :
207 : public:
208 35 : explicit WCSDataset201(const char *cache_dir)
209 35 : : WCSDataset110(201, cache_dir)
210 : {
211 35 : }
212 : };
213 :
214 : #define DIGIT_ZERO '0'
215 :
216 : // The WCS URL parameters that can be set
217 : // - through options to the service file
218 : // - to the URL
219 : // These are also inherited from template service file.
220 : // Fundamental URL parameters (service, version, request, coverage)
221 : // and parameters that require more work from the driver's part, such
222 : // as subsetting parameters (subset, rangesubset) are not in this
223 : // list.
224 :
225 : #define WCS_URL_PARAMETERS \
226 : "Format", "Interpolation", "MediaType", "UpdateSequence", \
227 : "GEOTIFF:COMPRESSION", "GEOTIFF:JPEG_QUALITY", "GEOTIFF:PREDICTOR", \
228 : "GEOTIFF:INTERLEAVE", "GEOTIFF:TILING", "GEOTIFF:TILEWIDTH"
229 :
230 : #endif /* WCSDATASET_H_INCLUDED */
|