SUMO - Simulation of Urban MObility
PCLoaderOSM.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // A reader of pois and polygons stored in OSM-format
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2008-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef PCLoaderOSM_h
24 #define PCLoaderOSM_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include "PCPolyContainer.h"
38 #include "PCTypeMap.h"
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
45 class OptionsCont;
46 
47 
48 // ===========================================================================
49 // class declarations
50 // ===========================================================================
57 class PCLoaderOSM : public SUMOSAXHandler {
58 public:
70  static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
71  PCTypeMap& tm);
72 
73 
74 protected:
75 
78  struct PCOSMNode {
80  long long int id;
86  std::map<std::string, std::string> myAttributes;
87  };
88 
89 
92  struct PCOSMRelation {
94  long long int id;
96  std::string name;
98  std::map<std::string, std::string> myAttributes;
99  };
100 
101 
104  struct PCOSMEdge {
106  long long int id;
108  std::string name;
112  std::vector<long long int> myCurrentNodes;
114  std::map<std::string, std::string> myAttributes;
115  };
116 
117  typedef std::vector<PCOSMRelation*> Relations;
118  typedef std::map<long long int, PCOSMRelation*> RelationsMap;
119  typedef std::map<long long int, PCOSMEdge*> EdgeMap;
120 
121 protected:
123  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
124  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
125 
127  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
128  const std::string& fullType, int index, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
129 
130 
131 protected:
132  static const std::set<std::string> MyKeysToInclude;
133 
134 private:
135  static std::set<std::string> initMyKeysToInclude();
136 
137 
138 protected:
143  class NodesHandler : public SUMOSAXHandler {
144  public:
150  NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
151  MsgHandler& errorHandler);
152 
153 
155  ~NodesHandler();
156 
157 
158  protected:
160 
161 
169  void myStartElement(int element, const SUMOSAXAttributes& attrs);
170 
171 
178  void myEndElement(int element);
180 
181 
182  private:
185 
188 
190  std::map<long long int, PCOSMNode*>& myToFill;
191 
193  std::vector<int> myParentElements;
194 
196  long long int myLastNodeID;
197 
198  private:
200  NodesHandler(const NodesHandler& s);
201 
204 
205  };
206 
212  public:
220  RelationsHandler(RelationsMap& additionalWays,
221  Relations& relations,
222  bool withAttributes,
223  MsgHandler& errorHandler);
224 
225 
227  ~RelationsHandler();
228 
229 
230  protected:
232 
233 
241  void myStartElement(int element, const SUMOSAXAttributes& attrs);
242 
243 
250  void myEndElement(int element);
252 
253 
254  private:
256  RelationsMap& myAdditionalWays;
257 
259  Relations& myRelations;
260 
263 
266 
269 
271  std::vector<long long int> myCurrentWays;
272 
274  std::vector<long long int> myParentElements;
275 
277  bool myKeep;
278 
279  private:
282 
285 
286  };
287 
288 
293  class EdgesHandler : public SUMOSAXHandler {
294  public:
303  EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
304  EdgeMap& toFill,
305  const RelationsMap& additionalWays,
306  bool withAttributes,
307  MsgHandler& errorHandler);
308 
309 
311  ~EdgesHandler();
312 
313 
314  protected:
316 
317 
325  void myStartElement(int element, const SUMOSAXAttributes& attrs);
326 
327 
334  void myEndElement(int element);
336 
337 
338  private:
341 
344 
346  const std::map<long long int, PCOSMNode*>& myOSMNodes;
347 
349  EdgeMap& myEdgeMap;
350 
352  const RelationsMap& myAdditionalWays;
353 
356 
358  std::vector<int> myParentElements;
359 
361  bool myKeep;
362 
363  private:
365  EdgesHandler(const EdgesHandler& s);
366 
369 
370  };
371 
372 };
373 
374 
375 #endif
376 
377 /****************************************************************************/
378 
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:98
SUMOReal lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:84
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:104
static int addPOI(const PCOSMNode *node, const Position &pos, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the POI and return the next index on success
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
Definition: PCLoaderOSM.cpp:98
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:349
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:66
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:268
An internal definition of a loaded relation.
Definition: PCLoaderOSM.h:92
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:256
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:271
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:196
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:259
long long int id
The node&#39;s id.
Definition: PCLoaderOSM.h:80
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:69
SAX-handler base for SUMO-files.
SUMOReal lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:82
A storage for loaded polygons and pois.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:343
std::map< long long int, PCOSMEdge * > EdgeMap
Definition: PCLoaderOSM.h:119
long long int id
The edge&#39;s id.
Definition: PCLoaderOSM.h:106
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:211
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:277
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:132
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:114
A storage for type mappings.
Definition: PCTypeMap.h:52
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:355
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:187
std::string name
The relation&#39;s name (if any)
Definition: PCLoaderOSM.h:96
Encapsulated SAX-Attributes.
A reader of pois and polygons stored in OSM-format.
Definition: PCLoaderOSM.h:57
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:86
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:110
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:265
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:293
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:118
long long int id
The relation&#39;s id.
Definition: PCLoaderOSM.h:94
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:361
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:358
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:340
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:143
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:274
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:193
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:117
const SUMOSAXHandler & operator=(const SUMOSAXHandler &s)
invalidated assignment operator
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:112
static int addPolygon(const PCOSMEdge *edge, const PositionVector &vec, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, bool useName, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the polygon and return the next index on success
A storage for options typed value containers)
Definition: OptionsCont.h:108
std::string name
The edge&#39;s name (if any)
Definition: PCLoaderOSM.h:108
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:262
#define SUMOReal
Definition: config.h:214
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:184
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:346
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:190
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:352
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:78
virtual void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.