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 #include <netbuild/NBPTPlatform.h>
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class NBEdge;
49 class NBEdgeCont;
50 class NBNetBuilder;
51 class NBNode;
52 class NBNodeCont;
54 class NBTypeCont;
55 class OptionsCont;
56 
57 
58 // ===========================================================================
59 // class definitions
60 // ===========================================================================
67 public:
79  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
80 
81 
82 protected:
85  struct NIOSMNode {
86  NIOSMNode(long long int _id, double _lon, double _lat)
87  :
88  id(_id), lon(_lon), lat(_lat), ele(0), tlsControlled(false), railwayCrossing(false),
89  ptStopPosition(false), ptStopLength(0), name(""),
91  node(0) { }
92 
94  const long long int id;
96  const double lon;
98  const double lat;
100  double ele;
108  double ptStopLength;
110  std::string name;
115 
116  private:
118  NIOSMNode& operator=(const NIOSMNode& s) = delete;
119 
120 
121  };
122 
126  enum WayType {
127  WAY_NONE = 0,
132  };
133 
134 
137  struct Edge : public Parameterised {
138 
139  explicit Edge(long long int _id)
140  :
141  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
142  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
143  myBuswayType(WAY_NONE), // buslanes are always built when declared
144  myLayer(0), // layer is non-zero only in conflict areas
145  myCurrentIsRoad(false),
146  myCurrentIsPlatform(false) { }
147 
148 
150  const long long int id;
152  std::string streetName;
158  double myMaxSpeed;
160  std::string myHighWayType;
162  std::string myIsOneWay;
168  int myLayer;
170  std::vector<long long int> myCurrentNodes;
175 
176  private:
178  Edge& operator=(const Edge& s) = delete;
179 
180 
181  };
182 
183 
185 
187 
188  void load(const OptionsCont& oc, NBNetBuilder& nb);
189 
190 private:
194  class CompareNodes {
195  public:
196  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
197  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
198  }
199  };
200 
201 
203  static const std::string compoundTypeSeparator;
204 
206 
210  std::map<long long int, NIOSMNode*> myOSMNodes;
211 
213  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
214 
215 
217  std::map<long long int, Edge*> myEdges;
218 
220  std::map<long long int, Edge*> myPlatformShapes;
221 
223  std::set<std::string> myUnusableTypes;
224 
226  std::map<std::string, std::string> myKnownCompoundTypes;
227 
242  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
243 
244 
257  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
258  const std::vector<long long int>& passed, NBNetBuilder& nb);
259 
261  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
262 
264  std::map<NBNode*, std::pair<double, double> >
265  getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
266 
267 protected:
268  static const double MAXSPEED_UNGIVEN;
269  static const long long int INVALID_ID;
270 
275  friend class NodesHandler;
276  class NodesHandler : public SUMOSAXHandler {
277  public:
283  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
284  CompareNodes>& uniqueNodes,
285  const OptionsCont& cont);
286 
287 
289  ~NodesHandler() override;
290 
291 
292  protected:
294 
295 
303  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
304 
305 
312  void myEndElement(int element) override;
314 
315 
316  private:
317 
319  std::map<long long int, NIOSMNode*>& myToFill;
320 
322  long long int myLastNodeID;
323 
326 
329 
331  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
332 
334  const bool myImportElevation;
335 
338 
339 
340  private:
342  NodesHandler(const NodesHandler& s);
343 
346 
347  };
348 
349 
354  class EdgesHandler : public SUMOSAXHandler {
355  public:
361  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
362  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes);
363 
364 
366  ~EdgesHandler() override;
367 
368 
369  protected:
371 
372 
380  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
381 
382 
389  void myEndElement(int element) override;
391 
392 
393  private:
395  const std::map<long long int, NIOSMNode*>& myOSMNodes;
396 
398  std::map<long long int, Edge*>& myEdgeMap;
399 
401  std::map<long long int, Edge*>& myPlatformShapesMap;
402 
405 
407  std::vector<int> myParentElements;
408 
410  std::map<std::string, double> mySpeedMap;
411 
412  private:
414  EdgesHandler(const EdgesHandler& s);
415 
418 
419  };
420 
427  public:
433  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
434  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
435  const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
436  const OptionsCont& oc);
437 
438 
440  ~RelationHandler() override;
441 
442 
443  protected:
445 
446 
454  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
455 
456 
463  void myEndElement(int element) override;
465 
466 
467  private:
469  const std::map<long long int, NIOSMNode*>& myOSMNodes;
470 
472  const std::map<long long int, Edge*>& myOSMEdges;
473 
475  const std::map<long long int, Edge*>& myPlatformShapes;
476 
479 
482 
484  long long int myCurrentRelation;
485 
487  std::vector<int> myParentElements;
488 
491 
493  long long int myFromWay;
494 
496  long long int myToWay;
497 
499  long long int myViaNode;
500  long long int myViaWay;
501 
502 
505 
515  RESTRICTION_UNKNOWN
516  };
518 
520  void resetValues();
521 
523  bool checkEdgeRef(long long int ref) const;
524 
526  bool applyRestriction() const;
527 
529  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
530 
531  private:
534 
537 
539  std::vector<long long int> myStops;
540 
541 
542  struct NIIPTPlatform {
543  long long int ref;
544  bool isWay;
545  };
546 
548  std::vector<NIIPTPlatform> myPlatforms;
549 
551  std::vector<long long int> myWays;
552 
555 
557  bool myIsRoute;
558 
561 
563  std::string myName;
564 
566  std::string myRef;
567  };
568 
569 };
570 
571 
572 #endif
573 
574 /****************************************************************************/
575 
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.
std::map< long long int, Edge * > & myPlatformShapesMap
A map of built 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.
NBPTLineCont * myNBPTLineCont
PT Line container to be filled.
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
vehicle is a not electrified rail
A container for traffic light definitions and built programs.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:71
vehicle is a light rail
long long int myCurrentRelation
The currently parsed relation.
NIOSMNode(long long int _id, double _lon, double _lat)
std::vector< NIIPTPlatform > myPlatforms
bus stop platforms
std::vector< long long int > myStops
bus stop references
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
std::vector< long long int > myWays
ways in pt line references
const OptionsCont & myOptionsCont
the options cont
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 ...
const std::map< long long int, Edge * > & myPlatformShapes
The previously parsed platform shapes.
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.
bool ptStopPosition
Whether this is a public transport stop position.
Encapsulated SAX-Attributes.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
NIOSMNode & operator=(const NIOSMNode &s)=delete
invalidated assignment operator
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
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
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...
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
vehicle is a bus
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.
bool myCurrentIsPlatform
Information whether this is a pt platform.
long long int myToWay
the destination way for the current restriction
bool myIsRoute
indicates whether current relation is a route
int myLayer
Information about the relative z-ordering of ways.
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
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.
bool myIsStopArea
indicates whether current relation is a pt stop area
static const long long int INVALID_ID
bool myCurrentIsRoad
Information whether this is a road.
Edge * myCurrentEdge
The currently built edge.
std::map< long long int, Edge * > myPlatformShapes
the map from OSM way ids to platform shapes
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
SVCPermissions permissions
type of pt stop
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
bool myIsPTRoute
indicates whether current relation is a pt route
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
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.