Root/
1 | /* |
2 | * Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #include "projection.h" |
21 | |
22 | #include <cmath> |
23 | |
24 | qreal Projection::lon2rawx(qreal lon) |
25 | { |
26 | return (lon + 180.0) / 360.0; |
27 | } |
28 | |
29 | qreal Projection::lat2rawy(qreal lat) |
30 | { |
31 | return (1.0 - log(tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0; |
32 | } |
33 | |
34 | qreal Projection::lon2tilex(qreal lon, int z) |
35 | { |
36 | return (lon + 180.0) / 360.0 * (1 << z); |
37 | } |
38 | |
39 | qreal Projection::lat2tiley(qreal lat, int z) |
40 | { |
41 | return (1.0 - log(tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0 * (1 << z); |
42 | } |
43 | |
44 | qreal Projection::tilex2lon(qreal x, int z) |
45 | { |
46 | return x / (1 << z) * 360.0 - 180; |
47 | } |
48 | |
49 | qreal Projection::tiley2lat(qreal y, int z) |
50 | { |
51 | qreal n = M_PI - 2.0 * M_PI * y / (1 << z); |
52 | return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); |
53 | } |
54 | |
55 | QString Projection::geo2string(const QPointF &geo) |
56 | { |
57 | QString lat = geo.y() > 0 ? QString("N %1").arg(geo.y()) : QString("S %1").arg(-geo.y()); |
58 | QString lon = geo.x() > 0 ? QString("E %1").arg(geo.x()) : QString("W %1").arg(-geo.x()); |
59 | return lat+" "+lon; |
60 | } |
61 | |
62 |
Branches:
master