libosmscout  1.1.1
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 
23 #include <osmscout/import/Import.h>
24 
25 #include <map>
26 #include <unordered_map>
27 #include <unordered_set>
28 
29 #include <osmscout/Area.h>
30 
31 #include <osmscout/DataFile.h>
32 #include <osmscout/CoordDataFile.h>
33 
34 #include <osmscout/util/Geometry.h>
35 
38 #include <osmscout/import/RawWay.h>
40 
42 
43 namespace osmscout {
44 
45  class RelAreaDataGenerator CLASS_FINAL : public ImportModule
46  {
47  public:
48  static const char* const RELAREA_TMP;
49  static const char* const WAYAREABLACK_DAT;
50 
51  private:
52  typedef std::unordered_set<OSMId> IdSet;
53 
54  typedef std::unordered_map<OSMId,RawWayRef> IdRawWayMap;
55 
56  private:
57  class GroupingState
58  {
59  private:
60  size_t rings;
61  bool *used;
62  bool *includes;
63  bool *hasIncludes;
64 
65  public:
66  explicit GroupingState(size_t rings)
67  {
68  this->rings=rings;
69 
70  used=new bool[rings];
71  for (size_t i=0; i<rings; i++) {
72  used[i]=false;
73  }
74 
75  includes=new bool[rings*rings];
76  for (size_t i=0; i<rings*rings; i++) {
77  includes[i]=false;
78  }
79 
80  hasIncludes=new bool[rings];
81  for (size_t i=0; i<rings; i++) {
82  hasIncludes[i]=false;
83  }
84  }
85 
86  ~GroupingState()
87  {
88  delete [] hasIncludes;
89  delete [] includes;
90  delete [] used;
91  }
92 
93  inline size_t GetRingCount() const
94  {
95  return rings;
96  }
97 
98  inline void SetUsed(size_t used)
99  {
100  this->used[used]=true;
101  }
102 
103  inline bool IsUsed(size_t used) const
104  {
105  return this->used[used];
106  }
107 
108  inline void SetIncluded(size_t includer, size_t included)
109  {
110  hasIncludes[includer]=true;
111  includes[included*rings+includer]=true;
112  }
113 
114  inline bool HasIncludes(size_t includer) const
115  {
116  return hasIncludes[includer];
117  }
118 
119  inline bool Includes(size_t included, size_t includer) const
120  {
121  return includes[included*rings+includer];
122  }
123  };
124 
125  struct MultipolygonPart
126  {
127  Area::Ring role;
128  std::list<RawWayRef> ways;
129 
130  // diagnostics data
131  enum RelationRole {
132  none,
133  inner,
134  outer
135  } relationRole{none};
136 
137  OSMId id{0};
138 
139  inline bool IsArea() const
140  {
141  if (ways.size()==1) {
142  return ways.front()->IsArea() ||
143  ways.front()->GetNodes().front()==ways.front()->GetNodes().back();
144  }
145  else {
146  return false;
147  }
148  }
149 
150  inline void SetRelationRole(const std::string &role)
151  {
152  if (role=="outer") {
153  relationRole=outer;
154  } else if (role=="inner") {
155  relationRole=inner;
156  } else {
157  relationRole=none;
158  }
159  }
160 
161  inline std::string GetRelationRoleStr() const
162  {
163  switch (relationRole){
164  case outer:
165  return "outer";
166  case inner:
167  return "inner";
168  default:
169  return "none";
170  }
171  }
172 
173  inline void SetId(OSMId id)
174  {
175  this->id = id;
176  }
177  };
178 
179  private:
180  std::list<MultipolygonPart>::const_iterator FindTopLevel(const std::list<MultipolygonPart>& rings,
181  const GroupingState& state,
182  size_t& topIndex);
183 
184  std::list<MultipolygonPart>::const_iterator FindSub(const std::list<MultipolygonPart>& rings,
185  size_t topIndex,
186  const GroupingState& state,
187  size_t& subIndex);
188 
189  void ConsumeSubs(Progress& progress,
190  const std::list<MultipolygonPart>& rings,
191  std::list<MultipolygonPart>& groups,
192  GroupingState& state,
193  size_t topIndex,
194  uint8_t id);
195 
196  bool BuildRings(const TypeConfig& typeConfig,
197  const ImportParameter& parameter,
198  Progress& progress,
199  OSMId id,
200  const std::string& name,
201  const TypeInfoRef& type,
202  std::list<MultipolygonPart>& parts);
203 
204  bool ResolveMultipolygon(const TypeConfig& typeConfig,
205  const ImportParameter& parameter,
206  Progress& progress,
207  OSMId id,
208  const std::string& name,
209  const TypeInfoRef& type,
210  std::list<MultipolygonPart>& parts);
211 
212  bool ComposeAreaMembers(const TypeConfig& typeConfig,
213  Progress& progress,
214  const CoordDataFile::ResultMap& coordMap,
215  const IdRawWayMap& wayMap,
216  const std::string& name,
217  const RawRelation& rawRelation,
218  std::list<MultipolygonPart>& parts);
219 
220  bool ComposeBoundaryMembers(const TypeConfig& typeConfig,
221  Progress& progress,
222  const CoordDataFile::ResultMap& coordMap,
223  const IdRawWayMap& wayMap,
224  const std::map<OSMId,RawRelationRef>& relationMap,
225  const Area& relation,
226  const std::string& name,
227  const RawRelation& rawRelation,
228  IdSet& resolvedRelations,
229  std::list<MultipolygonPart>& parts);
230 
231  bool ResolveMultipolygonMembers(Progress& progress,
232  const ImportParameter& parameter,
233  const TypeConfig& typeConfig,
234  CoordDataFile& coordDataFile,
235  RawWayIndexedDataFile& wayDataFile,
236  RawRelationIndexedDataFile& relDataFile,
237  IdSet& resolvedRelations,
238  const Area& relation,
239  const std::string& name,
240  const RawRelation& rawRelation,
241  std::list<MultipolygonPart>& parts);
242 
243  bool HandleMultipolygonRelation(const ImportParameter& parameter,
244  Progress& progress,
245  const TypeConfig& typeConfig,
246  IdSet& wayAreaIndexBlacklist,
247  CoordDataFile& coordDataFile,
248  RawWayIndexedDataFile& wayDataFile,
249  RawRelationIndexedDataFile& relDataFile,
250  RawRelation& rawRelation,
251  const std::string& name,
252  Area& relation);
253 
254  std::string ResolveRelationName(const FeatureRef& featureName,
255  const RawRelation& rawRelation) const;
256 
257  TypeInfoRef AutodetectRelationType(const ImportParameter& parameter,
258  const TypeConfig& typeConfig,
259  const RawRelation& rawRelation,
260  std::list<MultipolygonPart>& parts,
261  std::list<MultipolygonPart>::iterator& copyPart) const;
262 
263  public:
264  void GetDescription(const ImportParameter& parameter,
265  ImportModuleDescription& description) const override;
266 
267  bool Import(const TypeConfigRef& typeConfig,
268  const ImportParameter& parameter,
269  Progress& progress) override;
270  };
271 }
272 
273 #endif
int64_t OSMId
Definition: OSMScoutTypes.h:34
Definition: Area.h:38
#define CLASS_FINAL
Definition: Compiler.h:26
std::shared_ptr< Feature > FeatureRef
Definition: TypeFeature.h:219
static const char *const RELAREA_TMP
Definition: GenRelAreaDat.h:48
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
static const char *const WAYAREABLACK_DAT
Definition: GenRelAreaDat.h:49
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227
std::unordered_map< OSMId, Point > ResultMap
Definition: CoordDataFile.h:42