libosmscout  1.1.1
OSMTile.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_OSMTILE_H
2 #define OSMSCOUT_CLIENT_QT_OSMTILE_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2016 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
23 #include <cmath>
24 
25 #include <osmscout/util/GeoBox.h>
27 
28 namespace osmscout {
29 
42 static const double GRAD_TO_RAD = 2 * M_PI / 360;
43 
45 public:
46  static osmscout::GeoBox tileBoundingBox(uint32_t zoomLevel, uint32_t xtile, uint32_t ytile);
47  static osmscout::GeoCoord tileRelativeCoord(uint32_t zoomLevel, double x, double y);
48  static osmscout::GeoCoord tileVisualCenter(uint32_t zoomLevel, uint32_t xtile, uint32_t ytile);
49 
50  static inline double minLat(){
51  return -85.0511;
52  }
53  static inline double maxLat(){
54  return +85.0511;
55  }
56  static inline double minLon(){
57  return -180.0;
58  }
59  static inline double maxLon(){
60  return 180.0;
61  }
62  static inline int osmTileOriginalWidth(){
63  return 256;
64  }
65  static inline double tileDPI(){
66  return 96.0;
67  }
68 
69  static inline uint32_t lon2tilex(double lon, uint32_t z)
70  {
71  return (uint32_t)(floor((lon + 180.0) / 360.0 * (double)worldRes(z)));
72  }
73 
74  static inline uint32_t lat2tiley(double lat, uint32_t z)
75  {
76  return (uint32_t)(floor((1.0 - std::log( tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0 * (double)worldRes(z)));
77  }
78 
79  static inline double tilex2lon(uint32_t x, uint32_t z)
80  {
81  return (double)x / (double)worldRes(z) * 360.0 - 180;
82  }
83 
84  static inline double tiley2lat(uint32_t y, uint32_t z)
85  {
86  double n = M_PI - 2.0 * M_PI * y / (double)worldRes(z);
87  return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
88  }
89 
93  static inline uint32_t worldRes(uint32_t level){
94  // equivalent of pow(2.0, z)
95  return 1 << level;
96  }
97 };
98 
99 }
100 
101 #endif /* OSMSCOUT_CLIENT_QT_OSMTILE_H */
OSMSCOUT_API Log log
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
static uint32_t lat2tiley(double lat, uint32_t z)
Definition: OSMTile.h:74
static double minLat()
Definition: OSMTile.h:50
Definition: OSMTile.h:44
static double minLon()
Definition: OSMTile.h:56
static double maxLat()
Definition: OSMTile.h:53
static const double GRAD_TO_RAD
Definition: OSMTile.h:42
Definition: Area.h:38
static uint32_t lon2tilex(double lon, uint32_t z)
Definition: OSMTile.h:69
static int osmTileOriginalWidth()
Definition: OSMTile.h:62
static uint32_t worldRes(uint32_t level)
Definition: OSMTile.h:93
static double tiley2lat(uint32_t y, uint32_t z)
Definition: OSMTile.h:84
static double maxLon()
Definition: OSMTile.h:59
static double tileDPI()
Definition: OSMTile.h:65
static double tilex2lon(uint32_t x, uint32_t z)
Definition: OSMTile.h:79