1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/map/osm.cpp

40 lines
943 B
C++
Raw Normal View History

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
QPointF osm::ll2m(const Coordinates &c)
{
return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
}
Coordinates osm::m2ll(const QPointF &p)
{
return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
}
2018-09-24 22:49:10 +02:00
QPoint osm::mercator2tile(const QPointF &m, int zoom)
2018-09-20 07:59:47 +02:00
{
2018-09-24 22:49:10 +02:00
return QPoint((int)(floor((m.x() + 180.0) / 360.0 * (1<<zoom))),
(int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<zoom))));
2018-09-20 07:59:47 +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
}
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
qreal osm::resolution(const QPointF &p, int zoom, int tileSize)
{
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));
}