1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-31 09:05:14 +01:00

Added support for geographic2d "projected" WMTS maps

This commit is contained in:
Martin Tůma 2018-02-22 21:02:56 +01:00
parent 10aa7d3945
commit 619df591e2
5 changed files with 26 additions and 8 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -1,5 +1,6 @@
#include <QPainter>
#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)