1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/map/osm.cpp

41 lines
949 B
C++
Raw Normal View History

2018-10-07 13:07:04 +02:00
#include <QtCore>
2018-09-24 22:49:10 +02:00
#include "common/wgs84.h"
2018-09-20 07:59:47 +02:00
#include "osm.h"
2018-09-24 22:49:10 +02:00
2018-09-20 07:59:47 +02:00
#define EPSILON 1e-6
2018-09-25 21:07:44 +02:00
QPointF OSM::ll2m(const Coordinates &c)
2018-09-20 07:59:47 +02:00
{
return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
}
2018-09-25 21:07:44 +02:00
Coordinates OSM::m2ll(const QPointF &p)
2018-09-20 07:59:47 +02:00
{
return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
}
2018-09-25 21:07:44 +02:00
QPoint OSM::mercator2tile(const QPointF &m, int zoom)
2018-09-20 07:59:47 +02:00
{
2018-10-07 13:07:04 +02:00
return QPoint(qFloor((m.x() + 180.0) / 360.0 * (1<<zoom)),
qFloor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<zoom)));
2018-09-20 07:59:47 +02:00
}
2018-09-25 21:07:44 +02:00
qreal OSM::zoom2scale(int zoom, int tileSize)
2018-09-20 07:59:47 +02:00
{
return (360.0/(qreal)((1<<zoom) * tileSize));
2018-09-20 07:59:47 +02:00
}
2018-09-25 21:07:44 +02:00
int OSM::scale2zoom(qreal scale, int tileSize)
2018-09-20 07:59:47 +02:00
{
return (int)(log2(360.0/(scale * (qreal)tileSize)) + EPSILON);
2018-09-20 07:59:47 +02:00
}
2018-09-24 22:49:10 +02:00
2018-09-25 21:07:44 +02:00
qreal OSM::resolution(const QPointF &p, int zoom, int tileSize)
2018-09-24 22:49:10 +02:00
{
qreal scale = zoom2scale(zoom, tileSize);
return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
* cos(2.0 * atan(exp(deg2rad(-p.y() * scale))) - M_PI/2));
}