Libosmium  2.19.0
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-2023 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>
44 
45 #include <cassert>
46 #include <cstdlib>
47 #include <iterator>
48 #include <utility>
49 
50 namespace osmium {
51 
52  namespace builder {
53  template <typename TDerived, typename T>
54  class OSMObjectBuilder;
55  } // namespace builder
56 
60  class OuterRing : public NodeRefList {
61 
62  public:
63 
65 
66  constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
67  return t == itemtype;
68  }
69 
72  }
73 
74  }; // class OuterRing
75 
76 
80  class InnerRing : public NodeRefList {
81 
82  public:
83 
85 
86  constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
87  return t == itemtype;
88  }
89 
92  }
93 
94  }; // class InnerRing
95 
96 
105  osmium::object_id_type area_id = std::abs(id) * 2;
107  ++area_id;
108  }
109  return id < 0 ? -area_id : area_id;
110  }
111 
119  return id / 2;
120  }
121 
125  class Area : public OSMObject {
126 
127  template <typename TDerived, typename T>
129 
130  Area() :
131  OSMObject(sizeof(Area), osmium::item_type::area) {
132  }
133 
134  public:
135 
137 
138  constexpr static bool is_compatible_to(osmium::item_type t) noexcept {
139  return t == itemtype;
140  }
141 
148  bool from_way() const noexcept {
149  return (positive_id() & 0x1U) == 0;
150  }
151 
157  osmium::object_id_type orig_id() const noexcept {
158  return osmium::area_id_to_object_id(id());
159  }
160 
168  std::pair<size_t, size_t> num_rings() const {
169  std::pair<size_t, size_t> counter{0, 0};
170 
171  for (const auto& item : *this) {
172  switch (item.type()) {
174  ++counter.first;
175  break;
177  ++counter.second;
178  break;
180  // ignore tags
181  break;
192  assert(false && "Children of Area can only be outer/inner_ring and tag_list.");
193  break;
194  }
195  }
196 
197  return counter;
198  }
199 
204  bool is_multipolygon() const {
205  return num_rings().first > 1;
206  }
207 
214  return subitems<const osmium::OuterRing>();
215  }
216 
224  const osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_range{outer.data(), next()};
225  return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
226  }
227 
233  osmium::Box envelope() const noexcept {
234  osmium::Box box;
235  for (const auto& ring : outer_rings()) {
236  box.extend(ring.envelope());
237  }
238  return box;
239  }
240 
241  }; // class Area
242 
243 
244 } // namespace osmium
245 
246 #endif // OSMIUM_OSM_AREA_HPP
Definition: area.hpp:125
std::pair< size_t, size_t > num_rings() const
Definition: area.hpp:168
osmium::memory::ItemIteratorRange< const osmium::OuterRing > outer_rings() const
Definition: area.hpp:213
osmium::memory::ItemIteratorRange< const osmium::InnerRing > inner_rings(const osmium::OuterRing &outer) const
Definition: area.hpp:223
bool from_way() const noexcept
Definition: area.hpp:148
static constexpr osmium::item_type itemtype
Definition: area.hpp:136
Area()
Definition: area.hpp:130
constexpr static bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:138
osmium::Box envelope() const noexcept
Definition: area.hpp:233
bool is_multipolygon() const
Definition: area.hpp:204
osmium::object_id_type orig_id() const noexcept
Definition: area.hpp:157
Definition: area.hpp:80
constexpr static bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:86
static constexpr osmium::item_type itemtype
Definition: area.hpp:84
InnerRing()
Definition: area.hpp:90
Definition: node_ref_list.hpp:52
Definition: object.hpp:64
unsigned_object_id_type positive_id() const noexcept
Get absolute value of the ID of this object.
Definition: object.hpp:123
Definition: area.hpp:60
static constexpr osmium::item_type itemtype
Definition: area.hpp:64
OuterRing()
Definition: area.hpp:70
constexpr static bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:66
osmium::memory::Item & item() const noexcept
Definition: builder.hpp:93
Definition: osm_object_builder.hpp:401
unsigned char * data() const noexcept
Definition: collection.hpp:91
Definition: item_iterator.hpp:175
const_iterator cbegin() const noexcept
Definition: item_iterator.hpp:203
item_type type() const noexcept
Definition: item.hpp:171
unsigned char * next() noexcept
Definition: item.hpp:155
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept
Definition: area.hpp:104
item_type
Definition: item_type.hpp:45
@ relation_member_list_with_full_members
osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept
Definition: area.hpp:118