diff --git a/src/map/coordinatesystem.cpp b/src/map/coordinatesystem.cpp index bd2a2ad9..d50f855a 100644 --- a/src/map/coordinatesystem.cpp +++ b/src/map/coordinatesystem.cpp @@ -33,3 +33,24 @@ CoordinateSystem::CoordinateSystem(int code) break; } } + +#ifndef QT_NO_DEBUG +QDebug operator<<(QDebug dbg, const CoordinateSystem &cs) +{ + QString ao; + + switch (cs.axisOrder()) { + case CoordinateSystem::XY: + ao = "XY"; + break; + case CoordinateSystem::YX: + ao = "YX"; + break; + default: + ao = "Unknown"; + } + + dbg.nospace() << "CoordinateSystem(" << ao << ")"; + return dbg.space(); +} +#endif // QT_NO_DEBUG diff --git a/src/map/coordinatesystem.h b/src/map/coordinatesystem.h index 16b47db5..e2451788 100644 --- a/src/map/coordinatesystem.h +++ b/src/map/coordinatesystem.h @@ -1,12 +1,15 @@ #ifndef COORDINATESYSTEM_H #define COORDINATESYSTEM_H +#include + class CoordinateSystem { public: enum AxisOrder {Unknown, XY, YX}; CoordinateSystem() : _axisOrder(Unknown) {} + CoordinateSystem(AxisOrder axisOrder) : _axisOrder(axisOrder) {} CoordinateSystem(int code); bool isValid() const {return (_axisOrder != Unknown);} @@ -17,4 +20,8 @@ private: AxisOrder _axisOrder; }; +#ifndef QT_NO_DEBUG +QDebug operator<<(QDebug dbg, const CoordinateSystem &cs); +#endif // QT_NO_DEBUG + #endif // COORDINATESYSTEM_H diff --git a/src/map/mapsource.cpp b/src/map/mapsource.cpp index dfb65ab0..b163ef5d 100644 --- a/src/map/mapsource.cpp +++ b/src/map/mapsource.cpp @@ -15,11 +15,10 @@ MapSource::Config::Config() : type(TMS), zooms(ZOOM_MIN, ZOOM_MAX), bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT, - BOUNDS_BOTTOM)), format("image/png"), axisOrder(CoordinateSystem::Unknown), - rest(false) {} + BOUNDS_BOTTOM)), format("image/png"), rest(false) {} -static CoordinateSystem::AxisOrder axisOrder(QXmlStreamReader &reader) +static CoordinateSystem coordinateSystem(QXmlStreamReader &reader) { QXmlStreamAttributes attr = reader.attributes(); if (attr.value("axis") == "yx") @@ -142,7 +141,7 @@ void MapSource::map(QXmlStreamReader &reader, Config &config) else if (reader.name() == "style") config.style = reader.readElementText(); else if (reader.name() == "set") { - config.axisOrder = axisOrder(reader); + config.coordinateSystem = coordinateSystem(reader); config.set = reader.readElementText(); } else if (reader.name() == "dimension") { QXmlStreamAttributes attr = reader.attributes(); @@ -152,7 +151,7 @@ void MapSource::map(QXmlStreamReader &reader, Config &config) config.dimensions.append(QPair( attr.value("id").toString(), reader.readElementText())); } else if (reader.name() == "crs") { - config.axisOrder = axisOrder(reader); + config.coordinateSystem = coordinateSystem(reader); config.crs = reader.readElementText(); } else if (reader.name() == "authorization") { QXmlStreamAttributes attr = reader.attributes(); @@ -224,11 +223,11 @@ Map *MapSource::loadFile(const QString &path) if (config.type == WMTS) m = new WMTSMap(config.name, WMTS::Setup(config.url, config.layer, - config.set, config.style, config.format, config.rest, config.axisOrder, - config.dimensions, config.authorization)); + config.set, config.style, config.format, config.rest, + config.coordinateSystem, config.dimensions, config.authorization)); else if (config.type == WMS) m = new WMSMap(config.name, WMS::Setup(config.url, config.layer, - config.style, config.format, config.crs, config.axisOrder, + config.style, config.format, config.crs, config.coordinateSystem, config.authorization)); else m = new OnlineMap(config.name, config.url, config.zooms, config.bounds); diff --git a/src/map/mapsource.h b/src/map/mapsource.h index 4a3952af..bf368881 100644 --- a/src/map/mapsource.h +++ b/src/map/mapsource.h @@ -34,7 +34,7 @@ private: QString set; QString format; QString crs; - CoordinateSystem::AxisOrder axisOrder; + CoordinateSystem coordinateSystem; bool rest; QList > dimensions; Authorization authorization; diff --git a/src/map/projection.cpp b/src/map/projection.cpp index 4f509f07..2b5d082e 100644 --- a/src/map/projection.cpp +++ b/src/map/projection.cpp @@ -29,7 +29,7 @@ Projection::Method::Method(int id) } Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()), - _geographic(false) + _cs(pcs->coordinateSystem()), _geographic(false) { const Ellipsoid *ellipsoid = _gcs->datum().ellipsoid(); const Projection::Setup &setup = pcs->setup(); @@ -70,15 +70,12 @@ Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()), default: _ct = 0; } - - _axisOrder = pcs->coordinateSystem().axisOrder(); } -Projection::Projection(const GCS *gcs, CoordinateSystem::AxisOrder axisOrder) - : _gcs(gcs), _axisOrder(axisOrder), _geographic(true) +Projection::Projection(const GCS *gcs, const CoordinateSystem &cs) + : _gcs(gcs), _units(LinearUnits(9001)), _cs(cs), _geographic(true) { _ct = new LatLon(gcs->angularUnits()); - _units = LinearUnits(9001); } Projection::Projection(const Projection &p) @@ -87,7 +84,7 @@ Projection::Projection(const Projection &p) _units = p._units; _ct = p._ct ? p._ct->clone() : 0; _geographic = p._geographic; - _axisOrder = p._axisOrder; + _cs = p._cs; } Projection::~Projection() @@ -101,7 +98,7 @@ Projection &Projection::operator=(const Projection &p) _units = p._units; _ct = p._ct ? p._ct->clone() : 0; _geographic = p._geographic; - _axisOrder = p._axisOrder; + _cs = p._cs; return *this; } diff --git a/src/map/projection.h b/src/map/projection.h index d8a2281f..1497cbc3 100644 --- a/src/map/projection.h +++ b/src/map/projection.h @@ -73,8 +73,8 @@ public: Projection() : _gcs(0), _ct(0), _geographic(false) {} Projection(const Projection &p); Projection(const PCS *pcs); - Projection(const GCS *gcs, CoordinateSystem::AxisOrder axisOrder - = CoordinateSystem::YX); + Projection(const GCS *gcs, const CoordinateSystem &cs + = CoordinateSystem(CoordinateSystem::YX)); ~Projection(); Projection &operator=(const Projection &p); @@ -87,13 +87,13 @@ public: Coordinates xy2ll(const QPointF &p) const; const LinearUnits &units() const {return _units;} - CoordinateSystem::AxisOrder axisOrder() const {return _axisOrder;} + const CoordinateSystem &coordinateSystem() const {return _cs;} private: const GCS *_gcs; const CT *_ct; LinearUnits _units; - CoordinateSystem::AxisOrder _axisOrder; + CoordinateSystem _cs; bool _geographic; }; diff --git a/src/map/tileloader.cpp b/src/map/tileloader.cpp index a768b2d9..59f510b1 100644 --- a/src/map/tileloader.cpp +++ b/src/map/tileloader.cpp @@ -64,7 +64,7 @@ void TileLoader::loadTilesSync(QList &list) if (t.pixmap().isNull()) { QString file = tileFile(t); - if (QFileInfo(file).exists()) + if (QFileInfo::exists(file)) loadTileFile(t, file); } } diff --git a/src/map/wms.cpp b/src/map/wms.cpp index 447c3821..76e83459 100644 --- a/src/map/wms.cpp +++ b/src/map/wms.cpp @@ -63,7 +63,7 @@ QString WMS::style(QXmlStreamReader &reader) RectC WMS::geographicBoundingBox(QXmlStreamReader &reader) { - qreal left, top, right, bottom; + qreal left = NAN, top = NAN, right = NAN, bottom = NAN; while (reader.readNextStartElement()) { if (reader.name() == "westBoundLongitude") @@ -265,7 +265,7 @@ bool WMS::getCapabilities(const QString &url, const QString &file, if (_downloader->get(dl, authorization)) wait.exec(); - if (QFileInfo(file).exists()) + if (QFileInfo::exists(file)) return true; else { _errorString = "Error downloading capabilities XML file"; @@ -278,7 +278,7 @@ WMS::WMS(const QString &file, const WMS::Setup &setup) : _valid(false) QString capaUrl = QString("%1?service=WMS&request=GetCapabilities") .arg(setup.url()); - if (!QFileInfo(file).exists()) + if (!QFileInfo::exists(file)) if (!getCapabilities(capaUrl, file, setup.authorization())) return; if (!parseCapabilities(file, setup)) diff --git a/src/map/wms.h b/src/map/wms.h index e909ff67..fe297cc3 100644 --- a/src/map/wms.h +++ b/src/map/wms.h @@ -19,10 +19,10 @@ public: public: Setup(const QString &url, const QString &layer, const QString &style, const QString &format, const QString &crs, - CoordinateSystem::AxisOrder axisOrder, - const Authorization &authorization = Authorization()) - : _url(url), _layer(layer), _style(style), _format(format), _crs(crs), - _axisOrder(axisOrder), _authorization(authorization) {} + const CoordinateSystem &cs, const Authorization &authorization + = Authorization()) + : _url(url), _layer(layer), _style(style), _format(format), + _crs(crs), _cs(cs), _authorization(authorization) {} const QString &url() const {return _url;} const Authorization &authorization() const {return _authorization;} @@ -30,7 +30,7 @@ public: const QString &style() const {return _style;} const QString &format() const {return _format;} const QString &crs() const {return _crs;} - CoordinateSystem::AxisOrder axisOrder() const {return _axisOrder;} + const CoordinateSystem &coordinateSystem() const {return _cs;} private: QString _url; @@ -38,7 +38,7 @@ public: QString _style; QString _format; QString _crs; - CoordinateSystem::AxisOrder _axisOrder; + CoordinateSystem _cs; Authorization _authorization; }; diff --git a/src/map/wmsmap.cpp b/src/map/wmsmap.cpp index 62b47d6c..77167dd8 100644 --- a/src/map/wmsmap.cpp +++ b/src/map/wmsmap.cpp @@ -87,12 +87,12 @@ bool WMSMap::loadWMS() _setup.authorization()); if (wms.version() >= "1.3.0") { - if (_setup.axisOrder() == CoordinateSystem::Unknown) - _axisOrder = _projection.axisOrder(); + if (_setup.coordinateSystem().axisOrder() == CoordinateSystem::Unknown) + _cs = _projection.coordinateSystem(); else - _axisOrder = _setup.axisOrder(); + _cs = _setup.coordinateSystem(); } else - _axisOrder = CoordinateSystem::XY; + _cs = CoordinateSystem::XY; computeZooms(wms.scaleDenominator()); updateTransform(); @@ -221,7 +221,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect) j * TILE_SIZE))); QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE - 1, j * TILE_SIZE + TILE_SIZE - 1))); - QRectF bbox = (_axisOrder == CoordinateSystem::YX) + QRectF bbox = (_cs.axisOrder() == CoordinateSystem::YX) ? QRectF(QPointF(tbr.y(), tbr.x()), QPointF(ttl.y(), ttl.x())) : QRectF(ttl, tbr); diff --git a/src/map/wmsmap.h b/src/map/wmsmap.h index aadcc4ac..1e2c2336 100644 --- a/src/map/wmsmap.h +++ b/src/map/wmsmap.h @@ -61,10 +61,10 @@ private: TileLoader _tileLoader; Projection _projection; Transform _transform; + CoordinateSystem _cs; QVector _zooms; - int _zoom; QRectF _boundingBox; - CoordinateSystem::AxisOrder _axisOrder; + int _zoom; bool _block; bool _valid; diff --git a/src/map/wmts.cpp b/src/map/wmts.cpp index b237255a..41aa27c5 100644 --- a/src/map/wmts.cpp +++ b/src/map/wmts.cpp @@ -291,7 +291,7 @@ bool WMTS::getCapabilities(const QString &url, const QString &file, if (_downloader->get(dl, authorization)) wait.exec(); - if (QFileInfo(file).exists()) + if (QFileInfo::exists(file)) return true; else { _errorString = "Error downloading capabilities XML file"; @@ -305,7 +305,7 @@ WMTS::WMTS(const QString &file, const WMTS::Setup &setup) : _valid(false) QString("%1?service=WMTS&Version=1.0.0&request=GetCapabilities") .arg(setup.url()); - if (!QFileInfo(file).exists()) + if (!QFileInfo::exists(file)) if (!getCapabilities(capaUrl, file, setup.authorization())) return; if (!parseCapabilities(file, setup)) diff --git a/src/map/wmts.h b/src/map/wmts.h index 7cae56db..728e7cbe 100644 --- a/src/map/wmts.h +++ b/src/map/wmts.h @@ -21,12 +21,12 @@ public: public: Setup(const QString &url, const QString &layer, const QString &set, const QString &style, const QString &format, bool rest, - CoordinateSystem::AxisOrder axisOrder, + const CoordinateSystem &cs, const QList > &dimensions, - const Authorization &authorization = Authorization()) : - _url(url), _layer(layer), _set(set), _style(style), _format(format), - _rest(rest), _axisOrder(axisOrder), _dimensions(dimensions), - _authorization(authorization) {} + const Authorization &authorization = Authorization()) + : _url(url), _layer(layer), _set(set), _style(style), + _format(format), _rest(rest), _cs(cs), _dimensions(dimensions), + _authorization(authorization) {} const QString &url() const {return _url;} const Authorization &authorization() const {return _authorization;} @@ -35,7 +35,7 @@ public: const QString &style() const {return _style;} const QString &format() const {return _format;} bool rest() const {return _rest;} - CoordinateSystem::AxisOrder axisOrder() const {return _axisOrder;} + const CoordinateSystem &coordinateSystem() const {return _cs;} const QList > &dimensions() const {return _dimensions;} @@ -46,7 +46,7 @@ public: QString _style; QString _format; bool _rest; - CoordinateSystem::AxisOrder _axisOrder; + CoordinateSystem _cs; QList > _dimensions; Authorization _authorization; }; diff --git a/src/map/wmtsmap.cpp b/src/map/wmtsmap.cpp index a6eb93d4..38c06ba9 100644 --- a/src/map/wmtsmap.cpp +++ b/src/map/wmtsmap.cpp @@ -26,10 +26,10 @@ bool WMTSMap::loadWMTS() _tileLoader = TileLoader(wmts.tileUrl(), tilesDir(), _setup.authorization()); - if (_setup.axisOrder() == CoordinateSystem::Unknown) - _axisOrder = _projection.axisOrder(); + if (_setup.coordinateSystem().axisOrder() == CoordinateSystem::Unknown) + _cs = _projection.coordinateSystem(); else - _axisOrder = _setup.axisOrder(); + _cs = _setup.coordinateSystem(); updateTransform(); @@ -72,7 +72,7 @@ void WMTSMap::updateTransform() const WMTS::Zoom &z = _zooms.at(_zoom); ReferencePoint tl, br; - QPointF topLeft = (_axisOrder == CoordinateSystem::YX) + QPointF topLeft = (_cs.axisOrder() == CoordinateSystem::YX) ? QPointF(z.topLeft().y(), z.topLeft().x()) : z.topLeft(); qreal pixelSpan = sd2res(z.scaleDenominator()); diff --git a/src/map/wmtsmap.h b/src/map/wmtsmap.h index ff99c079..466bae00 100644 --- a/src/map/wmtsmap.h +++ b/src/map/wmtsmap.h @@ -60,8 +60,8 @@ private: QList _zooms; Projection _projection; Transform _transform; + CoordinateSystem _cs; int _zoom; - CoordinateSystem::AxisOrder _axisOrder; bool _block; bool _valid;