libosmscout 1.1.1
Loading...
Searching...
No Matches
Tiling.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_UTIL_TILING_H
2#define OSMSCOUT_UTIL_TILING_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2014 Tim Teulings
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
24
25#include <iterator>
26
27#include <osmscout/GeoCoord.h>
28#include <osmscout/Pixel.h>
29
32
34
35namespace osmscout {
36
51
52 // forward declaration to avoid circular header includes
53 class GeoCoord;
54 class GeoBox;
55
66 class OSMSCOUT_API OSMTileId CLASS_FINAL
67 {
68 private:
69 uint32_t x;
70 uint32_t y;
71
72 public:
73 OSMTileId(uint32_t x,
74 uint32_t y);
75
76 uint32_t GetX() const
77 {
78 return x;
79 }
80
81 uint32_t GetY() const
82 {
83 return y;
84 }
85
86 GeoCoord GetTopLeftCoord(const Magnification& magnification) const;
87 GeoBox GetBoundingBox(const Magnification& magnification) const;
88
89 bool operator==(const OSMTileId& other) const
90 {
91 return x==other.x && y==other.y;
92 }
93
94 bool operator!=(const OSMTileId& other) const
95 {
96 return x!=other.x || y!=other.y;
97 }
98
99 std::string GetDisplayText() const
100 {
101 return std::to_string(x)+","+std::to_string(y);
102 }
103
104 static OSMTileId GetOSMTile(const Magnification& magnification,
105 const GeoCoord& coord);
106
107 };
108
110 {
111 public:
113 using value_type = OSMTileId;
114 using reference = OSMTileId&;
115 using pointer = OSMTileId*;
116 using iterator_category = std::input_iterator_tag;
117
118 private:
119 OSMTileId currentTile;
120 OSMTileId minTile;
121 OSMTileId maxTile;
122
123 public:
124 OSMTileIdBoxConstIterator(const OSMTileId& currentTile,
125 const OSMTileId& minTile,
126 const OSMTileId& maxTile)
127 : currentTile(currentTile),
128 minTile(minTile),
129 maxTile(maxTile)
130 {
131 // no code
132 }
133
135
137 {
138 if (currentTile.GetX()>=maxTile.GetX()) {
139 currentTile=OSMTileId(minTile.GetX(),currentTile.GetY()+1);
140 }
141 else {
142 currentTile=OSMTileId(currentTile.GetX()+1,currentTile.GetY());
143 }
144
145 return *this;
146 }
147
149 {
150 OSMTileIdBoxConstIterator tmp(*this);
151
152 operator++();
153
154 return tmp;
155 }
156
157 bool operator==(const OSMTileIdBoxConstIterator& other) const
158 {
159 return currentTile==other.currentTile;
160 }
161
162 bool operator!=(const OSMTileIdBoxConstIterator& other) const
163 {
164 return currentTile!=other.currentTile;
165 }
166
167 const OSMTileId& operator*() const
168 {
169 return currentTile;
170 }
171
172 OSMTileId operator->() const
173 {
174 return currentTile;
175 }
176 };
177
184 class OSMSCOUT_API OSMTileIdBox CLASS_FINAL
185 {
186 private:
187 OSMTileId minTile;
188 OSMTileId maxTile;
189
190 public:
192 const OSMTileId& b);
193
195 {
196 return minTile;
197 }
198
200 {
201 return maxTile;
202 }
203
204 uint32_t GetMinX() const
205 {
206 return minTile.GetX();
207 }
208
209 uint32_t GetMaxX() const
210 {
211 return maxTile.GetX();
212 }
213
214 uint32_t GetMinY() const
215 {
216 return minTile.GetY();
217 }
218
219 uint32_t GetMaxY() const
220 {
221 return maxTile.GetY();
222 }
223
224 uint32_t GetWidth() const
225 {
226 return maxTile.GetX()-minTile.GetX()+1;
227 }
228
229 uint32_t GetHeight() const
230 {
231 return maxTile.GetY()-minTile.GetY()+1;
232 }
233
234 uint32_t GetCount() const
235 {
236 return GetWidth()*GetHeight();
237 }
238
240 {
241 return OSMTileIdBoxConstIterator(minTile,
242 minTile,
243 maxTile);
244 }
245
247 {
248 return OSMTileIdBoxConstIterator(OSMTileId(minTile.GetX(),
249 maxTile.GetY()+1),
250 minTile,
251 maxTile);
252 }
253
254 GeoBox GetBoundingBox(const Magnification& magnification) const;
255
256 std::string GetDisplayText() const
257 {
258 return std::string("["+minTile.GetDisplayText()+" - "+maxTile.GetDisplayText()+"]");
259 }
260 };
261}
262
263#endif
#define CLASS_FINAL
Definition Compiler.h:26
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
uint32_t GetY() const
Definition Tiling.h:81
double GetWidth() const
Definition GeoBox.h:240
double GetHeight() const
Definition GeoBox.h:248
const GeoCoord coord
Definition RouteStateAgent.h:49
static OSMTileId GetOSMTile(const Magnification &magnification, const GeoCoord &coord)
uint32_t GetWidth() const
Definition Tiling.h:224
uint32_t GetCount() const
Definition Tiling.h:234
GeoBox GetBoundingBox(const Magnification &magnification) const
GeoCoord GetTopLeftCoord(const Magnification &magnification) const
OSMTileId GetMax() const
Definition Tiling.h:199
bool operator!=(const OSMTileId &other) const
Definition Tiling.h:94
OSMTileId GetMin() const
Definition Tiling.h:194
uint32_t GetMinY() const
Definition Tiling.h:214
uint32_t GetX() const
Definition Tiling.h:76
OSMTileIdBoxConstIterator end() const
Definition Tiling.h:246
OSMTileId(uint32_t x, uint32_t y)
OSMTileIdBox(const OSMTileId &a, const OSMTileId &b)
bool operator==(const OSMTileId &other) const
Definition Tiling.h:89
uint32_t x
Definition Pixel.h:48
uint32_t GetMinX() const
Definition Tiling.h:204
uint32_t y
Definition Pixel.h:49
uint32_t GetMaxY() const
Definition Tiling.h:219
uint32_t GetMaxX() const
Definition Tiling.h:209
OSMTileIdBoxConstIterator begin() const
Definition Tiling.h:239
uint32_t GetHeight() const
Definition Tiling.h:229
std::string GetDisplayText() const
Definition Tiling.h:99
OSMTileIdBoxConstIterator & operator++()
Definition Tiling.h:136
OSMTileId operator->() const
Definition Tiling.h:172
bool operator!=(const OSMTileIdBoxConstIterator &other) const
Definition Tiling.h:162
OSMTileIdBoxConstIterator(const OSMTileIdBoxConstIterator &other)=default
OSMTileId value_type
Definition Tiling.h:113
OSMTileIdBoxConstIterator(const OSMTileId &currentTile, const OSMTileId &minTile, const OSMTileId &maxTile)
Definition Tiling.h:124
OSMTileId & reference
Definition Tiling.h:114
std::input_iterator_tag iterator_category
Definition Tiling.h:116
bool operator==(const OSMTileIdBoxConstIterator &other) const
Definition Tiling.h:157
OSMTileId * pointer
Definition Tiling.h:115
OSMTileIdBoxConstIterator self_type
Definition Tiling.h:112
OSMTileIdBoxConstIterator operator++(int)
Definition Tiling.h:148
const OSMTileId & operator*() const
Definition Tiling.h:167
Definition Area.h:39