Libosmium  2.9.0
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 <class T> class ObjectBuilder;
54  } // namespace builder
55 
59  class OuterRing : public NodeRefList {
60 
61  public:
62 
64 
66  NodeRefList(itemtype) {
67  }
68 
69  }; // class OuterRing
70 
71 
75  class InnerRing : public NodeRefList {
76 
77  public:
78 
80 
82  NodeRefList(itemtype) {
83  }
84 
85  }; // class InnerRing
86 
87 
96  osmium::object_id_type area_id = std::abs(id) * 2;
98  ++area_id;
99  }
100  return id < 0 ? -area_id : area_id;
101  }
102 
110  return id / 2;
111  }
112 
116  class Area : public OSMObject {
117 
119 
120  Area() :
121  OSMObject(sizeof(Area), osmium::item_type::area) {
122  }
123 
124  public:
125 
127 
132  bool from_way() const noexcept {
133  return (positive_id() & 0x1) == 0;
134  }
135 
139  osmium::object_id_type orig_id() const noexcept {
140  return osmium::area_id_to_object_id(id());
141  }
142 
148  std::pair<size_t, size_t> num_rings() const {
149  std::pair<size_t, size_t> counter { 0, 0 };
150 
151  for (auto it = cbegin(); it != cend(); ++it) {
152  switch (it->type()) {
154  ++counter.first;
155  break;
157  ++counter.second;
158  break;
160  // ignore tags
161  break;
172  assert(false && "Children of Area can only be outer/inner_ring and tag_list.");
173  break;
174  }
175  }
176 
177  return counter;
178  }
179 
184  bool is_multipolygon() const {
185  return num_rings().first > 1;
186  }
187 
198  return it.cast<const osmium::InnerRing>();
199  }
200 
211  return std::next(it).cast<const osmium::InnerRing>();
212  }
213 
220  return subitems<const osmium::OuterRing>();
221  }
222 
231  return osmium::memory::ItemIteratorRange<const osmium::InnerRing>{outer_range.cbegin().data(), std::next(outer_range.cbegin()).data()};
232  }
233 
234  }; // class Area
235 
236 
237 } // namespace osmium
238 
239 #endif // OSMIUM_OSM_AREA_HPP
osmium::object_id_type orig_id() const noexcept
Definition: area.hpp:139
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
bool from_way() const noexcept
Definition: area.hpp:132
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:197
Definition: item_iterator.hpp:248
static constexpr osmium::item_type itemtype
Definition: area.hpp:63
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:363
static constexpr osmium::item_type itemtype
Definition: area.hpp:79
Definition: area.hpp:116
Definition: area.hpp:75
const_iterator cbegin() const
Definition: object.hpp:359
osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept
Definition: area.hpp:95
OSMIUM_DEPRECATED osmium::memory::ItemIterator< const osmium::InnerRing > inner_ring_cend(const osmium::memory::ItemIterator< const osmium::OuterRing > &it) const
Definition: area.hpp:210
static constexpr osmium::item_type itemtype
Definition: area.hpp:126
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
bool is_multipolygon() const
Definition: area.hpp:184
osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept
Definition: area.hpp:109
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
OuterRing()
Definition: area.hpp:65
Definition: area.hpp:59
unsigned char * data() const noexcept
Definition: collection.hpp:91
Definition: builder.hpp:185
const_iterator cbegin() const noexcept
Definition: item_iterator.hpp:276
osmium::memory::ItemIteratorRange< const osmium::OuterRing > outer_rings() const
Definition: area.hpp:219
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:115
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:229
std::pair< size_t, size_t > num_rings() const
Definition: area.hpp:148
InnerRing()
Definition: area.hpp:81
Definition: object.hpp:58