mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-07 12:05:14 +01:00
Fixed broken GeoTIFF Mercator coordinates transformation
This commit is contained in:
parent
dc25290637
commit
3def9f95b0
@ -3,13 +3,23 @@
|
|||||||
#include "common/coordinates.h"
|
#include "common/coordinates.h"
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "common/wgs84.h"
|
#include "common/wgs84.h"
|
||||||
#include "mercator.h"
|
|
||||||
#include "emptymap.h"
|
#include "emptymap.h"
|
||||||
|
|
||||||
|
|
||||||
#define SCALE_MIN 0.5
|
#define SCALE_MIN 0.5
|
||||||
#define SCALE_MAX 1.0E-6
|
#define SCALE_MAX 1.0E-6
|
||||||
|
|
||||||
|
static QPointF ll2m(const Coordinates &c)
|
||||||
|
{
|
||||||
|
return QPointF(c.lon(), rad2deg(log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0))));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Coordinates m2ll(const QPointF &p)
|
||||||
|
{
|
||||||
|
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
||||||
{
|
{
|
||||||
_scale = SCALE_MAX;
|
_scale = SCALE_MAX;
|
||||||
@ -25,8 +35,7 @@ qreal EmptyMap::zoomFit(const QSize &size, const RectC &br)
|
|||||||
if (!br.isValid())
|
if (!br.isValid())
|
||||||
_scale = SCALE_MAX;
|
_scale = SCALE_MAX;
|
||||||
else {
|
else {
|
||||||
QRectF tbr(Mercator().ll2xy(br.topLeft()),
|
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
|
||||||
Mercator().ll2xy(br.bottomRight()));
|
|
||||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||||
_scale = qMax(sc.x(), sc.y());
|
_scale = qMax(sc.x(), sc.y());
|
||||||
}
|
}
|
||||||
@ -73,12 +82,12 @@ void EmptyMap::draw(QPainter *painter, const QRectF &rect)
|
|||||||
|
|
||||||
QPointF EmptyMap::ll2xy(const Coordinates &c) const
|
QPointF EmptyMap::ll2xy(const Coordinates &c) const
|
||||||
{
|
{
|
||||||
QPointF m = Mercator().ll2xy(c);
|
QPointF m = ll2m(c);
|
||||||
return QPointF(m.x() / _scale, m.y() / -_scale);
|
return QPointF(m.x() / _scale, m.y() / -_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
Coordinates EmptyMap::xy2ll(const QPointF &p) const
|
Coordinates EmptyMap::xy2ll(const QPointF &p) const
|
||||||
{
|
{
|
||||||
QPointF m(p.x() * _scale, -p.y() * _scale);
|
QPointF m(p.x() * _scale, -p.y() * _scale);
|
||||||
return Mercator().xy2ll(m);
|
return m2ll(QPointF(p.x() * _scale, -p.y() * _scale));
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "common/coordinates.h"
|
||||||
|
#include "common/wgs84.h"
|
||||||
#include "mercator.h"
|
#include "mercator.h"
|
||||||
|
|
||||||
QPointF Mercator::ll2xy(const Coordinates &c) const
|
QPointF Mercator::ll2xy(const Coordinates &c) const
|
||||||
{
|
{
|
||||||
return QPointF(c.lon(), rad2deg(log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0))));
|
return QPointF(deg2rad(c.lon()) * WGS84_RADIUS,
|
||||||
|
log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0)) * WGS84_RADIUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Coordinates Mercator::xy2ll(const QPointF &p) const
|
Coordinates Mercator::xy2ll(const QPointF &p) const
|
||||||
{
|
{
|
||||||
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
|
return Coordinates(rad2deg(p.x() / WGS84_RADIUS),
|
||||||
|
rad2deg(2 * atan(exp(p.y() / WGS84_RADIUS)) - M_PI/2));
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "common/coordinates.h"
|
#include "common/coordinates.h"
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "common/wgs84.h"
|
#include "common/wgs84.h"
|
||||||
#include "mercator.h"
|
|
||||||
#include "downloader.h"
|
#include "downloader.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "onlinemap.h"
|
#include "onlinemap.h"
|
||||||
@ -12,6 +11,16 @@
|
|||||||
|
|
||||||
#define TILE_SIZE 256
|
#define TILE_SIZE 256
|
||||||
|
|
||||||
|
static QPointF ll2m(const Coordinates &c)
|
||||||
|
{
|
||||||
|
return QPointF(c.lon(), rad2deg(log(tan(M_PI/4.0 + deg2rad(c.lat())/2.0))));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Coordinates m2ll(const QPointF &p)
|
||||||
|
{
|
||||||
|
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
|
||||||
|
}
|
||||||
|
|
||||||
static QPoint mercator2tile(const QPointF &m, int z)
|
static QPoint mercator2tile(const QPointF &m, int z)
|
||||||
{
|
{
|
||||||
QPoint tile;
|
QPoint tile;
|
||||||
@ -183,8 +192,7 @@ qreal OnlineMap::zoomFit(const QSize &size, const RectC &br)
|
|||||||
if (!br.isValid())
|
if (!br.isValid())
|
||||||
_zoom = _zooms.max();
|
_zoom = _zooms.max();
|
||||||
else {
|
else {
|
||||||
QRectF tbr(Mercator().ll2xy(br.topLeft()),
|
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
|
||||||
Mercator().ll2xy(br.bottomRight()));
|
|
||||||
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
||||||
|
|
||||||
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
|
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
|
||||||
@ -252,13 +260,12 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect)
|
|||||||
QPointF OnlineMap::ll2xy(const Coordinates &c) const
|
QPointF OnlineMap::ll2xy(const Coordinates &c) const
|
||||||
{
|
{
|
||||||
qreal scale = zoom2scale(_zoom);
|
qreal scale = zoom2scale(_zoom);
|
||||||
QPointF m = Mercator().ll2xy(c);
|
QPointF m = ll2m(c);
|
||||||
return QPointF(m.x() / scale, m.y() / -scale);
|
return QPointF(m.x() / scale, m.y() / -scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
Coordinates OnlineMap::xy2ll(const QPointF &p) const
|
Coordinates OnlineMap::xy2ll(const QPointF &p) const
|
||||||
{
|
{
|
||||||
qreal scale = zoom2scale(_zoom);
|
qreal scale = zoom2scale(_zoom);
|
||||||
QPointF m(p.x() * scale, -p.y() * scale);
|
return m2ll(QPointF(p.x() * scale, -p.y() * scale));
|
||||||
return Mercator().xy2ll(m);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user