Libosmium  2.20.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
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
39#include <osmium/osm/box.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
50namespace 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
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
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
osmium::memory::ItemIteratorRange< const osmium::InnerRing > inner_rings(const osmium::OuterRing &outer) const
Definition: area.hpp:223
std::pair< size_t, size_t > num_rings() const
Definition: area.hpp:168
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:138
bool from_way() const noexcept
Definition: area.hpp:148
static constexpr osmium::item_type itemtype
Definition: area.hpp:136
Area()
Definition: area.hpp:130
osmium::memory::ItemIteratorRange< const osmium::OuterRing > outer_rings() const
Definition: area.hpp:213
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
static constexpr osmium::item_type itemtype
Definition: area.hpp:84
InnerRing()
Definition: area.hpp:90
static constexpr bool is_compatible_to(osmium::item_type t) noexcept
Definition: area.hpp:86
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
static constexpr 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