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 : * Permission is hereby granted, free of charge, to any person obtaining a
14 : * copy of this software and associated documentation files (the "Software"),
15 : * to deal in the Software without restriction, including without limitation
16 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 : * and/or sell copies of the Software, and to permit persons to whom the
18 : * Software is furnished to do so, subject to the following conditions:
19 : *
20 : * The above copyright notice and this permission notice shall be included
21 : * in all copies or substantial portions of the Software.
22 : *
23 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 : * DEALINGS IN THE SOFTWARE.
30 : ****************************************************************************/
31 :
32 : #ifndef WCSDATASET_H_INCLUDED
33 : #define WCSDATASET_H_INCLUDED
34 :
35 : /************************************************************************/
36 : /* ==================================================================== */
37 : /* WCSDataset */
38 : /* ==================================================================== */
39 : /************************************************************************/
40 :
41 : #include "cpl_string.h"
42 : #include "gdal_pam.h"
43 :
44 : class WCSRasterBand;
45 :
46 : class WCSDataset CPL_NON_FINAL : public GDALPamDataset
47 : {
48 : friend class WCSRasterBand;
49 : friend class WCSDataset100;
50 : friend class WCSDataset110;
51 : friend class WCSDataset201;
52 :
53 : std::string m_cache_dir;
54 : bool bServiceDirty;
55 : CPLXMLNode *psService;
56 :
57 : char *apszCoverageOfferingMD[2];
58 :
59 : char **papszSDSModifiers;
60 :
61 : int m_Version; // eg 100 for 1.0.0, 110 for 1.1.0
62 : const char *Version() const;
63 :
64 : std::string osCRS; // name of the CRS
65 : OGRSpatialReference m_oSRS{};
66 : bool native_crs; // the CRS is the native CRS of the server
67 : bool axis_order_swap; // the CRS requires x and y coordinates to be swapped
68 : // for requests
69 : double adfGeoTransform[6];
70 : bool SetCRS(const std::string &crs, bool native);
71 : void SetGeometry(const std::vector<int> &size,
72 : const std::vector<double> &origin,
73 : const std::vector<std::vector<double>> &offsets);
74 :
75 : std::string osBandIdentifier;
76 :
77 : std::string osDefaultTime;
78 : std::vector<std::string> aosTimePositions;
79 :
80 : int TestUseBlockIO(int, int, int, int, int, int) const;
81 : CPLErr DirectRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
82 : GDALDataType, int, int *, GSpacing nPixelSpace,
83 : GSpacing nLineSpace, GSpacing nBandSpace,
84 : GDALRasterIOExtraArg *psExtraArg);
85 :
86 : virtual CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
87 : GDALDataType, int, int *, GSpacing nPixelSpace,
88 : GSpacing nLineSpace, GSpacing nBandSpace,
89 : GDALRasterIOExtraArg *psExtraArg) override;
90 :
91 : virtual std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize,
92 : int nYSize, int nBufXSize,
93 : int nBufYSize) = 0;
94 :
95 : virtual std::string GetCoverageRequest(bool scaled, int nBufXSize,
96 : int nBufYSize,
97 : const std::vector<double> &extent,
98 : const std::string &osBandList) = 0;
99 :
100 : CPLErr GetCoverage(int nXOff, int nYOff, int nXSize, int nYSize,
101 : int nBufXSize, int nBufYSize, int nBandCount,
102 : int *panBandList, GDALRasterIOExtraArg *psExtraArg,
103 : CPLHTTPResult **ppsResult);
104 :
105 0 : virtual std::string DescribeCoverageRequest()
106 : {
107 0 : return "";
108 : }
109 :
110 : virtual CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) = 0;
111 :
112 : int DescribeCoverage();
113 :
114 : virtual bool ExtractGridInfo() = 0;
115 :
116 : int EstablishRasterDetails();
117 :
118 : virtual CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) = 0;
119 : virtual void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
120 : CPLXMLNode *) = 0;
121 :
122 : GDALDataset *GDALOpenResult(CPLHTTPResult *psResult);
123 :
124 : void FlushMemoryResult();
125 :
126 : std::string osResultFilename;
127 :
128 : GByte *pabySavedDataBuffer;
129 :
130 : char **papszHttpOptions;
131 :
132 : int nMaxCols;
133 : int nMaxRows;
134 :
135 : public:
136 : WCSDataset(int version, const char *cache_dir);
137 : virtual ~WCSDataset();
138 :
139 : static WCSDataset *CreateFromMetadata(const std::string &,
140 : const std::string &);
141 : static WCSDataset *CreateFromCapabilities(const std::string &,
142 : const std::string &,
143 : const std::string &);
144 :
145 : static GDALDataset *Open(GDALOpenInfo *);
146 : static int Identify(GDALOpenInfo *);
147 :
148 : virtual CPLErr GetGeoTransform(double *) override;
149 : const OGRSpatialReference *GetSpatialRef() const override;
150 : virtual char **GetFileList(void) override;
151 :
152 : virtual char **GetMetadataDomainList() override;
153 : virtual char **GetMetadata(const char *pszDomain) override;
154 : };
155 :
156 : class WCSDataset100 final : public WCSDataset
157 : {
158 : std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize, int nYSize,
159 : int nBufXSize, int nBufYSize) override;
160 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
161 : const std::vector<double> &extent,
162 : const std::string &osBandList) override;
163 : std::string DescribeCoverageRequest() override;
164 : CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
165 : bool ExtractGridInfo() override;
166 : CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
167 : void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
168 : CPLXMLNode *) override;
169 :
170 : public:
171 26 : explicit WCSDataset100(const char *cache_dir) : WCSDataset(100, cache_dir)
172 : {
173 26 : }
174 : };
175 :
176 : class WCSDataset110 CPL_NON_FINAL : public WCSDataset
177 : {
178 : std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize, int nYSize,
179 : int nBufXSize, int nBufYSize) override;
180 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
181 : const std::vector<double> &extent,
182 : const std::string &) override;
183 : std::string DescribeCoverageRequest() override;
184 : CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
185 : bool ExtractGridInfo() override;
186 : CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
187 : void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
188 : CPLXMLNode *) override;
189 :
190 : public:
191 95 : WCSDataset110(int version, const char *cache_dir)
192 95 : : WCSDataset(version, cache_dir)
193 : {
194 95 : }
195 : };
196 :
197 : class WCSDataset201 final : public WCSDataset110
198 : {
199 : std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize, int nYSize,
200 : int nBufXSize, int nBufYSize) override;
201 : std::string GetSubdataset(const std::string &coverage);
202 : bool SetFormat(CPLXMLNode *coverage);
203 : static bool ParseGridFunction(CPLXMLNode *coverage,
204 : std::vector<int> &axisOrder);
205 : int ParseRange(CPLXMLNode *coverage, const std::string &range_subset,
206 : char ***metadata);
207 : std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
208 : const std::vector<double> &extent,
209 : const std::string &osBandList) override;
210 : std::string DescribeCoverageRequest() override;
211 : bool GridOffsets(CPLXMLNode *grid, const std::string &subtype,
212 : bool swap_grid_axis, std::vector<double> &origin,
213 : std::vector<std::vector<double>> &offset,
214 : std::vector<std::string> labels, char ***metadata);
215 : bool Offset2GeoTransform(const std::vector<double> &origin,
216 : const std::vector<std::vector<double>> &offset);
217 : bool ExtractGridInfo() override;
218 :
219 : public:
220 35 : explicit WCSDataset201(const char *cache_dir)
221 35 : : WCSDataset110(201, cache_dir)
222 : {
223 35 : }
224 : };
225 :
226 : #define DIGIT_ZERO '0'
227 :
228 : // The WCS URL parameters that can be set
229 : // - through options to the service file
230 : // - to the URL
231 : // These are also inherited from template service file.
232 : // Fundamental URL parameters (service, version, request, coverage)
233 : // and parameters that require more work from the driver's part, such
234 : // as subsetting parameters (subset, rangesubset) are not in this
235 : // list.
236 :
237 : #define WCS_URL_PARAMETERS \
238 : "Format", "Interpolation", "MediaType", "UpdateSequence", \
239 : "GEOTIFF:COMPRESSION", "GEOTIFF:JPEG_QUALITY", "GEOTIFF:PREDICTOR", \
240 : "GEOTIFF:INTERLEAVE", "GEOTIFF:TILING", "GEOTIFF:TILEWIDTH"
241 :
242 : #endif /* WCSDATASET_H_INCLUDED */
|