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 : virtual CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
71 : GDALDataType, int, BANDMAP_TYPE,
72 : GSpacing nPixelSpace, GSpacing nLineSpace,
73 : GSpacing nBandSpace,
74 : GDALRasterIOExtraArg *psExtraArg) override;
75 :
76 : virtual std::vector<double> GetNativeExtent(int nXOff, int nYOff,
77 : int nXSize, int nYSize,
78 : int nBufXSize,
79 : int nBufYSize) = 0;
80 :
81 : virtual std::string GetCoverageRequest(bool scaled, int nBufXSize,
82 : int nBufYSize,
83 : const std::vector<double> &extent,
84 : const std::string &osBandList) = 0;
85 :
86 : CPLErr GetCoverage(int nXOff, int nYOff, int nXSize, int nYSize,
87 : int nBufXSize, int nBufYSize, int nBandCount,
88 : const int *panBandList, GDALRasterIOExtraArg *psExtraArg,
89 : CPLHTTPResult **ppsResult);
90 :
91 0 : virtual std::string DescribeCoverageRequest()
92 : {
93 0 : return "";
94 : }
95 :
96 : virtual CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) = 0;
97 :
98 : int DescribeCoverage();
99 :
100 : virtual bool ExtractGridInfo() = 0;
101 :
102 : int EstablishRasterDetails();
103 :
104 : virtual CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) = 0;
105 : virtual void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
106 : CPLXMLNode *) = 0;
107 :
108 : GDALDataset *GDALOpenResult(CPLHTTPResult *psResult);
109 :
110 : void FlushMemoryResult();
111 :
112 : std::string osResultFilename;
113 :
114 : GByte *pabySavedDataBuffer;
115 :
116 : char **papszHttpOptions;
117 :
118 : int nMaxCols;
119 : int nMaxRows;
120 :
121 : public:
122 : WCSDataset(int version, const char *cache_dir);
123 : virtual ~WCSDataset();
124 :
125 : static WCSDataset *CreateFromMetadata(const std::string &,
126 : const std::string &);
127 : static WCSDataset *CreateFromCapabilities(const std::string &,
128 : const std::string &,
129 : const std::string &);
130 :
131 : static GDALDataset *Open(GDALOpenInfo *);
132 : static int Identify(GDALOpenInfo *);
133 :
134 : virtual CPLErr GetGeoTransform(GDALGeoTransform >) const override;
135 : const OGRSpatialReference *GetSpatialRef() const override;
136 : virtual char **GetFileList(void) override;
137 :
138 : virtual char **GetMetadataDomainList() override;
139 : virtual char **GetMetadata(const char *pszDomain) override;
140 : };
141 :
142 : class WCSDataset100 final : public WCSDataset
143 : {
144 : std::vector<double> GetNativeExtent(int nXOff, int nYOff, int nXSize,
145 : int nYSize, int nBufXSize,
146 : int nBufYSize) override;
147 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
148 : const std::vector<double> &extent,
149 : const std::string &osBandList) override;
150 : std::string DescribeCoverageRequest() override;
151 : CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
152 : bool ExtractGridInfo() override;
153 : CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
154 : void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
155 : CPLXMLNode *) override;
156 :
157 : public:
158 26 : explicit WCSDataset100(const char *cache_dir) : WCSDataset(100, cache_dir)
159 : {
160 26 : }
161 : };
162 :
163 : class WCSDataset110 CPL_NON_FINAL : public WCSDataset
164 : {
165 : std::vector<double> GetNativeExtent(int nXOff, int nYOff, int nXSize,
166 : int nYSize, int nBufXSize,
167 : int nBufYSize) override;
168 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
169 : const std::vector<double> &extent,
170 : const std::string &) override;
171 : std::string DescribeCoverageRequest() override;
172 : CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
173 : bool ExtractGridInfo() override;
174 : CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
175 : void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
176 : CPLXMLNode *) override;
177 :
178 : public:
179 95 : WCSDataset110(int version, const char *cache_dir)
180 95 : : WCSDataset(version, cache_dir)
181 : {
182 95 : }
183 : };
184 :
185 : class WCSDataset201 final : public WCSDataset110
186 : {
187 : std::vector<double> GetNativeExtent(int nXOff, int nYOff, int nXSize,
188 : int nYSize, int nBufXSize,
189 : int nBufYSize) override;
190 : std::string GetSubdataset(const std::string &coverage);
191 : bool SetFormat(CPLXMLNode *coverage);
192 : static bool ParseGridFunction(CPLXMLNode *coverage,
193 : std::vector<int> &axisOrder);
194 : int ParseRange(CPLXMLNode *coverage, const std::string &range_subset,
195 : char ***metadata);
196 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
197 : const std::vector<double> &extent,
198 : const std::string &osBandList) override;
199 : std::string DescribeCoverageRequest() override;
200 : bool GridOffsets(CPLXMLNode *grid, const std::string &subtype,
201 : bool swap_grid_axis, std::vector<double> &origin,
202 : std::vector<std::vector<double>> &offset,
203 : std::vector<std::string> labels, char ***metadata);
204 : bool Offset2GeoTransform(const std::vector<double> &origin,
205 : const std::vector<std::vector<double>> &offset);
206 : bool ExtractGridInfo() override;
207 :
208 : public:
209 35 : explicit WCSDataset201(const char *cache_dir)
210 35 : : WCSDataset110(201, cache_dir)
211 : {
212 35 : }
213 : };
214 :
215 : #define DIGIT_ZERO '0'
216 :
217 : // The WCS URL parameters that can be set
218 : // - through options to the service file
219 : // - to the URL
220 : // These are also inherited from template service file.
221 : // Fundamental URL parameters (service, version, request, coverage)
222 : // and parameters that require more work from the driver's part, such
223 : // as subsetting parameters (subset, rangesubset) are not in this
224 : // list.
225 :
226 : #define WCS_URL_PARAMETERS \
227 : "Format", "Interpolation", "MediaType", "UpdateSequence", \
228 : "GEOTIFF:COMPRESSION", "GEOTIFF:JPEG_QUALITY", "GEOTIFF:PREDICTOR", \
229 : "GEOTIFF:INTERLEAVE", "GEOTIFF:TILING", "GEOTIFF:TILEWIDTH"
230 :
231 : #endif /* WCSDATASET_H_INCLUDED */
|