From 619df591e2f6f9f26cff766b01bbec96fb4aa569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 22 Feb 2018 21:02:56 +0100 Subject: [PATCH] Added support for geographic2d "projected" WMTS maps --- src/map/gcs.h | 1 - src/map/projection.cpp | 6 ++++-- src/map/projection.h | 4 +++- src/map/wmts.cpp | 18 ++++++++++++++---- src/map/wmtsmap.cpp | 5 +++++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/map/gcs.h b/src/map/gcs.h index 4a3cf62a..02eb0427 100644 --- a/src/map/gcs.h +++ b/src/map/gcs.h @@ -25,7 +25,6 @@ public: Coordinates toWGS84(const Coordinates &c) const; Coordinates fromWGS84(const Coordinates &c) const; - static const GCS *gcs(int id); static const GCS *gcs(int geodeticDatum, int primeMeridian, int angularUnits); diff --git a/src/map/projection.cpp b/src/map/projection.cpp index 3905e4be..8a40a7fb 100644 --- a/src/map/projection.cpp +++ b/src/map/projection.cpp @@ -27,7 +27,7 @@ Projection::Method::Method(int id) } Projection::Projection(const GCS *gcs, const Method &method, const Setup &setup, - const LinearUnits &units) : _gcs(gcs), _units(units) + const LinearUnits &units) : _gcs(gcs), _units(units), _geographic(false) { const Ellipsoid *ellipsoid = _gcs->datum().ellipsoid(); @@ -68,7 +68,7 @@ Projection::Projection(const GCS *gcs, const Method &method, const Setup &setup, } } -Projection::Projection(const GCS *gcs) : _gcs(gcs) +Projection::Projection(const GCS *gcs) : _gcs(gcs), _geographic(true) { _ct = new LatLon(gcs->angularUnits()); _units = LinearUnits(9001); @@ -79,6 +79,7 @@ Projection::Projection(const Projection &p) _gcs = p._gcs; _units = p._units; _ct = p._ct->clone(); + _geographic = p._geographic; } Projection::~Projection() @@ -91,6 +92,7 @@ Projection &Projection::operator=(const Projection &p) _gcs = p._gcs; _units = p._units; _ct = p._ct->clone(); + _geographic = p._geographic; return *this; } diff --git a/src/map/projection.h b/src/map/projection.h index 6e5d5b3a..2a849ba6 100644 --- a/src/map/projection.h +++ b/src/map/projection.h @@ -68,7 +68,7 @@ public: int _id; }; - Projection() : _gcs(0), _ct(0) {} + Projection() : _gcs(0), _ct(0), _geographic(false) {} Projection(const Projection &p); Projection(const GCS *gcs, const Method &method, const Setup &setup, const LinearUnits &units); @@ -79,6 +79,7 @@ public: bool isNull() const {return (_gcs == 0 && _ct == 0 && _units.isNull());} bool isValid() const {return (_gcs == 0 || _ct == 0 || _units.isNull());} + bool isGeographic() const {return _geographic;} QPointF ll2xy(const Coordinates &c) const; Coordinates xy2ll(const QPointF &p) const; @@ -89,6 +90,7 @@ private: const GCS * _gcs; CT *_ct; LinearUnits _units; + bool _geographic; }; #ifndef QT_NO_DEBUG diff --git a/src/map/wmts.cpp b/src/map/wmts.cpp index 5ff76977..fc7dde58 100644 --- a/src/map/wmts.cpp +++ b/src/map/wmts.cpp @@ -15,7 +15,10 @@ bool WMTS::createProjection(const QString &crs) { QStringList list(crs.split(':')); QString authority, code; + bool res; + int epsg; const PCS *pcs; + const GCS *gcs; switch (list.size()) { case 2: @@ -32,12 +35,19 @@ bool WMTS::createProjection(const QString &crs) if (authority != "EPSG") return false; - if (!(pcs = PCS::pcs(code.toInt()))) + epsg = code.toInt(&res); + if (!res) return false; - _projection = Projection(pcs->gcs(), pcs->method(), pcs->setup(), - pcs->units()); - return true; + if ((pcs = PCS::pcs(epsg))) { + _projection = Projection(pcs->gcs(), pcs->method(), pcs->setup(), + pcs->units()); + return true; + } else if ((gcs = GCS::gcs(epsg))) { + _projection = Projection(gcs); + return true; + } else + return false; } void WMTS::tileMatrix(QXmlStreamReader &reader) diff --git a/src/map/wmtsmap.cpp b/src/map/wmtsmap.cpp index 1b030de0..84ab9365 100644 --- a/src/map/wmtsmap.cpp +++ b/src/map/wmtsmap.cpp @@ -1,5 +1,6 @@ #include #include "common/rectc.h" +#include "common/wgs84.h" #include "config.h" #include "transform.h" #include "wmts.h" @@ -47,6 +48,8 @@ void WMTSMap::updateTransform() ReferencePoint tl, br; qreal pixelSpan = sd2res(z.scaleDenominator); + if (_projection.isGeographic()) + pixelSpan /= deg2rad(WGS84_RADIUS); QPointF tileSpan(z.tile.width() * pixelSpan, z.tile.height() * pixelSpan); QPointF bottomRight(z.topLeft.x() + tileSpan.x() * z.matrix.width(), z.topLeft.y() - tileSpan.y() * z.matrix.height()); @@ -115,6 +118,8 @@ qreal WMTSMap::zoomFit(const QSize &size, const RectC &br) _projection.ll2xy(br.bottomRight())); QPointF sc(tbr.width() / size.width(), tbr.height() / size.height()); qreal resolution = qMax(qAbs(sc.x()), qAbs(sc.y())); + if (_projection.isGeographic()) + resolution *= deg2rad(WGS84_RADIUS); for (int i = 0; i < _zooms.size(); i++) { if (sd2res(_zooms.at(i).scaleDenominator) < resolution)