Libosmium  2.15.1
Fast and flexible C++ library for working with OpenStreetMap data
area.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_OSM_AREA_HPP
2 #define OSMIUM_OSM_AREA_HPP
3 
4 /*
5 
6 This file is part of Osmium (https://osmcode.org/libosmium).
7 
8 Copyright 2013-2019 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
37 #include <osmium/memory/item.hpp>
39 #include <osmium/osm/box.hpp>
40 #include <osmium/osm/item_type.hpp>
42 #include <osmium/osm/object.hpp>
43 #include <osmium/osm/types.hpp>
45 
46 #include <cassert>
47 #include <cstdlib>
48 #include <iterator>
49 #include <utility>
50 
51 namespace osmium {
52 
53  namespace builder {
54  template <typename TDerived, typename T>
55  class OSMObjectBuilder;
56  } // namespace builder
57 
61  class OuterRing : public NodeRefList {
62 
63  public:
64 
65  static constexpr osmium::item_type itemtype = osmium::item_type::outer_ring;
66 
67  constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
68  return t == itemtype;
69  }
70 
72  NodeRefList(itemtype) {
73  }
74 
75  }; // class OuterRing
76 
77 
81  class InnerRing : public NodeRefList {
82 
83  public:
84 
85  static constexpr osmium::item_type itemtype = osmium::item_type::inner_ring;
86 
87  constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
88  return t == itemtype;
89  }
90 
92  NodeRefList(itemtype) {
93  }
94 
95  }; // class InnerRing
96 
97 
106  osmium::object_id_type area_id = std::abs(id) * 2;
108  ++area_id;
109  }
110  return id < 0 ? -area_id : area_id;
111  }
112 
120  return id / 2;
121  }
122 
126  class Area : public OSMObject {
127 
128  template <typename TDerived, typename T>
130 
131  Area() :
132  OSMObject(sizeof(Area), osmium::item_type::area) {
133  }
134 
135  public:
136 
137  static constexpr osmium::item_type itemtype = osmium::item_type::area;
138 
139  constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
140  return t == itemtype;
141  }
142 
149  bool from_way() const noexcept {
150  return (positive_id() & 0x1u) == 0;
151  }
152 
158  osmium::object_id_type orig_id() const noexcept {
159  return osmium::area_id_to_object_id(id());
160  }
161 
169  std::pair<size_t, size_t> num_rings() const {
170  std::pair<size_t, size_t> counter{0, 0};
171 
172  for (const auto& item : *this) {
173  switch (item.type()) {
175  ++counter.first;
176  break;
178  ++counter.second;
179  break;
181  // ignore tags
182  break;
193  assert(false && "Children of Area can only be outer/inner_ring and tag_list.");
194  break;
195  }
196  }
197 
198  return counter;
199  }
200 
205  bool is_multipolygon() const {
206  return num_rings().first > 1;
207  }
208 
219  return it.cast<const osmium::InnerRing>();
220  }
221 
232  return std::next(it).cast<const osmium::InnerRing>();
233  }
234 
241  return subitems<const osmium::OuterRing>();
242  }
243 
251  osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_range{outer.data(), next()};
252  return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
253  }
254 
260  osmium::Box envelope() const noexcept {
261  osmium::Box box;
262  for (const auto& ring : outer_rings()) {
263  box.extend(ring.envelope());
264  }
265  return box;
266  }
267 
268  }; // class Area
269 
270 
271 } // namespace osmium
272 
273 #endif // OSMIUM_OSM_AREA_HPP
osmium::object_id_type orig_id() const noexcept
Definition: area.hpp:158
Definition: osm_object_builder.hpp:402
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:139
bool from_way() const noexcept
Definition: area.hpp:149
type
Definition: entity_bits.hpp:63
Definition: item_iterator.hpp:175
std::pair< size_t, size_t > num_rings() const
Definition: area.hpp:169
Definition: item_iterator.hpp:59
item_type
Definition: item_type.hpp:43
bool is_multipolygon() const
Definition: area.hpp:205
Box & extend(const Location &location) noexcept
Definition: box.hpp:100
Definition: area.hpp:126
Definition: area.hpp:81
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:87
OSMIUM_DEPRECATED osmium::memory::ItemIterator< const osmium::InnerRing > inner_ring_cend(const osmium::memory::ItemIterator< const osmium::OuterRing > &it) const
Definition: area.hpp:231
osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept
Definition: area.hpp:105
OSMIUM_DEPRECATED osmium::memory::ItemIterator< const osmium::InnerRing > inner_ring_cbegin(const osmium::memory::ItemIterator< const osmium::OuterRing > &it) const
Definition: area.hpp:218
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
osmium::memory::ItemIteratorRange< const osmium::InnerRing > inner_rings(const osmium::OuterRing &outer) const
Definition: area.hpp:250
osmium::Box envelope() const noexcept
Definition: area.hpp:260
osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept
Definition: area.hpp:119
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
OuterRing()
Definition: area.hpp:71
Definition: area.hpp:61
Area()
Definition: area.hpp:131
osmium::memory::ItemIteratorRange< const osmium::OuterRing > outer_rings() const
Definition: area.hpp:240
Definition: box.hpp:49
const_iterator cbegin() const noexcept
Definition: item_iterator.hpp:203
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:67
Definition: node_ref_list.hpp:52
data_type data() noexcept
Definition: item_iterator.hpp:135
ItemIterator< T > cast() const noexcept
Definition: item_iterator.hpp:97
item_type type() const noexcept
Definition: item.hpp:171
InnerRing()
Definition: area.hpp:91
Definition: object.hpp:64
osmium::memory::Item & item() const
Definition: builder.hpp:90