SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCLoaderOSM.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A reader of pois and polygons stored in OSM-format
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef PCLoaderOSM_h
23 #define PCLoaderOSM_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include "PCPolyContainer.h"
37 #include "PCTypeMap.h"
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
44 class OptionsCont;
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
56 class PCLoaderOSM : public SUMOSAXHandler {
57 public:
69  static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
70  PCTypeMap& tm);
71 
72 
73 protected:
76  struct PCOSMNode {
84  std::map<std::string, std::string> myAttributes;
85  };
86 
87 
90  struct PCOSMEdge {
92  std::string id;
94  std::string name;
96  bool myIsClosed;
98  std::vector<SUMOLong> myCurrentNodes;
100  std::map<std::string, std::string> myAttributes;
101  };
102 
103 protected:
105  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
106  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
107 
109  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
110  const std::string& fullType, int index, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
111 
112 
113 protected:
114  static const std::set<std::string> MyKeysToInclude;
115 
116 private:
117  static std::set<std::string> initMyKeysToInclude();
118 
119 
120 protected:
125  class NodesHandler : public SUMOSAXHandler {
126  public:
132  NodesHandler(std::map<SUMOLong, PCOSMNode*>& toFill, bool withAttributes,
133  MsgHandler& errorHandler);
134 
135 
137  ~NodesHandler();
138 
139 
140  protected:
142 
143 
151  void myStartElement(int element, const SUMOSAXAttributes& attrs);
152 
153 
160  void myEndElement(int element);
162 
163 
164  private:
167 
170 
172  std::map<SUMOLong, PCOSMNode*>& myToFill;
173 
175  std::vector<int> myParentElements;
176 
179 
180  private:
182  NodesHandler(const NodesHandler& s);
183 
186 
187  };
188 
189 
190 
195  class EdgesHandler : public SUMOSAXHandler {
196  public:
204  EdgesHandler(const std::map<SUMOLong, PCOSMNode*>& osmNodes,
205  std::map<std::string, PCOSMEdge*>& toFill, bool withAttributes,
206  MsgHandler& errorHandler);
207 
208 
210  ~EdgesHandler();
211 
212 
213  protected:
215 
216 
224  void myStartElement(int element, const SUMOSAXAttributes& attrs);
225 
226 
233  void myEndElement(int element);
235 
236 
237  private:
240 
243 
245  const std::map<SUMOLong, PCOSMNode*>& myOSMNodes;
246 
248  std::map<std::string, PCOSMEdge*>& myEdgeMap;
249 
252 
254  std::vector<int> myParentElements;
255 
257  bool myKeep;
258 
259  private:
261  EdgesHandler(const EdgesHandler& s);
262 
265 
266  };
267 
268 };
269 
270 
271 #endif
272 
273 /****************************************************************************/
274 
SUMOReal lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:82
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:90
SUMOLong myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:178
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:96
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:65
std::map< std::string, PCOSMEdge * > & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:248
std::vector< SUMOLong > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:98
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:68
SAX-handler base for SUMO-files.
SUMOReal lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:80
std::string id
The edge&#39;s id.
Definition: PCLoaderOSM.h:92
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:242
NodesHandler(std::map< SUMOLong, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:114
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:100
A storage for type mappings.
Definition: PCTypeMap.h:51
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:251
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:169
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:56
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:84
const std::map< SUMOLong, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:245
SUMOLong id
The node&#39;s id.
Definition: PCLoaderOSM.h:78
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:96
#define SUMOLong
Definition: config.h:212
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:195
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:257
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:254
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:239
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:125
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:175
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:94
std::map< SUMOLong, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:172
#define SUMOReal
Definition: config.h:215
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:166
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:76