libosmscout 1.1.1
Loading...
Searching...
No Matches
GenRelAreaDat.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_IMPORT_GENRELAREADAT_H
2#define OSMSCOUT_IMPORT_GENRELAREADAT_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2010 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
24
25#include <map>
26#include <unordered_map>
27#include <unordered_set>
28
29#include <osmscout/Area.h>
30
32
34
39
41
42namespace osmscout {
43
44 class RelAreaDataGenerator CLASS_FINAL : public ImportModule
45 {
46 public:
47 static const char* const RELAREA_TMP;
48 static const char* const WAYAREABLACK_DAT;
49
50 private:
51 typedef std::unordered_set<OSMId> IdSet;
52
53 typedef std::unordered_map<OSMId,RawWayRef> IdRawWayMap;
54
55 private:
56 class GroupingState
57 {
58 private:
59 size_t rings;
60 bool *used;
61 bool *includes;
62 bool *hasIncludes;
63
64 public:
65 explicit GroupingState(size_t rings)
66 {
67 this->rings=rings;
68
69 used=new bool[rings];
70 for (size_t i=0; i<rings; i++) {
71 used[i]=false;
72 }
73
74 includes=new bool[rings*rings];
75 for (size_t i=0; i<rings*rings; i++) {
76 includes[i]=false;
77 }
78
79 hasIncludes=new bool[rings];
80 for (size_t i=0; i<rings; i++) {
81 hasIncludes[i]=false;
82 }
83 }
84
85 ~GroupingState()
86 {
87 delete [] hasIncludes;
88 delete [] includes;
89 delete [] used;
90 }
91
92 inline size_t GetRingCount() const
93 {
94 return rings;
95 }
96
97 inline void SetUsed(size_t used)
98 {
99 this->used[used]=true;
100 }
101
102 inline bool IsUsed(size_t used) const
103 {
104 return this->used[used];
105 }
106
107 inline void SetIncluded(size_t includer, size_t included)
108 {
109 hasIncludes[includer]=true;
110 includes[included*rings+includer]=true;
111 }
112
113 inline bool HasIncludes(size_t includer) const
114 {
115 return hasIncludes[includer];
116 }
117
118 inline bool Includes(size_t included, size_t includer) const
119 {
120 return includes[included*rings+includer];
121 }
122 };
123
124 struct MultipolygonPart
125 {
126 Area::Ring role;
127 std::list<RawWayRef> ways;
128
129 // diagnostics data
130 enum RelationRole {
131 none,
132 inner,
133 outer
134 } relationRole{none};
135
136 OSMId id{0};
137
138 inline bool IsArea() const
139 {
140 if (ways.size()==1) {
141 return ways.front()->IsArea() ||
142 ways.front()->GetNodes().front()==ways.front()->GetNodes().back();
143 }
144 else {
145 return false;
146 }
147 }
148
149 inline void SetRelationRole(const std::string &role)
150 {
151 if (role=="outer") {
152 relationRole=outer;
153 } else if (role=="inner") {
154 relationRole=inner;
155 } else {
156 relationRole=none;
157 }
158 }
159
160 static inline std::string GetRelationRoleStr(RelationRole relationRole)
161 {
162 switch (relationRole){
163 case outer:
164 return "outer";
165 case inner:
166 return "inner";
167 default:
168 return "none";
169 }
170 }
171
172 inline std::string GetRelationRoleStr() const
173 {
174 return GetRelationRoleStr(relationRole);
175 }
176
177 inline void SetId(OSMId id)
178 {
179 this->id = id;
180 }
181 };
182
183 private:
184 std::list<MultipolygonPart>::const_iterator FindTopLevel(const std::list<MultipolygonPart>& rings,
185 const GroupingState& state,
186 size_t& topIndex);
187
188 std::list<MultipolygonPart>::const_iterator FindSub(const std::list<MultipolygonPart>& rings,
189 size_t topIndex,
190 const GroupingState& state,
191 size_t& subIndex);
192
193 void ConsumeSubs(Progress& progress,
194 const std::list<MultipolygonPart>& rings,
195 std::vector<MultipolygonPart>& groups,
196 GroupingState& state,
197 size_t topIndex,
198 uint8_t id);
199
200 bool BuildRings(const TypeConfig& typeConfig,
201 const ImportParameter& parameter,
202 Progress& progress,
203 OSMId id,
204 const std::string& name,
205 const TypeInfoRef& type,
206 std::list<MultipolygonPart>& parts);
207
208 bool ResolveMultipolygon(const TypeConfig& typeConfig,
209 const ImportParameter& parameter,
210 Progress& progress,
211 OSMId id,
212 const std::string& name,
213 const TypeInfoRef& type,
214 std::list<MultipolygonPart>& parts);
215
216 bool ComposeAreaMembers(const TypeConfig& typeConfig,
217 Progress& progress,
218 const CoordDataFile::ResultMap& coordMap,
219 const IdRawWayMap& wayMap,
220 const std::string& name,
221 const RawRelation& rawRelation,
222 std::list<MultipolygonPart>& parts);
223
224 bool ComposeBoundaryMembers(const TypeConfig& typeConfig,
225 Progress& progress,
226 const CoordDataFile::ResultMap& coordMap,
227 const IdRawWayMap& wayMap,
228 const std::map<OSMId,RawRelationRef>& relationMap,
229 const Area& relation,
230 const std::string& name,
231 const RawRelation& rawRelation,
232 IdSet& resolvedRelations,
233 std::list<MultipolygonPart>& parts);
234
235 bool ResolveMultipolygonMembers(Progress& progress,
236 const ImportParameter& parameter,
237 const TypeConfig& typeConfig,
238 CoordDataFile& coordDataFile,
239 RawWayIndexedDataFile& wayDataFile,
240 RawRelationIndexedDataFile& relDataFile,
241 IdSet& resolvedRelations,
242 const Area& relation,
243 const std::string& name,
244 const RawRelation& rawRelation,
245 std::list<MultipolygonPart>& parts);
246
247 bool HandleMultipolygonRelation(const ImportParameter& parameter,
248 Progress& progress,
249 const TypeConfig& typeConfig,
250 IdSet& wayAreaIndexBlacklist,
251 CoordDataFile& coordDataFile,
252 RawWayIndexedDataFile& wayDataFile,
253 RawRelationIndexedDataFile& relDataFile,
254 RawRelation& rawRelation,
255 const std::string& name,
256 Area& relation);
257
258 std::string ResolveRelationName(const FeatureRef& featureName,
259 const RawRelation& rawRelation) const;
260
261 TypeInfoRef AutodetectRelationType(const ImportParameter& parameter,
262 const TypeConfig& typeConfig,
263 const RawRelation& rawRelation,
264 std::list<MultipolygonPart>& parts,
265 std::list<MultipolygonPart>::iterator& copyPart) const;
266
267 public:
268 void GetDescription(const ImportParameter& parameter,
269 ImportModuleDescription& description) const override;
270
271 bool Import(const TypeConfigRef& typeConfig,
272 const ImportParameter& parameter,
273 Progress& progress) override;
274 };
275}
276
277#endif
Definition Area.h:88
void GetDescription(const ImportParameter &parameter, ImportModuleDescription &description) const override
std::vector< Ring > rings
Definition Area.h:242
static const char *const WAYAREABLACK_DAT
Definition GenRelAreaDat.h:48
bool Includes(const P &coord, bool openInterval=true) const
Definition GeoBox.h:113
static const char *const RELAREA_TMP
Definition GenRelAreaDat.h:47
bool Import(const TypeConfigRef &typeConfig, const ImportParameter &parameter, Progress &progress) override
Definition ImportModule.h:101
int64_t OSMId
Definition OSMScoutTypes.h:33
std::shared_ptr< TypeConfig > TypeConfigRef
Definition TypeConfig.h:1396
Definition Area.h:39
std::shared_ptr< TypeInfo > TypeInfoRef
Definition TypeConfig.h:61