SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
77  struct PCOSMNode {
85  std::map<std::string, std::string> myAttributes;
86  };
87 
88 
91  struct PCOSMEdge {
93  std::string id;
95  std::string name;
97  bool myIsClosed;
99  std::vector<SUMOLong> myCurrentNodes;
101  std::map<std::string, std::string> myAttributes;
102  };
103 
104 protected:
106  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
107  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
108 
110  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
111  const std::string& fullType, int index, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
112 
113 
114 protected:
115  static const std::set<std::string> MyKeysToInclude;
116 
117 private:
118  static std::set<std::string> initMyKeysToInclude();
119 
120 
121 protected:
126  class NodesHandler : public SUMOSAXHandler {
127  public:
133  NodesHandler(std::map<SUMOLong, PCOSMNode*>& toFill, bool withAttributes,
134  MsgHandler& errorHandler);
135 
136 
138  ~NodesHandler();
139 
140 
141  protected:
143 
144 
152  void myStartElement(int element, const SUMOSAXAttributes& attrs);
153 
154 
161  void myEndElement(int element);
163 
164 
165  private:
168 
171 
173  std::map<SUMOLong, PCOSMNode*>& myToFill;
174 
176  std::vector<int> myParentElements;
177 
180 
181  private:
183  NodesHandler(const NodesHandler& s);
184 
187 
188  };
189 
190 
191 
196  class EdgesHandler : public SUMOSAXHandler {
197  public:
205  EdgesHandler(const std::map<SUMOLong, PCOSMNode*>& osmNodes,
206  std::map<std::string, PCOSMEdge*>& toFill, bool withAttributes,
207  MsgHandler& errorHandler);
208 
209 
211  ~EdgesHandler();
212 
213 
214  protected:
216 
217 
225  void myStartElement(int element, const SUMOSAXAttributes& attrs);
226 
227 
234  void myEndElement(int element);
236 
237 
238  private:
241 
244 
246  const std::map<SUMOLong, PCOSMNode*>& myOSMNodes;
247 
249  std::map<std::string, PCOSMEdge*>& myEdgeMap;
250 
253 
255  std::vector<int> myParentElements;
256 
258  bool myKeep;
259 
260  private:
262  EdgesHandler(const EdgesHandler& s);
263 
266 
267  };
268 
269 };
270 
271 
272 #endif
273 
274 /****************************************************************************/
275 
SUMOReal lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:83
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:91
SUMOLong myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:179
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
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:66
std::map< std::string, PCOSMEdge * > & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:249
std::vector< SUMOLong > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:99
EdgesHandler(const std::map< SUMOLong, PCOSMNode * > &osmNodes, std::map< std::string, PCOSMEdge * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Constructor.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
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:81
std::string id
The edge's id.
Definition: PCLoaderOSM.h:93
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:243
NodesHandler(std::map< SUMOLong, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:115
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:101
A storage for type mappings.
Definition: PCTypeMap.h:52
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:252
void myEndElement(int element)
Called when a closing tag occurs.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:170
void myEndElement(int element)
Called when a closing tag occurs.
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:85
const std::map< SUMOLong, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:246
SUMOLong id
The node's id.
Definition: PCLoaderOSM.h:79
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:97
#define SUMOLong
Definition: config.h:215
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:196
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:258
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:255
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:240
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:126
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:176
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's name (if any)
Definition: PCLoaderOSM.h:95
std::map< SUMOLong, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:173
#define SUMOReal
Definition: config.h:218
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:167
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:77