SUMO - Simulation of Urban MObility
NIImporter_OpenStreetMap.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // Importer for networks stored in OpenStreetMap format
20 /****************************************************************************/
21 #ifndef NIImporter_OpenStreetMap_h
22 #define NIImporter_OpenStreetMap_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <map>
35 #include <netbuild/NBPTPlatform.h>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class NBEdge;
42 class NBEdgeCont;
43 class NBNetBuilder;
44 class NBNode;
45 class NBNodeCont;
47 class NBTypeCont;
48 class OptionsCont;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
60 public:
72  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
73 
74 
75 protected:
78  struct NIOSMNode {
79  NIOSMNode(long long int _id, double _lon, double _lat)
80  :
81  id(_id), lon(_lon), lat(_lat), ele(0),
82  tlsControlled(false),
83  railwayCrossing(false),
84  railwaySignal(false),
85  railwayBufferStop(false),
86  ptStopPosition(false), ptStopLength(0), name(""),
88  node(0) { }
89 
91  const long long int id;
93  const double lon;
95  const double lat;
97  double ele;
109  double ptStopLength;
111  std::string name;
116 
117  private:
119  NIOSMNode& operator=(const NIOSMNode& s) = delete;
120 
121 
122  };
123 
127  enum WayType {
128  WAY_NONE = 0,
133  };
134 
135  enum ParkingType {
144  };
145 
146 
149  struct Edge : public Parameterised {
150 
151  explicit Edge(long long int _id)
152  :
153  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
154  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
155  myBuswayType(WAY_NONE), // buslanes are always built when declared
156  mySidewalkType(WAY_UNKNOWN), // building of extra lanes depends on sidewalkWidth of loaded typemap
157  myParkingType(PARKING_NONE), // parking areas exported optionally
158  myLayer(0), // layer is non-zero only in conflict areas
159  myCurrentIsRoad(false),
160  myCurrentIsPlatform(false) { }
161 
162 
164  const long long int id;
166  std::string streetName;
172  double myMaxSpeed;
174  std::string myHighWayType;
176  std::string myIsOneWay;
186  int myLayer;
188  std::vector<long long int> myCurrentNodes;
193 
194  private:
196  Edge& operator=(const Edge& s) = delete;
197 
198 
199  };
200 
201 
203 
205 
206  void load(const OptionsCont& oc, NBNetBuilder& nb);
207 
208 private:
212  class CompareNodes {
213  public:
214  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
215  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
216  }
217  };
218 
219 
221  static const std::string compoundTypeSeparator;
222 
224 
228  std::map<long long int, NIOSMNode*> myOSMNodes;
229 
231  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
232 
233 
235  std::map<long long int, Edge*> myEdges;
236 
238  std::map<long long int, Edge*> myPlatformShapes;
239 
241  std::set<std::string> myUnusableTypes;
242 
244  std::map<std::string, std::string> myKnownCompoundTypes;
245 
260  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
261 
262 
275  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
276  const std::vector<long long int>& passed, NBNetBuilder& nb);
277 
279  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
280 
282  std::map<NBNode*, std::pair<double, double> >
283  getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
284 
285 protected:
286  static const double MAXSPEED_UNGIVEN;
287  static const long long int INVALID_ID;
288 
293  friend class NodesHandler;
294  class NodesHandler : public SUMOSAXHandler {
295  public:
301  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
302  CompareNodes>& uniqueNodes,
303  const OptionsCont& cont);
304 
305 
307  ~NodesHandler() override;
308 
309 
310  protected:
312 
313 
321  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
322 
323 
330  void myEndElement(int element) override;
332 
333 
334  private:
335 
337  std::map<long long int, NIOSMNode*>& myToFill;
338 
340  long long int myLastNodeID;
341 
344 
347 
349  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
350 
352  const bool myImportElevation;
353 
356 
357 
358  private:
360  NodesHandler(const NodesHandler& s);
361 
364 
365  };
366 
367 
372  class EdgesHandler : public SUMOSAXHandler {
373  public:
379  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
380  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes);
381 
382 
384  ~EdgesHandler() override;
385 
386 
387  protected:
389 
390 
398  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
399 
400 
407  void myEndElement(int element) override;
409 
410 
411  private:
413  const std::map<long long int, NIOSMNode*>& myOSMNodes;
414 
416  std::map<long long int, Edge*>& myEdgeMap;
417 
419  std::map<long long int, Edge*>& myPlatformShapesMap;
420 
423 
425  std::vector<int> myParentElements;
426 
428  std::map<std::string, double> mySpeedMap;
429 
432 
433  private:
435  EdgesHandler(const EdgesHandler& s);
436 
439 
440  };
441 
448  public:
454  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
455  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
456  const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
457  const OptionsCont& oc);
458 
459 
461  ~RelationHandler() override;
462 
463 
464  protected:
466 
467 
475  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
476 
477 
484  void myEndElement(int element) override;
486 
487 
488  private:
490  const std::map<long long int, NIOSMNode*>& myOSMNodes;
491 
493  const std::map<long long int, Edge*>& myOSMEdges;
494 
496  const std::map<long long int, Edge*>& myPlatformShapes;
497 
500 
503 
505  long long int myCurrentRelation;
506 
508  std::vector<int> myParentElements;
509 
512 
514  long long int myFromWay;
515 
517  long long int myToWay;
518 
520  long long int myViaNode;
521  long long int myViaWay;
522 
523 
526 
536  RESTRICTION_UNKNOWN
537  };
539 
541  void resetValues();
542 
544  bool checkEdgeRef(long long int ref) const;
545 
547  bool applyRestriction() const;
548 
550  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
551 
552  private:
555 
558 
560  std::vector<long long int> myStops;
561 
562 
563  struct NIIPTPlatform {
564  long long int ref;
565  bool isWay;
566  };
567 
569  std::vector<NIIPTPlatform> myPlatforms;
570 
572  std::vector<long long int> myWays;
573 
576 
578  bool myIsRoute;
579 
581  std::string myPTRouteType;
582 
584  std::string myName;
585 
587  std::string myRef;
588 
591 
593  std::string myNightService;
594  };
595 
596 };
597 
598 
599 #endif
600 
601 /****************************************************************************/
602 
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.
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...
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:65
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.
bool railwaySignal
Whether this is a railway (main) signal.
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)
bool myAllAttributes
whether additional way attributes shall be added to the edge
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.
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
NIOSMNode & operator=(const NIOSMNode &s)=delete
invalidated assignment operator
int myParkingType
Information about road-side parking.
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:44
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 railwayBufferStop
Whether this is a railway buffer stop.
vehicle is a bus
bool tlsControlled
Whether this is a tls controlled junction.
WayType mySidewalkType
Information about the kind of sidwalk along this road.
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:109
std::string myPTRouteType
indicates whether current relation is a pt route
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
A storage for options typed value containers)
Definition: OptionsCont.h:92
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.
int myInterval
service interval of the pt line in seconds
Represents a single node (junction) during network building.
Definition: NBNode.h:68
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.
std::string myNightService
night service information of the pt line
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:60
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:55
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.