dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mercatorprojectionyandex.cpp
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 #define _USE_MATH_DEFINES
28 #include <cmath>
30 
31 namespace projections {
32 MercatorProjectionYandex::MercatorProjectionYandex():MinLatitude(-85.05112878), MaxLatitude(85.05112878),MinLongitude(-180),
33 MaxLongitude(180), RAD_DEG(180 / M_PI),DEG_RAD(M_PI / 180),MathPiDiv4(M_PI / 4),tileSize(256, 256)
34 {
35 }
36 Point MercatorProjectionYandex::FromLatLngToPixel(double lat, double lng, const int &zoom)
37 {
38  lat = bound(lat, MinLatitude, MaxLatitude);
39  lng = bound(lng, MinLongitude, MaxLongitude);
40 
41  double rLon = lng * DEG_RAD; // Math.PI / 180;
42  double rLat = lat * DEG_RAD; // Math.PI / 180;
43 
44  double a = 6378137;
45  double k = 0.0818191908426;
46 
47  double z = tan(MathPiDiv4 + rLat / 2) / pow((tan(MathPiDiv4 + asin(k * sin(rLat)) / 2)), k);
48  double z1 = pow(2, 23 - zoom);
49 
50  double DX = ((20037508.342789 + a * rLon) * 53.5865938 / z1);
51  double DY = ((20037508.342789 - a * log(z)) * 53.5865938 / z1);
52 
53  Point ret;// = Point.Empty;
54  ret.SetX((qint64) round(DX));
55  ret.SetY((qint64) round(DY));
56 
57  return ret;
58 
59 }
60 internals::PointLatLng MercatorProjectionYandex::FromPixelToLatLng(const qint64 &x,const qint64 &y,const int &zoom)
61 {
62  double a = 6378137;
63  double c1 = 0.00335655146887969;
64  double c2 = 0.00000657187271079536;
65  double c3 = 0.00000001764564338702;
66  double c4 = 0.00000000005328478445;
67  double z1 = (23 - zoom);
68  double mercX = (x * pow(2, z1)) / 53.5865938 - 20037508.342789;
69  double mercY = 20037508.342789 - (y *pow(2, z1)) / 53.5865938;
70 
71  double g = M_PI /2 - 2 *atan(1 / exp(mercY /a));
72  double z = g + c1 * sin(2 * g) + c2 * sin(4 * g) + c3 * sin(6 * g) + c4 * sin(8 * g);
73 
74  internals::PointLatLng ret;// = internals::PointLatLng.Empty;
75  ret.SetLat(z * RAD_DEG);
76  ret.SetLng (mercX / a * RAD_DEG);
77 
78  return ret;
79 }
81 {
82  return tileSize;
83 }
85 {
86  return 6356752.3142;
87 }
89 {
90  return (1.0 / 298.257223563);
91 }
93 {
94  int xy = (1 << zoom);
95  return Size(xy - 1, xy - 1);
96 }
97 
99 {
100  Q_UNUSED(zoom);
101  return Size(0, 0);
102 }
103 }
virtual internals::PointLatLng FromPixelToLatLng(const qint64 &x, const qint64 &y, const int &zoom)
void SetLat(const double &value)
Definition: pointlatlng.h:69
double bound(double const &n, double const &minValue, double const &maxValue) const
PureProjection::bound Bounds the value at an upper and lower threshold.
void SetLng(const double &value)
Definition: pointlatlng.h:80
end a
Definition: OPPlots.m:98
virtual core::Point FromLatLngToPixel(double lat, double lng, int const &zoom)
z
Definition: OPPlots.m:102
x
Definition: OPPlots.m:100
virtual Size GetTileMatrixMinXY(const int &zoom)
virtual Size GetTileMatrixMaxXY(const int &zoom)
y
Definition: OPPlots.m:101