1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
/******************************************************************************
* $Id: wmsdriver.h 25776 2013-03-20 20:46:48Z rouault $
*
* Project: WMS Client Driver
* Purpose: Implementation of Dataset and RasterBand classes for WMS
* and other similar services.
* Author: Adam Nowacki, nowak@xpam.de
*
******************************************************************************
* Copyright (c) 2007, Adam Nowacki
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
class GDALWMSDataset;
class GDALWMSRasterBand;
CPLString MD5String(const char *s);
CPLString ProjToWKT(const CPLString &proj);
void URLAppend(CPLString *url, const char *s);
void URLAppendF(CPLString *url, const char *s, ...);
void URLAppend(CPLString *url, const CPLString &s);
CPLString BufferToVSIFile(GByte *buffer, size_t size);
CPLErr MakeDirs(const char *path);
int StrToBool(const char *p);
int URLSearchAndReplace (CPLString *base, const char *search, const char *fmt, ...);
/* Convert a.b.c.d to a * 0x1000000 + b * 0x10000 + c * 0x100 + d */
int VersionStringToInt(const char *version);
class GDALWMSImageRequestInfo {
public:
double m_x0, m_y0;
double m_x1, m_y1;
int m_sx, m_sy;
};
class GDALWMSDataWindow {
public:
double m_x0, m_y0;
double m_x1, m_y1;
int m_sx, m_sy;
int m_tx, m_ty, m_tlevel;
enum { BOTTOM = -1, DEFAULT = 0, TOP = 1 } m_y_origin;
GDALWMSDataWindow() : m_x0(-180), m_y0(90), m_x1(180), m_y1(-90),
m_sx(-1), m_sy(-1), m_tx(0), m_ty(0),
m_tlevel(-1), m_y_origin(DEFAULT) {}
};
class GDALWMSTiledImageRequestInfo {
public:
int m_x, m_y;
int m_level;
};
class GDALWMSRasterIOHint {
public:
int m_x0, m_y0;
int m_sx, m_sy;
int m_overview;
bool m_valid;
};
class GDALWMSMiniDriverCapabilities {
public:
/* Version N capabilities require all version N and earlier variables to be set to correct values */
int m_capabilities_version;
/* Version 1 capabilities */
int m_has_image_request; // 1 if ImageRequest method is implemented
int m_has_tiled_image_requeset; // 1 if TiledImageRequest method is implemented
int m_has_arb_overviews; // 1 if ImageRequest method supports arbitrary overviews / resolutions
int m_max_overview_count; // Maximum number of overviews supported if known, -1 otherwise
};
/* All data returned by mini-driver as pointer should remain valid for mini-driver lifetime
and should be freed by mini-driver destructor unless otherwise specified. */
class GDALWMSMiniDriver {
friend class GDALWMSDataset;
public:
GDALWMSMiniDriver();
virtual ~GDALWMSMiniDriver();
public:
/* Read mini-driver specific configuration. */
virtual CPLErr Initialize(CPLXMLNode *config);
public:
virtual void GetCapabilities(GDALWMSMiniDriverCapabilities *caps);
virtual void ImageRequest(CPLString *url, const GDALWMSImageRequestInfo &iri);
virtual void TiledImageRequest(CPLString *url, const GDALWMSImageRequestInfo &iri, const GDALWMSTiledImageRequestInfo &tiri);
virtual void GetTiledImageInfo(CPLString *url,
const GDALWMSImageRequestInfo &iri,
const GDALWMSTiledImageRequestInfo &tiri,
int nXInBlock,
int nYInBlock);
/* Return data projection in WKT format, NULL or empty string if unknown */
virtual const char *GetProjectionInWKT();
protected:
GDALWMSDataset *m_parent_dataset;
};
class GDALWMSMiniDriverFactory {
public:
GDALWMSMiniDriverFactory();
virtual ~GDALWMSMiniDriverFactory();
public:
virtual GDALWMSMiniDriver* New() = 0;
virtual void Delete(GDALWMSMiniDriver *instance) = 0;
public:
const CPLString &GetName() {
return m_name;
}
protected:
CPLString m_name;
};
class GDALWMSMiniDriverManager {
public:
GDALWMSMiniDriverManager();
~GDALWMSMiniDriverManager();
public:
void Register(GDALWMSMiniDriverFactory *mdf);
GDALWMSMiniDriverFactory *Find(const CPLString &name);
protected:
std::list<GDALWMSMiniDriverFactory *> m_mdfs;
};
#define H_GDALWMSMiniDriverFactory(name) \
class GDALWMSMiniDriverFactory_##name : public GDALWMSMiniDriverFactory { \
public: \
GDALWMSMiniDriverFactory_##name(); \
virtual ~GDALWMSMiniDriverFactory_##name(); \
\
public: \
virtual GDALWMSMiniDriver* New(); \
virtual void Delete(GDALWMSMiniDriver *instance); \
};
#define CPP_GDALWMSMiniDriverFactory(name) \
GDALWMSMiniDriverFactory_##name::GDALWMSMiniDriverFactory_##name() { \
m_name = #name;\
} \
\
GDALWMSMiniDriverFactory_##name::~GDALWMSMiniDriverFactory_##name() { \
} \
\
GDALWMSMiniDriver* GDALWMSMiniDriverFactory_##name::New() { \
return new GDALWMSMiniDriver_##name(); \
} \
\
void GDALWMSMiniDriverFactory_##name::Delete(GDALWMSMiniDriver *instance) { \
delete instance; \
}
class GDALWMSCache {
public:
GDALWMSCache();
~GDALWMSCache();
public:
CPLErr Initialize(CPLXMLNode *config);
CPLErr Write(const char *key, const CPLString &file_name);
CPLErr Read(const char *key, CPLString *file_name);
protected:
CPLString KeyToCacheFile(const char *key);
protected:
CPLString m_cache_path;
CPLString m_postfix;
int m_cache_depth;
};
class GDALWMSDataset : public GDALPamDataset {
friend class GDALWMSRasterBand;
public:
GDALWMSDataset();
virtual ~GDALWMSDataset();
virtual const char *GetProjectionRef();
virtual CPLErr SetProjection(const char *proj);
virtual CPLErr GetGeoTransform(double *gt);
virtual CPLErr SetGeoTransform(double *gt);
virtual CPLErr AdviseRead(int x0, int y0, int sx, int sy, int bsx, int bsy, GDALDataType bdt, int band_count, int *band_map, char **options);
virtual const char *GetMetadataItem( const char * pszName,
const char * pszDomain = "" );
const GDALWMSDataWindow *WMSGetDataWindow() const;
void WMSSetClamp(bool flag);
void WMSSetBlockSize(int x, int y);
void WMSSetRasterSize(int x, int y);
void WMSSetDataType(GDALDataType type);
void WMSSetDataWindow(GDALWMSDataWindow &window);
void WMSSetBandsCount(int count);
void SetColorTable(GDALColorTable *pct) { m_poColorTable=pct; }
void WMSSetNoDataValue(const char * pszNoData);
void WMSSetMinValue(const char* pszMin);
void WMSSetMaxValue(const char* pszMax);
void mSetBand(int i, GDALRasterBand *band) { SetBand(i,band); };
GDALWMSRasterBand *mGetBand(int i) { return reinterpret_cast<GDALWMSRasterBand *>(GetRasterBand(i)); };
void WMSSetDefaultDataWindowCoordinates(double x0, double y0, double x1, double y1);
void WMSSetDefaultTileLevel(int tlevel);
void WMSSetDefaultTileCount(int tilecountx, int tilecounty);
void WMSSetDefaultBlockSize(int x, int y);
void WMSSetDefaultOverviewCount(int overview_count);
void WMSSetNeedsDataWindow(int flag);
static GDALDataset* Open(GDALOpenInfo *poOpenInfo);
static int Identify(GDALOpenInfo *poOpenInfo);
static GDALDataset *CreateCopy( const char * pszFilename,
GDALDataset *poSrcDS,
int bStrict, char ** papszOptions,
GDALProgressFunc pfnProgress,
void * pProgressData );
protected:
virtual CPLErr IRasterIO(GDALRWFlag rw, int x0, int y0, int sx, int sy, void *buffer, int bsx, int bsy, GDALDataType bdt, int band_count, int *band_map, int pixel_space, int line_space, int band_space);
CPLErr Initialize(CPLXMLNode *config);
GDALWMSDataWindow m_data_window;
GDALWMSMiniDriver *m_mini_driver;
GDALWMSMiniDriverCapabilities m_mini_driver_caps;
GDALWMSCache *m_cache;
CPLString m_projection;
GDALColorTable *m_poColorTable;
std::vector<double> vNoData, vMin, vMax;
GDALDataType m_data_type;
int m_block_size_x, m_block_size_y;
GDALWMSRasterIOHint m_hint;
int m_use_advise_read;
int m_verify_advise_read;
int m_offline_mode;
int m_http_max_conn;
int m_http_timeout;
int m_clamp_requests;
int m_unsafeSsl;
std::vector<int> m_http_zeroblock_codes;
int m_zeroblock_on_serverexceptions;
CPLString m_osUserAgent;
CPLString m_osReferer;
CPLString m_osUserPwd;
GDALWMSDataWindow m_default_data_window;
int m_default_block_size_x, m_default_block_size_y;
int m_default_tile_count_x, m_default_tile_count_y;
int m_default_overview_count;
int m_bNeedsDataWindow;
CPLString m_osXML;
};
class GDALWMSRasterBand : public GDALPamRasterBand {
friend class GDALWMSDataset;
char** BuildHTTPRequestOpts();
void ComputeRequestInfo( GDALWMSImageRequestInfo &iri,
GDALWMSTiledImageRequestInfo &tiri,
int x, int y);
CPLString osMetadataItem;
CPLString osMetadataItemURL;
public:
GDALWMSRasterBand(GDALWMSDataset *parent_dataset, int band, double scale);
virtual ~GDALWMSRasterBand();
void AddOverview(double scale);
virtual double GetNoDataValue( int * );
virtual double GetMinimum( int * );
virtual double GetMaximum( int * );
virtual GDALColorTable *GetColorTable();
virtual CPLErr AdviseRead(int x0, int y0, int sx, int sy, int bsx, int bsy, GDALDataType bdt, char **options);
virtual GDALColorInterp GetColorInterpretation();
virtual CPLErr SetColorInterpretation( GDALColorInterp );
virtual CPLErr IReadBlock(int x, int y, void *buffer);
virtual CPLErr IRasterIO(GDALRWFlag rw, int x0, int y0, int sx, int sy, void *buffer, int bsx, int bsy, GDALDataType bdt, int pixel_space, int line_space);
virtual int HasArbitraryOverviews();
virtual int GetOverviewCount();
virtual GDALRasterBand *GetOverview(int n);
virtual const char *GetMetadataItem( const char * pszName,
const char * pszDomain = "" );
protected:
CPLErr ReadBlocks(int x, int y, void *buffer, int bx0, int by0, int bx1, int by1, int advise_read);
bool IsBlockInCache(int x, int y);
void AskMiniDriverForBlock(CPLString *url, int x, int y);
CPLErr ReadBlockFromFile(int x, int y, const char *file_name, int to_buffer_band, void *buffer, int advise_read);
CPLErr ZeroBlock(int x, int y, int to_buffer_band, void *buffer);
CPLErr ReportWMSException(const char *file_name);
protected:
GDALWMSDataset *m_parent_dataset;
double m_scale;
std::vector<GDALWMSRasterBand *> m_overviews;
int m_overview;
GDALColorInterp m_color_interp;
};
GDALWMSMiniDriverManager *GetGDALWMSMiniDriverManager();
void DestroyWMSMiniDriverManager(void);
|