SUMO - Simulation of Urban MObility
PCLoaderOSM.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // A reader of pois and polygons stored in OSM-format
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:
74 
77  struct PCOSMNode {
79  long long int id;
81  double lon;
83  double lat;
85  std::map<std::string, std::string> myAttributes;
86  };
87 
88 
91  struct PCOSMRelation {
93  long long int id;
95  std::string name;
97  std::map<std::string, std::string> myAttributes;
98  };
99 
100 
103  struct PCOSMEdge {
105  long long int id;
107  std::string name;
111  std::vector<long long int> myCurrentNodes;
113  std::map<std::string, std::string> myAttributes;
114  };
115 
116  typedef std::vector<PCOSMRelation*> Relations;
117  typedef std::map<long long int, PCOSMRelation*> RelationsMap;
118  typedef std::map<long long int, PCOSMEdge*> EdgeMap;
119 
120 protected:
122  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
123  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
124 
126  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
127  const std::string& fullType, int index, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
128 
129 
130 protected:
131  static const std::set<std::string> MyKeysToInclude;
132 
133 private:
134  static std::set<std::string> initMyKeysToInclude();
135 
136 
137 protected:
142  class NodesHandler : public SUMOSAXHandler {
143  public:
149  NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
150  MsgHandler& errorHandler);
151 
152 
154  ~NodesHandler();
155 
156 
157  protected:
159 
160 
168  void myStartElement(int element, const SUMOSAXAttributes& attrs);
169 
170 
177  void myEndElement(int element);
179 
180 
181  private:
184 
187 
189  std::map<long long int, PCOSMNode*>& myToFill;
190 
192  std::vector<int> myParentElements;
193 
195  long long int myLastNodeID;
196 
197  private:
199  NodesHandler(const NodesHandler& s);
200 
203 
204  };
205 
211  public:
219  RelationsHandler(RelationsMap& additionalWays,
220  Relations& relations,
221  bool withAttributes,
222  MsgHandler& errorHandler);
223 
224 
226  ~RelationsHandler();
227 
228 
229  protected:
231 
232 
240  void myStartElement(int element, const SUMOSAXAttributes& attrs);
241 
242 
249  void myEndElement(int element);
251 
252 
253  private:
255  RelationsMap& myAdditionalWays;
256 
258  Relations& myRelations;
259 
262 
265 
268 
270  std::vector<long long int> myCurrentWays;
271 
273  std::vector<long long int> myParentElements;
274 
276  bool myKeep;
277 
278  private:
281 
284 
285  };
286 
287 
292  class EdgesHandler : public SUMOSAXHandler {
293  public:
302  EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
303  EdgeMap& toFill,
304  const RelationsMap& additionalWays,
305  bool withAttributes,
306  MsgHandler& errorHandler);
307 
308 
310  ~EdgesHandler();
311 
312 
313  protected:
315 
316 
324  void myStartElement(int element, const SUMOSAXAttributes& attrs);
325 
326 
333  void myEndElement(int element);
335 
336 
337  private:
340 
343 
345  const std::map<long long int, PCOSMNode*>& myOSMNodes;
346 
348  EdgeMap& myEdgeMap;
349 
351  const RelationsMap& myAdditionalWays;
352 
355 
357  std::vector<int> myParentElements;
358 
360  bool myKeep;
361 
362  private:
364  EdgesHandler(const EdgesHandler& s);
365 
368 
369  };
370 
371 };
372 
373 
374 #endif
375 
376 /****************************************************************************/
377 
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:97
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:103
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:93
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:348
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:65
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:267
An internal definition of a loaded relation.
Definition: PCLoaderOSM.h:91
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:255
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:270
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:195
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:258
long long int id
The node&#39;s id.
Definition: PCLoaderOSM.h:79
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:64
SAX-handler base for SUMO-files.
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:342
double lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:81
std::map< long long int, PCOSMEdge * > EdgeMap
Definition: PCLoaderOSM.h:118
long long int id
The edge&#39;s id.
Definition: PCLoaderOSM.h:105
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:210
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:276
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:131
double lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:83
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:113
A storage for type mappings.
Definition: PCTypeMap.h:51
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:354
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:186
std::string name
The relation&#39;s name (if any)
Definition: PCLoaderOSM.h:95
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:45
A list of positions.
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:85
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:109
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
Definition: PCLoaderOSM.h:264
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:292
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:117
long long int id
The relation&#39;s id.
Definition: PCLoaderOSM.h:93
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
Definition: PCLoaderOSM.h:360
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:357
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:339
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:142
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:273
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:192
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:116
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:111
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:98
std::string name
The edge&#39;s name (if any)
Definition: PCLoaderOSM.h:107
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:261
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:183
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:345
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:189
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:351
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:77
virtual void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.