Eclipse 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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Importer for networks stored in OpenStreetMap format
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <string>
28 #include <map>
32 #include <netbuild/NBPTPlatform.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class NBEdge;
39 class NBEdgeCont;
40 class NBNetBuilder;
41 class NBNode;
42 class NBNodeCont;
44 class NBTypeCont;
45 class OptionsCont;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
57 public:
69  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
70 
71 protected:
74  struct NIOSMNode {
75  NIOSMNode(long long int _id, double _lon, double _lat)
76  :
77  id(_id), lon(_lon), lat(_lat), ele(0),
78  tlsControlled(false),
79  railwayCrossing(false),
80  railwaySignal(false),
81  railwayBufferStop(false),
82  ptStopPosition(false), ptStopLength(0), name(""),
84  positionMeters(std::numeric_limits<double>::max()),
85  node(0) { }
86 
88  const long long int id;
90  const double lon;
92  const double lat;
94  double ele;
106  double ptStopLength;
108  std::string name;
112  std::string position;
117 
118  private:
120  NIOSMNode& operator=(const NIOSMNode& s) = delete;
121 
122 
123  };
124 
125 public:
127  static SUMOVehicleClass interpretTransportType(const std::string& type, NIOSMNode* toSet = nullptr);
128 
129 protected:
130 
131 
135  enum WayType {
136  WAY_NONE = 0,
140  WAY_UNKNOWN = 4
141  };
142 
143  enum ParkingType {
151  PARKING_DIAGONAL = 32
152  };
153 
154  enum ChangeType {
158  CHANGE_NO = 3
159  };
160 
163  class Edge : public Parameterised {
164  public:
165  explicit Edge(long long int _id) :
166  id(_id), myNoLanes(-1), myNoLanesForward(0),
169  myExtraAllowed(0),
171  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
172  myBuswayType(WAY_NONE), // buslanes are always built when declared
173  mySidewalkType(WAY_UNKNOWN), // building of extra lanes depends on sidewalkWidth of loaded typemap
174  myRailDirection(WAY_UNKNOWN), // store direction(s) of railway usage
175  myParkingType(PARKING_NONE), // parking areas exported optionally
178  myLayer(0), // layer is non-zero only in conflict areas
179  myCurrentIsRoad(false),
180  myCurrentIsPlatform(false),
182  { }
183 
184  virtual ~Edge() {}
185 
187  const long long int id;
189  std::string streetName;
191  std::string ref;
197  double myMaxSpeed;
205  std::string myHighWayType;
207  std::string myIsOneWay;
223  std::vector<SVCPermissions> myLaneUseForward;
224  std::vector<SVCPermissions> myLaneUseBackward;
226  int myLayer;
228  std::vector<long long int> myCurrentNodes;
236  std::vector<int> myTurnSignsForward;
237  std::vector<int> myTurnSignsBackward;
238 
239  private:
241  Edge& operator=(const Edge& s) = delete;
242  };
243 
244 
246 
248 
249  void load(const OptionsCont& oc, NBNetBuilder& nb);
250 
251 private:
255  class CompareNodes {
256  public:
257  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
258  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
259  }
260  };
261 
262 
264  static const std::string compoundTypeSeparator;
265 
266  class CompareEdges;
267 
271  std::map<long long int, NIOSMNode*> myOSMNodes;
272 
274  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
275 
276 
278  std::map<long long int, Edge*> myEdges;
279 
281  std::map<long long int, Edge*> myPlatformShapes;
282 
284  std::set<std::string> myUnusableTypes;
285 
287  std::map<std::string, std::string> myKnownCompoundTypes;
288 
291 
294 
297 
312  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
313 
314 
329  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
330  const std::vector<long long int>& passed, NBNetBuilder& nb,
331  const NBNode* first, const NBNode* last);
332 
334  void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
335 
337  std::map<NBNode*, std::pair<double, double> >
338  getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
339 
341  std::string usableType(const std::string& type, const std::string& id, NBTypeCont& tc);
342 
344  void extendRailwayDistances(Edge* e, NBTypeCont& tc);
345 
347  static double interpretDistance(NIOSMNode* node);
348 
349 protected:
350  static const double MAXSPEED_UNGIVEN;
351  static const long long int INVALID_ID;
352 
353  static void applyChangeProhibition(NBEdge* e, int changeProhibition);
354  void applyLaneUseInformation(NBEdge* e, const std::vector<SVCPermissions>& laneUse);
355  void applyTurnSigns(NBEdge* e, const std::vector<int>& turnSigns);
356 
361  class NodesHandler : public SUMOSAXHandler {
362  public:
368  NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
369  CompareNodes>& uniqueNodes,
370  const OptionsCont& cont);
371 
372 
374  ~NodesHandler() override;
375 
376  int getDuplicateNodes() const {
377  return myDuplicateNodes;
378  }
379 
380  protected:
382 
383 
391  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
392 
393 
400  void myEndElement(int element) override;
402 
403 
404  private:
405 
407  std::map<long long int, NIOSMNode*>& myToFill;
408 
410  long long int myLastNodeID;
411 
414 
417 
419  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
420 
422  const bool myImportElevation;
423 
426 
429 
430  private:
433 
436 
437  };
438 
439 
444  class EdgesHandler : public SUMOSAXHandler {
445  public:
451  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
452  std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes);
453 
454 
456  ~EdgesHandler() override;
457 
458 
459  protected:
461 
462 
470  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
471 
472 
479  void myEndElement(int element) override;
481 
482  double interpretSpeed(const std::string& key, std::string value);
483 
484  int interpretChangeType(const std::string& value) const;
485 
486  void interpretLaneUse(const std::string& value, SUMOVehicleClass svc, std::vector<SVCPermissions>& result) const;
487 
488  private:
490  const std::map<long long int, NIOSMNode*>& myOSMNodes;
491 
493  std::map<long long int, Edge*>& myEdgeMap;
494 
496  std::map<long long int, Edge*>& myPlatformShapesMap;
497 
500 
502  std::vector<int> myParentElements;
503 
505  std::map<std::string, double> mySpeedMap;
506 
510  std::set<std::string> myExtraAttributes;
511 
514 
515  private:
518 
521 
522  };
523 
530  public:
536  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
537  const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
538  const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
539  const OptionsCont& oc);
540 
541 
543  ~RelationHandler() override;
544 
545  protected:
547 
548 
556  void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
557 
558 
565  void myEndElement(int element) override;
567 
568 
569  private:
571  const std::map<long long int, NIOSMNode*>& myOSMNodes;
572 
574  const std::map<long long int, Edge*>& myOSMEdges;
575 
577  const std::map<long long int, Edge*>& myPlatformShapes;
578 
581 
584 
586  long long int myCurrentRelation;
587 
589  std::vector<int> myParentElements;
590 
593 
595  long long int myFromWay;
596 
598  long long int myToWay;
599 
601  long long int myViaNode;
602  long long int myViaWay;
603 
604 
607 
611  enum class RestrictionType {
613  ONLY,
615  NO,
617  UNKNOWN
618  };
620 
622  void resetValues();
623 
625  bool checkEdgeRef(long long int ref) const;
626 
628  bool applyRestriction() const;
629 
631  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
632 
633  private:
636 
639 
641  std::vector<long long int> myStops;
642 
644  std::set<long long int> myPlatformStops;
645 
646 
647  struct NIIPTPlatform {
648  long long int ref;
649  bool isWay;
650  };
651 
653  std::vector<NIIPTPlatform> myPlatforms;
654 
656  std::vector<long long int> myWays;
657 
660 
662  bool myIsRoute;
663 
665  std::string myPTRouteType;
666 
669 
671  std::string myName;
672 
674  std::string myRef;
675 
678 
680  std::string myNightService;
681 
683  std::map<long long int, long long int > myStopAreas;
684 
685  };
686 
687 };
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:91
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:58
Represents a single node (junction) during network building.
Definition: NBNode.h:66
A container for traffic light definitions and built programs.
A storage for available edgeTypes of edges.
Definition: NBTypeCont.h:52
Functor which compares two NIOSMNodes according to their coordinates.
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
An internal definition of a loaded edge.
WayType mySidewalkType
Information about the kind of sidwalk along this road.
bool myCurrentIsPlatform
Information whether this is a pt platform.
std::vector< SVCPermissions > myLaneUseForward
(optional) information about the permitted vehicle classes on each lane
bool myCurrentIsRoad
Information whether this is a road.
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
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
bool myCurrentIsElectrified
Information whether this is railway is electrified.
std::string ref
The edge's track name.
std::string myHighWayType
The type, stored in "highway" key.
const long long int id
The edge's id.
int myLayer
Information about the relative z-ordering of ways.
Edge & operator=(const Edge &s)=delete
invalidated assignment operator
SVCPermissions myExtraDisallowed
Extra permissions prohibited from tags instead of highway type.
std::vector< SVCPermissions > myLaneUseBackward
int myNoLanes
number of lanes, or -1 if unknown
std::vector< int > myTurnSignsForward
turning direction (arrows printed on the road)
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
int myParkingType
Information about road-side parking.
double myMaxSpeedBackward
maximum speed in km/h, or MAXSPEED_UNGIVEN
WayType myBuswayType
Information about the kind of busway along this road.
int myChangeForward
Information about change prohibitions (forward direction.
SVCPermissions myExtraAllowed
Extra permissions added from tags instead of highway type.
int myChangeBackward
Information about change prohibitions (backward direction.
std::string streetName
The edge's street name.
WayType myRailDirection
Information about the direction(s) of railway usage.
std::string myIsOneWay
Information whether this is an one-way road.
A class which extracts OSM-edges from a parsed OSM-file.
std::set< std::string > myExtraAttributes
extra attributes to import
Edge * myCurrentEdge
The currently built edge.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
EdgesHandler(const std::map< long long int, NIOSMNode * > &osmNodes, std::map< long long int, Edge * > &toFill, std::map< long long int, Edge * > &platformShapes)
Constructor.
int interpretChangeType(const std::string &value) const
bool myAllAttributes
whether additional way attributes shall be added to the edge
bool myImportBikeAccess
import bike path specific permissions and directions
void myEndElement(int element) override
Called when a closing tag occurs.
EdgesHandler & operator=(const EdgesHandler &s)
invalidated assignment operator
double interpretSpeed(const std::string &key, std::string value)
EdgesHandler(const EdgesHandler &s)
invalidated copy constructor
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
std::map< long long int, Edge * > & myPlatformShapesMap
A map of built edges.
std::map< std::string, double > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
std::vector< int > myParentElements
The element stack.
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
void interpretLaneUse(const std::string &value, SUMOVehicleClass svc, std::vector< SVCPermissions > &result) const
A class which extracts OSM-nodes from a parsed OSM-file.
int myHierarchyLevel
The current hierarchy level.
bool myIsInValidNodeTag
Hierarchy helper for parsing a node's tags.
const bool myImportElevation
whether elevation data should be imported
NodesHandler(const NodesHandler &s)
invalidated copy constructor
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, const OptionsCont &cont)
Contructor.
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
const OptionsCont & myOptionsCont
the options
void myEndElement(int element) override
Called when a closing tag occurs.
NodesHandler & operator=(const NodesHandler &s)
invalidated assignment operator
A class which extracts relevant relation information from a parsed OSM-file.
void myEndElement(int element) override
Called when a closing tag occurs.
const std::map< long long int, Edge * > & myPlatformShapes
The previously parsed platform shapes.
RelationHandler & operator=(const RelationHandler &s)
invalidated assignment operator
long long int myViaNode
the via node/way for the current restriction
bool myIsRestriction
whether the currently parsed relation is a restriction
std::vector< long long int > myWays
ways in pt line references
long long int myCurrentRelation
The currently parsed relation.
std::set< long long int > myPlatformStops
myStops which are actually platforms (in case there is no stop_position)
void resetValues()
reset members to their defaults for parsing a new relation
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const OptionsCont & myOptionsCont
the options cont
RestrictionType
whether the only allowed or the only forbidden connection is defined
@ ONLY
The only valid connection is declared.
@ NO
The only invalid connection is declared.
std::string myNightService
night service information of the pt line
std::string myPTRouteType
indicates whether current relation is a pt route
std::vector< long long int > myStops
bus stop references
NBPTLineCont * myNBPTLineCont
PT Line container to be filled.
std::vector< NIIPTPlatform > myPlatforms
bus stop platforms
bool myIsStopArea
indicates whether current relation is a pt stop area
bool myIsRoute
indicates whether current relation is a route
std::vector< int > myParentElements
The element stack.
RelationHandler(const std::map< long long int, NIOSMNode * > &osmNodes, const std::map< long long int, Edge * > &osmEdges, NBPTStopCont *nbptStopCont, const std::map< long long int, Edge * > &platfromShapes, NBPTLineCont *nbptLineCont, const OptionsCont &oc)
Constructor.
int myInterval
service interval of the pt line in minutes
RelationHandler(const RelationHandler &s)
invalidated copy constructor
std::map< long long int, long long int > myStopAreas
the map from stop area member to stop_area id
NBPTStopCont * myNBPTStopCont
The previously filled pt stop container.
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
long long int myFromWay
the origination way for the current restriction
long long int myToWay
the destination way for the current restriction
bool applyRestriction() const
try to apply the parsed restriction and return whether successful
NBEdge * findEdgeRef(long long int wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
Importer for networks stored in OpenStreetMap format.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< long long int > &passed, NBNetBuilder &nb, const NBNode *first, const NBNode *last)
Builds an NBEdge.
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
static const long long int INVALID_ID
static const double MAXSPEED_UNGIVEN
std::map< long long int, Edge * > myPlatformShapes
the map from OSM way ids to platform shapes
void load(const OptionsCont &oc, NBNetBuilder &nb)
void applyTurnSigns(NBEdge *e, const std::vector< int > &turnSigns)
bool myImportSidewalks
import sidewalks
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
void reconstructLayerElevation(double layerElevation, NBNetBuilder &nb)
reconstruct elevation from layer info
static SUMOVehicleClass interpretTransportType(const std::string &type, NIOSMNode *toSet=nullptr)
translate osm transport designations into sumo vehicle class
bool myImportLaneAccess
import lane specific access restrictions
bool myImportTurnSigns
import turning signals (turn:lanes) to guide connection building
std::map< std::string, std::string > myKnownCompoundTypes
The compound types that have already been mapped to other known types.
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
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...
static double interpretDistance(NIOSMNode *node)
read distance value from node and return value in m
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
void extendRailwayDistances(Edge *e, NBTypeCont &tc)
extend kilometrage data for all nodes along railway
std::string usableType(const std::string &type, const std::string &id, NBTypeCont &tc)
check whether the type is known or consists of known type compounds. return empty string otherwise
void applyLaneUseInformation(NBEdge *e, const std::vector< SVCPermissions > &laneUse)
static void applyChangeProhibition(NBEdge *e, int changeProhibition)
A storage for options typed value containers)
Definition: OptionsCont.h:89
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
An internal representation of an OSM-node.
SVCPermissions permissions
type of pt stop
NBNode * node
the NBNode that was instantiated
double positionMeters
position converted to m (using highest precision available)
std::string position
kilometrage/mileage
const long long int id
The node's id.
NIOSMNode & operator=(const NIOSMNode &s)=delete
invalidated assignment operator
bool tlsControlled
Whether this is a tls controlled junction.
double ptStopLength
The length of the pt stop.
NIOSMNode(long long int _id, double _lon, double _lat)
bool ptStopPosition
Whether this is a public transport stop position.
std::string name
The name of the node.
bool railwayCrossing
Whether this is a railway crossing.
double ele
The elevation of this node.
bool railwayBufferStop
Whether this is a railway buffer stop.
const double lon
The longitude the node is located at.
const double lat
The latitude the node is located at.
bool railwaySignal
Whether this is a railway (main) signal.