Libosmium  2.10.3
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 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 
36 #include <cassert>
37 #include <cstdlib>
38 #include <iterator>
39 #include <utility>
40 
42 #include <osmium/memory/item.hpp>
44 #include <osmium/osm/item_type.hpp>
45 #include <osmium/osm/object.hpp>
46 #include <osmium/osm/types.hpp>
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 
67  NodeRefList(itemtype) {
68  }
69 
70  }; // class OuterRing
71 
72 
76  class InnerRing : public NodeRefList {
77 
78  public:
79 
81 
83  NodeRefList(itemtype) {
84  }
85 
86  }; // class InnerRing
87 
88 
97  osmium::object_id_type area_id = std::abs(id) * 2;
99  ++area_id;
100  }
101  return id < 0 ? -area_id : area_id;
102  }
103 
111  return id / 2;
112  }
113 
117  class Area : public OSMObject {
118 
119  template <typename TDerived, typename T>
121 
122  Area() :
123  OSMObject(sizeof(Area), osmium::item_type::area) {
124  }
125 
126  public:
127 
129 
136  bool from_way() const noexcept {
137  return (positive_id() & 0x1) == 0;
138  }
139 
145  osmium::object_id_type orig_id() const noexcept {
146  return osmium::area_id_to_object_id(id());
147  }
148 
156  std::pair<size_t, size_t> num_rings() const {
157  std::pair<size_t, size_t> counter { 0, 0 };
158 
159  for (auto it = cbegin(); it != cend(); ++it) {
160  switch (it->type()) {
162  ++counter.first;
163  break;
165  ++counter.second;
166  break;
168  // ignore tags
169  break;
180  assert(false && "Children of Area can only be outer/inner_ring and tag_list.");
181  break;
182  }
183  }
184 
185  return counter;
186  }
187 
192  bool is_multipolygon() const {
193  return num_rings().first > 1;
194  }
195 
206  return it.cast<const osmium::InnerRing>();
207  }
208 
219  return std::next(it).cast<const osmium::InnerRing>();
220  }
221 
228  return subitems<const osmium::OuterRing>();
229  }
230 
239  return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
240  }
241 
242  }; // class Area
243 
244 
245 } // namespace osmium
246 
247 #endif // OSMIUM_OSM_AREA_HPP
osmium::object_id_type orig_id() const noexcept
Definition: area.hpp:145
Definition: osm_object_builder.hpp:376
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
bool from_way() const noexcept
Definition: area.hpp:136
type
Definition: entity_bits.hpp:63
OSMIUM_DEPRECATED osmium::memory::ItemIterator< const osmium::InnerRing > inner_ring_cbegin(const osmium::memory::ItemIterator< const osmium::OuterRing > &it) const
Definition: area.hpp:205
Definition: item_iterator.hpp:248
static constexpr osmium::item_type itemtype
Definition: area.hpp:64
Definition: item_iterator.hpp:132
unsigned char * next() noexcept
Definition: item.hpp:149
item_type
Definition: item_type.hpp:43
const_iterator cend() const
Definition: object.hpp:371
static constexpr osmium::item_type itemtype
Definition: area.hpp:80
Definition: area.hpp:117
Definition: area.hpp:76
const_iterator cbegin() const
Definition: object.hpp:367
osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept
Definition: area.hpp:96
OSMIUM_DEPRECATED osmium::memory::ItemIterator< const osmium::InnerRing > inner_ring_cend(const osmium::memory::ItemIterator< const osmium::OuterRing > &it) const
Definition: area.hpp:218
static constexpr osmium::item_type itemtype
Definition: area.hpp:128
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
bool is_multipolygon() const
Definition: area.hpp:192
osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept
Definition: area.hpp:110
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
OuterRing()
Definition: area.hpp:66
Definition: area.hpp:60
Area()
Definition: area.hpp:122
unsigned char * data() const noexcept
Definition: collection.hpp:91
const_iterator cbegin() const noexcept
Definition: item_iterator.hpp:276
osmium::memory::ItemIteratorRange< const osmium::OuterRing > outer_rings() const
Definition: area.hpp:227
Definition: node_ref_list.hpp:51
unsigned_object_id_type positive_id() const noexcept
Get absolute value of the ID of this object.
Definition: object.hpp:123
ItemIterator< T > cast() const noexcept
Definition: item_iterator.hpp:170
osmium::memory::ItemIteratorRange< const osmium::InnerRing > inner_rings(const osmium::OuterRing &outer) const
Definition: area.hpp:237
std::pair< size_t, size_t > num_rings() const
Definition: area.hpp:156
InnerRing()
Definition: area.hpp:82
Definition: object.hpp:63