Libosmium  2.7.2
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 (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 <utility>
39 
41 #include <osmium/memory/item.hpp>
42 #include <osmium/osm/item_type.hpp>
43 #include <osmium/osm/object.hpp>
44 #include <osmium/osm/types.hpp>
47 
48 namespace osmium {
49 
50  namespace builder {
51  template <class T> class ObjectBuilder;
52  } // namespace builder
53 
57  class OuterRing : public NodeRefList {
58 
59  public:
60 
61  static constexpr osmium::item_type itemtype = osmium::item_type::outer_ring;
62 
64  NodeRefList(itemtype) {
65  }
66 
67  }; // class OuterRing
68 
69 
73  class InnerRing : public NodeRefList {
74 
75  public:
76 
77  static constexpr osmium::item_type itemtype = osmium::item_type::inner_ring;
78 
80  NodeRefList(itemtype) {
81  }
82 
83  }; // class InnerRing
84 
85 
94  osmium::object_id_type area_id = std::abs(id) * 2;
96  ++area_id;
97  }
98  return id < 0 ? -area_id : area_id;
99  }
100 
108  return id / 2;
109  }
110 
114  class Area : public OSMObject {
115 
117 
118  Area() :
119  OSMObject(sizeof(Area), osmium::item_type::area) {
120  }
121 
122  public:
123 
124  static constexpr osmium::item_type itemtype = osmium::item_type::area;
125 
130  bool from_way() const noexcept {
131  return (positive_id() & 0x1) == 0;
132  }
133 
137  osmium::object_id_type orig_id() const noexcept {
138  return osmium::area_id_to_object_id(id());
139  }
140 
146  std::pair<size_t, size_t> num_rings() const {
147  std::pair<size_t, size_t> counter { 0, 0 };
148 
149  for (auto it = cbegin(); it != cend(); ++it) {
150  switch (it->type()) {
152  ++counter.first;
153  break;
155  ++counter.second;
156  break;
158  // ignore tags
159  break;
170  assert(false && "Children of Area can only be outer/inner_ring and tag_list.");
171  break;
172  }
173  }
174 
175  return counter;
176  }
177 
182  bool is_multipolygon() const {
183  return num_rings().first > 1;
184  }
185 
196  return it.cast<const osmium::InnerRing>();
197  }
198 
209  return std::next(it).cast<const osmium::InnerRing>();
210  }
211 
218  return subitems<const osmium::OuterRing>();
219  }
220 
228  osmium::memory::ItemIteratorRange<const osmium::OuterRing> outer_range{outer.data(), next()};
229  return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
230  }
231 
232  }; // class Area
233 
234 
235 } // namespace osmium
236 
237 #endif // OSMIUM_OSM_AREA_HPP
osmium::object_id_type orig_id() const noexcept
Definition: area.hpp:137
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
bool from_way() const noexcept
Definition: area.hpp:130
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:195
Definition: item_iterator.hpp:235
Definition: item_iterator.hpp:119
item_type
Definition: item_type.hpp:43
Definition: area.hpp:114
Definition: area.hpp:73
osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept
Definition: area.hpp:93
OSMIUM_DEPRECATED osmium::memory::ItemIterator< const osmium::InnerRing > inner_ring_cend(const osmium::memory::ItemIterator< const osmium::OuterRing > &it) const
Definition: area.hpp:208
Namespace for everything in the Osmium library.
Definition: assembler.hpp:66
bool is_multipolygon() const
Definition: area.hpp:182
osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept
Definition: area.hpp:107
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
OuterRing()
Definition: area.hpp:63
Definition: area.hpp:57
Definition: builder.hpp:186
const_iterator cbegin() const noexcept
Definition: item_iterator.hpp:263
osmium::memory::ItemIteratorRange< const osmium::OuterRing > outer_rings() const
Definition: area.hpp:217
Definition: node_ref_list.hpp:50
data_type data() noexcept
Definition: item_iterator.hpp:195
ItemIterator< T > cast() const noexcept
Definition: item_iterator.hpp:157
osmium::memory::ItemIteratorRange< const osmium::InnerRing > inner_rings(const osmium::OuterRing &outer) const
Definition: area.hpp:227
std::pair< size_t, size_t > num_rings() const
Definition: area.hpp:146
InnerRing()
Definition: area.hpp:79
Definition: object.hpp:60