libosmscout 1.1.1
Loading...
Searching...
No Matches
TileId.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_TILEID_H
2#define OSMSCOUT_TILEID_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2016 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
23#include <memory>
24#include <tuple>
25
27
28#include <osmscout/Pixel.h>
29
32
33namespace osmscout {
34
46 {
47 private:
48 uint32_t x;
49 uint32_t y;
50
51 public:
52 TileId(uint32_t x,
53 uint32_t y);
54
58 uint32_t GetX() const
59 {
60 return x;
61 }
62
66 uint32_t GetY() const
67 {
68 return y;
69 }
70
71 Pixel AsPixel() const
72 {
73 return {x,y};
74 }
75
76 std::string GetDisplayText() const;
77
81 bool operator==(const TileId& other) const
82 {
83 return y==other.y &&
84 x==other.x;
85 }
86
90 bool operator!=(const TileId& other) const
91 {
92 return y!=other.y ||
93 x!=other.x;
94 }
95
100 bool operator<(const TileId& other) const
101 {
102 return std::tie(y, x) < std::tie(other.y, other.x);
103 }
104
105 GeoCoord GetTopLeftCoord(const Magnification& magnification) const;
106 GeoBox GetBoundingBox(const MagnificationLevel& level) const;
107 GeoBox GetBoundingBox(const Magnification& magnification) const;
108
109 static TileId GetTile(const Magnification& magnification,
110 const GeoCoord& coord);
111
112 static TileId GetTile(const MagnificationLevel& level,
113 const GeoCoord& coord);
114 };
115
120 {
121 std::size_t operator()(const TileId& id) const noexcept
122 {
123 auto h1 = static_cast<size_t>(id.GetX());
124 auto h2 = static_cast<size_t>(id.GetY());
125 return h1 ^ (h2 << 16u);
126 }
127 };
128
130 {
131 private:
132 uint32_t level;
133 TileId id;
134
135 public:
136 TileKey(const Magnification& magnification,
137 const TileId& id);
138
139 uint32_t GetLevel() const
140 {
141 return level;
142 }
143
144 TileId GetId() const
145 {
146 return id;
147 }
148
152 GeoBox GetBoundingBox() const;
153
154 std::string GetDisplayText() const;
155
157
158 bool operator==(const TileKey& other) const;
159 bool operator!=(const TileKey& other) const;
160 bool operator<(const TileKey& other) const;
161 };
162
163 class OSMSCOUT_API TileIdBoxConstIterator CLASS_FINAL
164 {
165 public:
168 using reference = const TileId&;
170 using iterator_category = std::input_iterator_tag;
171
172 private:
173 TileId currentTile;
174 TileId minTile;
175 TileId maxTile;
176
177 public:
178 TileIdBoxConstIterator(const TileId& currentTile,
179 const TileId& minTile,
180 const TileId& maxTile)
181 : currentTile(currentTile),
182 minTile(minTile),
183 maxTile(maxTile)
184 {
185 // no code
186 }
187
189
191 {
192 if (currentTile.GetX()>=maxTile.GetX()) {
193 currentTile=TileId(minTile.GetX(),
194 currentTile.GetY()+1);
195 }
196 else {
197 currentTile=TileId(currentTile.GetX()+1,
198 currentTile.GetY());
199 }
200
201 return *this;
202 }
203
205 {
206 TileIdBoxConstIterator tmp(*this);
207
208 operator++();
209
210 return tmp;
211 }
212
213 bool operator==(const TileIdBoxConstIterator& other) const
214 {
215 return currentTile==other.currentTile;
216 }
217
218 bool operator!=(const TileIdBoxConstIterator& other) const
219 {
220 return currentTile!=other.currentTile;
221 }
222
223 const TileId& operator*() const
224 {
225 return currentTile;
226 }
227
229 {
230 return currentTile;
231 }
232 };
233
240 class OSMSCOUT_API TileIdBox CLASS_FINAL
241 {
242 private:
243 TileId minTile;
244 TileId maxTile;
245
246 public:
248 const TileId& b);
249
250 TileIdBox(const Magnification& magnification,
251 const GeoBox& boundingBox)
252 : TileIdBox(TileId::GetTile(magnification,
253 boundingBox.GetMinCoord()),
254 TileId::GetTile(magnification,
255 boundingBox.GetMaxCoord()))
256 {
257 }
258
260 {
261 return minTile;
262 }
263
265 {
266 return maxTile;
267 }
268
269
271 {
272 return {(minTile.GetX()+maxTile.GetX())/2,
273 (minTile.GetY()+maxTile.GetY())/2};
274 }
275
276 uint32_t GetMinX() const
277 {
278 return minTile.GetX();
279 }
280
281 uint32_t GetMaxX() const
282 {
283 return maxTile.GetX();
284 }
285
286 uint32_t GetMinY() const
287 {
288 return minTile.GetY();
289 }
290
291 uint32_t GetMaxY() const
292 {
293 return maxTile.GetY();
294 }
295
296 uint32_t GetWidth() const
297 {
298 return maxTile.GetX()-minTile.GetX()+1;
299 }
300
301 uint32_t GetHeight() const
302 {
303 return maxTile.GetY()-minTile.GetY()+1;
304 }
305
306 uint32_t GetCount() const
307 {
308 return GetWidth()*GetHeight();
309 }
310
312 {
313 return TileIdBoxConstIterator(minTile,
314 minTile,
315 maxTile);
316 }
317
319 {
320 return TileIdBoxConstIterator(TileId(minTile.GetX(),
321 maxTile.GetY()+1),
322 minTile,
323 maxTile);
324 }
325
326 bool operator==(const TileIdBox& other) const
327 {
328 return minTile==other.minTile &&
329 maxTile==other.maxTile;
330 }
331
332 GeoBox GetBoundingBox(const Magnification& magnification) const;
333
334 TileIdBox Include(const TileId& tileId) const;
335 TileIdBox Include(const TileIdBox& other) const;
336 TileIdBox Intersection(const TileIdBox& other) const;
337
338 bool Intersects(const TileIdBox& other) const;
339
340 std::string GetDisplayText() const
341 {
342 return std::string("["+minTile.GetDisplayText()+" - "+maxTile.GetDisplayText()+"]");
343 }
344 };
345
349}
350
351#endif
#define CLASS_FINAL
Definition Compiler.h:26
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
double GetWidth() const
Definition GeoBox.h:240
double GetHeight() const
Definition GeoBox.h:248
bool operator!=(const TileIdBoxConstIterator &other) const
Definition TileId.h:218
TileIdBoxConstIterator operator++(int)
Definition TileId.h:204
uint32_t GetWidth() const
Definition TileId.h:296
GeoCoord GetMaxCoord() const
Definition GeoBox.h:198
GeoCoord GetMinCoord() const
Definition GeoBox.h:190
TypeInfoRef value_type
Definition TypeInfoSet.h:36
bool operator==(const TileIdBoxConstIterator &other) const
Definition TileId.h:213
uint32_t GetCount() const
Definition TileId.h:306
TileIdBox(const TileId &a, const TileId &b)
TileIdBoxConstIterator(const TileIdBoxConstIterator &other)=default
GeoBox GetBoundingBox(const Magnification &magnification) const
TypeInfoRef pointer
Definition TypeInfoSet.h:38
TileIdBox Include(const TileId &tileId) const
bool Intersects(const TileIdBox &other) const
TileIdBoxConstIterator begin() const
Definition TileId.h:311
TypeInfoSetConstIterator & operator++()
Definition TypeInfoSet.h:59
TileIdBoxConstIterator end() const
Definition TileId.h:318
TileId GetMax() const
Definition TileId.h:264
TileIdBox Include(const TileIdBox &other) const
uint32_t GetMinY() const
Definition TileId.h:286
TileIdBoxConstIterator & operator++()
Definition TileId.h:190
std::input_iterator_tag iterator_category
Definition TypeInfoSet.h:39
const TypeInfoRef & reference
Definition TypeInfoSet.h:37
TileId GetMin() const
Definition TileId.h:259
Pixel GetTile(const GeoCoord &coord) const
TypeInfoSetConstIterator self_type
Definition TypeInfoSet.h:35
TileId GetCenter() const
Definition TileId.h:270
TileIdBox Intersection(const TileIdBox &other) const
uint32_t GetMinX() const
Definition TileId.h:276
uint32_t GetMaxY() const
Definition TileId.h:291
const TileId & operator*() const
Definition TileId.h:223
TileIdBoxConstIterator(const TileId &currentTile, const TileId &minTile, const TileId &maxTile)
Definition TileId.h:178
bool operator==(const TileIdBox &other) const
Definition TileId.h:326
uint32_t GetMaxX() const
Definition TileId.h:281
TileIdBox(const Magnification &magnification, const GeoBox &boundingBox)
Definition TileId.h:250
uint32_t GetHeight() const
Definition TileId.h:301
std::string GetDisplayText() const
Definition TileId.h:340
TileId operator->() const
Definition TileId.h:228
Definition TileId.h:46
uint32_t GetY() const
Definition TileId.h:66
static TileId GetTile(const Magnification &magnification, const GeoCoord &coord)
bool operator==(const TileId &other) const
Definition TileId.h:81
Pixel AsPixel() const
Definition TileId.h:71
GeoBox GetBoundingBox(const Magnification &magnification) const
GeoBox GetBoundingBox(const MagnificationLevel &level) const
GeoCoord GetTopLeftCoord(const Magnification &magnification) const
std::string GetDisplayText() const
TileId(uint32_t x, uint32_t y)
bool operator<(const TileId &other) const
Definition TileId.h:100
uint32_t GetX() const
Definition TileId.h:58
bool operator!=(const TileId &other) const
Definition TileId.h:90
static TileId GetTile(const MagnificationLevel &level, const GeoCoord &coord)
std::string GetDisplayText() const
bool operator!=(const TileKey &other) const
TileId GetId() const
Definition TileId.h:144
GeoBox GetBoundingBox() const
TileKey(const Magnification &magnification, const TileId &id)
TileKey GetParent() const
uint32_t GetLevel() const
Definition TileId.h:139
bool operator<(const TileKey &other) const
bool operator==(const TileKey &other) const
Definition Area.h:39
Definition TileId.h:120
std::size_t operator()(const TileId &id) const noexcept
Definition TileId.h:121