SUMO - Simulation of Urban MObility
NIImporter_OpenStreetMap.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // Importer for networks stored in OpenStreetMap format
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef NIImporter_OpenStreetMap_h
25 #define NIImporter_OpenStreetMap_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <string>
38 #include <map>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class NBEdge;
48 class NBEdgeCont;
49 class NBNetBuilder;
50 class NBNode;
51 class NBNodeCont;
53 class NBTypeCont;
54 class OptionsCont;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
66 public:
78  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
79 
80 
81 protected:
84  struct NIOSMNode {
85  NIOSMNode(long long int _id, double _lon, double _lat) :
86  id(_id), lon(_lon), lat(_lat), ele(0), tlsControlled(false), railwayCrossing(false), ptStopPostion(false), ptStopLength(0), node(0) {}
87 
89  const long long int id;
91  const double lon;
93  const double lat;
95  double ele;
103  double ptStopLength;
105  std::string name;
108 
109  private:
111  NIOSMNode& operator=(const NIOSMNode& s);
112 
113  };
114 
118  enum WayType {
119  WAY_NONE = 0,
124  };
125 
126 
129  struct Edge : public Parameterised {
130 
131  Edge(long long int _id) :
132  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
133  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
134  myBuswayType(WAY_NONE), // buslanes are always built when declared
135  myLayer(0), // layer is non-zero only in conflict areas
136  myCurrentIsRoad(false) {}
137 
139  const long long int id;
141  std::string streetName;
147  double myMaxSpeed;
149  std::string myHighWayType;
151  std::string myIsOneWay;
157  int myLayer;
159  std::vector<long long int> myCurrentNodes;
162 
163  private:
165  Edge& operator=(const Edge& s);
166 
167  };
168 
169 
171 
173 
174  void load(const OptionsCont& oc, NBNetBuilder& nb);
175 
176 private:
180  class CompareNodes {
181  public:
182  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
183  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
184  }
185  };
186 
187 
189  static const std::string compoundTypeSeparator;
190 
192 
196  std::map<long long int, NIOSMNode*> myOSMNodes;
197 
199  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
200 
201 
203  std::map<long long int, Edge*> myEdges;
204 
206  std::set<std::string> myUnusableTypes;
207 
209  std::map<std::string, std::string> myKnownCompoundTypes;
210 
225  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
226 
227 
240  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
241  const std::vector<long long int>& passed, NBNetBuilder& nb);
242 
244  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
245 
247  std::map<NBNode*, std::pair<double, double> > getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
248 
249 protected:
250  static const double MAXSPEED_UNGIVEN;
251  static const long long int INVALID_ID;
252 
257  friend class NodesHandler;
258  class NodesHandler : public SUMOSAXHandler {
259  public:
265  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
266  CompareNodes>& uniqueNodes, const OptionsCont& cont);
267 
268 
270  ~NodesHandler();
271 
272 
273  protected:
275 
276 
284  void myStartElement(int element, const SUMOSAXAttributes& attrs);
285 
286 
293  void myEndElement(int element);
295 
296 
297  private:
298 
300  std::map<long long int, NIOSMNode*>& myToFill;
301 
303  long long int myLastNodeID;
304 
307 
310 
312  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
313 
315  const bool myImportElevation;
316 
319 
320 
321  private:
323  NodesHandler(const NodesHandler& s);
324 
327 
328  };
329 
330 
331 
336  class EdgesHandler : public SUMOSAXHandler {
337  public:
343  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
344  std::map<long long int, Edge*>& toFill);
345 
346 
348  ~EdgesHandler();
349 
350 
351  protected:
353 
354 
362  void myStartElement(int element, const SUMOSAXAttributes& attrs);
363 
364 
371  void myEndElement(int element);
373 
374 
375  private:
377  const std::map<long long int, NIOSMNode*>& myOSMNodes;
378 
380  std::map<long long int, Edge*>& myEdgeMap;
381 
384 
386  std::vector<int> myParentElements;
387 
389  std::map<std::string, double> mySpeedMap;
390 
391  private:
393  EdgesHandler(const EdgesHandler& s);
394 
397 
398  };
399 
406  public:
412  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
413  const std::map<long long int, Edge*>& osmEdges);
414 
415 
417  ~RelationHandler();
418 
419 
420  protected:
422 
423 
431  void myStartElement(int element, const SUMOSAXAttributes& attrs);
432 
433 
440  void myEndElement(int element);
442 
443 
444  private:
446  const std::map<long long int, NIOSMNode*>& myOSMNodes;
447 
449  const std::map<long long int, Edge*>& myOSMEdges;
450 
452  long long int myCurrentRelation;
453 
455  std::vector<int> myParentElements;
456 
459 
461  long long int myFromWay;
462 
464  long long int myToWay;
465 
467  long long int myViaNode;
468  long long int myViaWay;
469 
470 
480  RESTRICTION_UNKNOWN
481  };
483 
485  void resetValues();
486 
488  bool checkEdgeRef(long long int ref) const;
489 
491  bool applyRestriction() const;
492 
494  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
495 
496  private:
499 
502 
503  };
504 
505 };
506 
507 
508 #endif
509 
510 /****************************************************************************/
511 
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
An internal definition of a loaded edge.
const bool myImportElevation
whether elevation data should be imported
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
An internal representation of an OSM-node.
const long long int id
The edge&#39;s id.
std::string streetName
The edge&#39;s street name.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const long long int id
The node&#39;s id.
WayType myBuswayType
Information about the kind of busway along this road.
long long int myFromWay
the origination way for the current restriction
A container for traffic light definitions and built programs.
std::map< NBNode *, std::pair< double, double > > getNeighboringNodes(NBNode *node, double maxDist, const std::set< NBNode *> &knownElevation)
collect neighboring nodes with their road distance and maximum between-speed. Search does not continu...
bool ptStopPostion
Whether this is a public transport stop position.
The representation of a single edge during network building.
Definition: NBEdge.h:71
long long int myCurrentRelation
The currently parsed relation.
NIOSMNode(long long int _id, double _lon, double _lat)
NIOSMNode & operator=(const NIOSMNode &s)
invalidated assignment operator
SAX-handler base for SUMO-files.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
RestrictionType
whether the only allowed or the only forbidden connection is defined
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
NBNode * node
the NBNode that was instantiated
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
Functor which compares two Edges.
WayType myCyclewayType
Information about the kind of cycleway along this road.
int myNoLanesForward
number of lanes in forward direction or 0 if unknown, negative if backwards lanes are meant ...
void load(const OptionsCont &oc, NBNetBuilder &nb)
A class which extracts OSM-edges from a parsed OSM-file.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< long long int > &passed, NBNetBuilder &nb)
Builds an NBEdge.
double ele
The elevation of this node.
std::vector< int > myParentElements
The element stack.
Encapsulated SAX-Attributes.
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
bool myIsRestriction
whether the currently parsed relation is a restriction
An upper class for objects with additional parameters.
Definition: Parameterised.h:51
bool railwayCrossing
Whether this is a railway crossing.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
bool myIsInValidNodeTag
Hierarchy helper for parsing a node&#39;s tags.
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
const double lat
The latitude the node is located at.
int myNoLanes
number of lanes, or -1 if unknown
bool tlsControlled
Whether this is a tls controlled junction.
std::map< std::string, std::string > myKnownCompoundTypes
The compound types that have already been mapped to other known types.
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
long long int myToWay
the destination way for the current restriction
int myLayer
Information about the relative z-ordering of ways.
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
A storage for options typed value containers)
Definition: OptionsCont.h:99
long long int myViaNode
the via node/way for the current restriction
void reconstructLayerElevation(double layerElevation, NBNetBuilder &nb)
reconstruct elevation from layer info
std::string name
The name of the node.
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:75
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
int myHierarchyLevel
The current hierarchy level.
std::string myHighWayType
The type, stored in "highway" key.
const double lon
The longitude the node is located at.
Importer for networks stored in OpenStreetMap format.
static const long long int INVALID_ID
bool myCurrentIsRoad
Information whether this is a road.
Edge * myCurrentEdge
The currently built edge.
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
double ptStopLength
The length of the pt stop.
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
std::vector< int > myParentElements
The element stack.
Functor which compares two NIOSMNodes according to their coordinates.
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
static const double MAXSPEED_UNGIVEN
const OptionsCont & myOptionsCont
the options
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
std::map< std::string, double > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
A storage for available types of edges.
Definition: NBTypeCont.h:62