dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mercatorprojection.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>
29 #include "mercatorprojection.h"
30 
31 
32 namespace projections {
34  MinLatitude(-85.05112878), MaxLatitude(85.05112878),MinLongitude(-180),
35  MaxLongitude(180), tileSize(256, 256)
36 {
37 }
38 
39 Point MercatorProjection::FromLatLngToPixel(double lat, double lng, const int &zoom)
40 {
41  Point ret;// = Point.Empty;
42 
43  lat = bound(lat, MinLatitude, MaxLatitude);
44  lng = bound(lng, MinLongitude, MaxLongitude);
45 
46  double x = (lng + 180) / 360;
47  double sinLatitude = sin(lat * M_PI / 180);
48  double y = 0.5 - log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * M_PI);
49 
50  Size s = GetTileMatrixSizePixel(zoom);
51  qint64 mapSizeX = s.Width();
52  qint64 mapSizeY = s.Height();
53 
54  ret.SetX((qint64) round(bound(x * mapSizeX + 0.5, 0, mapSizeX - 1)));
55  ret.SetY((qint64) round(bound(y * mapSizeY + 0.5, 0, mapSizeY - 1)));
56 
57  return ret;
58 }
59 
67 internals::PointLatLng MercatorProjection::FromPixelToLatLng(const qint64 &x,const qint64 &y,const int &zoom)
68 {
69  internals::PointLatLng ret;// = internals::PointLatLng.Empty;
70 
71  Size s = GetTileMatrixSizePixel(zoom);
72  double mapSizeX = s.Width();
73  double mapSizeY = s.Height();
74 
75  //Calculate the percentage distance between top and bottom, and left and right
76  double xx = (bound(x, 0, mapSizeX - 1) / mapSizeX) - 0.5;
77  double yy = 0.5 - (bound(y, 0, mapSizeY - 1) / mapSizeY);
78 
79  ret.SetLat(90 - 360 * atan(exp(-yy * 2 * M_PI)) / M_PI);
80  ret.SetLng(360 * xx);
81 
82  return ret;
83 }
84 
86 {
87  return tileSize;
88 }
90 {
91  return 6378137;
92 }
94 {
95  return (1.0 / 298.257223563);
96 }
97 
104 {
105  int xy = (1 << zoom);
106  return Size(xy - 1, xy - 1);
107 }
108 
115 {
116  Q_UNUSED(zoom);
117  return Size(0, 0);
118 }
119 }
virtual double Flattening() const
virtual internals::PointLatLng FromPixelToLatLng(const qint64 &x, const qint64 &y, const int &zoom)
MercatorProjection::FromPixelToLatLng Referenced from top-left of globe, so the lat-lon (0...
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.
virtual Size GetTileMatrixMinXY(const int &zoom)
MercatorProjection::GetTileMatrixMinXY.
void SetLng(const double &value)
Definition: pointlatlng.h:80
virtual core::Point FromLatLngToPixel(double lat, double lng, int const &zoom)
virtual Size GetTileMatrixMaxXY(const int &zoom)
MercatorProjection::GetTileMatrixMaxXY.
x
Definition: OPPlots.m:100
virtual Size GetTileMatrixSizePixel(const int &zoom)
y
Definition: OPPlots.m:101