Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIImporter_OpenStreetMap.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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>
33
34
35// ===========================================================================
36// class declarations
37// ===========================================================================
38class NBEdge;
39class NBEdgeCont;
40class NBNetBuilder;
41class NBNode;
42class NBNodeCont;
44class NBTypeCont;
45class OptionsCont;
46
47
48// ===========================================================================
49// class definitions
50// ===========================================================================
57public:
69 static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
70
71protected:
72
76 enum WayType {
78 // technically possible
83 // recommended for routing
86 };
87
88
94
97 struct NIOSMNode : public Parameterised {
98 NIOSMNode(long long int _id, double _lon, double _lat)
99 :
100 id(_id), lon(_lon), lat(_lat), ele(0.),
101 tlsControlled(false),
102 pedestrianCrossing(false),
103 railwayCrossing(false),
105 railwayBufferStop(false),
106 ptStopPosition(false), ptStopLength(0), name(""),
108 positionMeters(std::numeric_limits<double>::max()),
110 node(nullptr) { }
111
113 const long long int id;
115 const double lon;
117 const double lat;
119 double ele;
135 std::string name;
139 std::string position;
146
147 private:
149 NIOSMNode& operator=(const NIOSMNode& s) = delete;
150
151
152 };
153
154public:
156 static SUMOVehicleClass interpretTransportType(const std::string& type, NIOSMNode* toSet = nullptr);
157
158protected:
159
160
171
178
179 enum class PlacementType {
180 NONE = 0,
181 LEFT_OF = 1,
182 RIGHT_OF = 2,
183 MIDDLE_OF = 3
184 };
185
188 class Edge : public Parameterised {
189 public:
191 struct DirLaneInfo {
192 int lanes = 0;
193 int busLanes = 0;
195 bool hasBusSpec = false;
196 bool hasExplicitDirBus = false;
197 };
198
199 explicit Edge(long long int _id) :
200 id(_id), myNoLanes(-1), myNoLanesBothWays(0),
207 myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
208 myBuswayType(WAY_NONE), // buslanes are always built when declared
209 mySidewalkType(WAY_UNKNOWN), // building of extra lanes depends on sidewalkWidth of loaded typemap
210 myRailDirection(WAY_UNKNOWN), // store direction(s) of railway usage
211 myParkingType(PARKING_NONE), // parking areas exported optionally
214 myLayer(0), // layer is non-zero only in conflict areas
215 myCurrentIsRoad(false),
216 myAmInRoundabout(false),
218 myPlacementLane(-1),
219 myWidth(-1)
220 { }
221
222 virtual ~Edge() {}
223
225 const long long int id;
227 std::string streetName;
229 std::string ref;
250 std::string myHighWayType;
252 std::string myIsOneWay;
268 std::vector<bool> myDesignatedLaneForward;
270 std::vector<bool> myDesignatedLaneBackward;
272 std::vector<SVCPermissions> myAllowedLaneForward;
274 std::vector<SVCPermissions> myAllowedLaneBackward;
276 std::vector<SVCPermissions> myDisallowedLaneForward;
278 std::vector<SVCPermissions> myDisallowedLaneBackward;
282 std::vector<long long int> myCurrentNodes;
292 std::map<std::string, std::string> myExtraTags;
294 std::vector<int> myTurnSignsForward;
295 std::vector<int> myTurnSignsBackward;
301 std::vector<double> myWidthLanesForward;
302 std::vector<double> myWidthLanesBackward;
303 double myWidth;
304
305 private:
307 Edge& operator=(const Edge& s) = delete;
308 };
309
310
312
314
315 void load(const OptionsCont& oc, NBNetBuilder& nb);
316
317private:
322 public:
323 bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
324 return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
325 }
326 };
327
328
330 static const std::string compoundTypeSeparator;
331
332 class CompareEdges;
333
337 std::map<long long int, NIOSMNode*> myOSMNodes;
338
340 std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
341
342
344 std::map<long long int, Edge*> myEdges;
345
347 std::map<long long int, Edge*> myPlatformShapes;
348
350 std::set<std::string> myUnusableTypes;
351
353 std::map<std::string, std::string> myKnownCompoundTypes;
354
357
360
363
366
369
372
375
378
381
384
386 static bool myAllAttributes;
387
389 static std::set<std::string> myExtraAttributes;
390
405 NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
406
407
422 int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
423 const std::vector<long long int>& passed, NBNetBuilder& nb,
424 const NBNode* first, const NBNode* last);
425
427 void reconstructLayerElevation(double layerElevation, NBNetBuilder& nb);
428
430 std::map<NBNode*, std::pair<double, double> >
431 getNeighboringNodes(NBNode* node, double maxDist, const std::set<NBNode*>& knownElevation);
432
434 std::string usableType(const std::string& type, const std::string& id, NBTypeCont& tc);
435
438
440 static double interpretDistance(NIOSMNode* node);
441
442protected:
443 static const double MAXSPEED_UNGIVEN;
444 static const long long int INVALID_ID;
445
446 static void applyChangeProhibition(NBEdge* e, int changeProhibition);
458
459 static void mergeTurnSigns(std::vector<int>& signs, std::vector<int> signs2);
460 void applyTurnSigns(NBEdge* e, const std::vector<int>& turnSigns);
461
467 public:
473 NodesHandler(std::map<long long int, NIOSMNode*>& toFill, std::set<NIOSMNode*,
474 CompareNodes>& uniqueNodes,
475 const OptionsCont& cont);
476
477
479 ~NodesHandler() override;
480
481 int getDuplicateNodes() const {
482 return myDuplicateNodes;
483 }
484
487 }
488
489 protected:
491
492
500 void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
501
502
509 void myEndElement(int element) override;
511
512
513 private:
515 std::map<long long int, NIOSMNode*>& myToFill;
516
518 std::string myLastNodeID;
519
522
524 std::string myRailwayRef;
525
528
530 std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
531
534
537
540
543
544 private:
547
550
551 };
552
553
559 public:
565 EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
566 std::map<long long int, Edge*>& toFill, std::map<long long int, Edge*>& platformShapes,
567 const NBTypeCont& tc);
568
569
571 ~EdgesHandler() override;
572
573
574 protected:
576
577
585 void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
586
587
594 void myEndElement(int element) override;
596
597 double interpretSpeed(const std::string& key, std::string value);
598
599 int interpretChangeType(const std::string& value) const;
600
601 void interpretLaneUse(const std::string& value, SUMOVehicleClass svc, const bool forward) const;
602
603 bool interpretPlacement(const std::string& value, NIImporter_OpenStreetMap::PlacementType& placement, int& laneIndex) const;
604
605 int parseBusLaneCount(const std::string& key, const std::string& value) const;
606
607 void resetWayStaging();
608
609 void resolveEdgeTags();
610
611 void addType(const std::string& singleTypeID);
612
613
614 private:
617 std::string value;
620 };
621
623 const std::map<long long int, NIOSMNode*>& myOSMNodes;
624
626 std::map<long long int, Edge*>& myEdgeMap;
627
629 std::map<long long int, Edge*>& myPlatformShapesMap;
630
632 Edge* myCurrentEdge = nullptr;
633
635 std::vector<double> myUnsuffixedWidthLanes;
636 std::vector<int> myUnsuffixedTurnSigns;
637 std::vector<StagedLaneUse> myUnsuffixedLaneUse;
644
646 std::map<std::string, double> mySpeedMap;
647
649
650 private:
653
656
657 };
658
665 public:
671 RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
672 const std::map<long long int, Edge*>& osmEdges, NBPTStopCont* nbptStopCont,
673 const std::map<long long int, Edge*>& platfromShapes, NBPTLineCont* nbptLineCont,
674 const OptionsCont& oc);
675
676
679
680 protected:
682
683
691 void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
692
693
700 void myEndElement(int element) override;
702
703
704 private:
706 const std::map<long long int, NIOSMNode*>& myOSMNodes;
707
709 const std::map<long long int, Edge*>& myOSMEdges;
710
712 const std::map<long long int, Edge*>& myPlatformShapes;
713
716
719
721 long long int myCurrentRelation;
722
725
728
730 long long int myFromWay;
731
733 long long int myToWay;
734
736 long long int myViaNode;
737 long long int myViaWay;
738
740 long long int myStation;
741
744
748 enum class RestrictionType {
750 ONLY,
752 NO,
754 UNKNOWN
755 };
757
759 void resetValues();
760
762 bool checkEdgeRef(long long int ref) const;
763
765 bool applyRestriction() const;
766
768 NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
769
770 private:
773
776
778 std::vector<long long int> myStops;
779
781 std::set<long long int> myPlatformStops;
782
783
785 long long int ref;
786 bool isWay;
787 };
788
790 std::vector<NIIPTPlatform> myPlatforms;
791
793 std::vector<long long int> myWays;
794
797
800
802 std::string myPTRouteType;
803
806
808 std::string myName;
809
811 std::string myRef;
812
815
817 std::string myNightService;
818
820 std::map<long long int, long long int > myStopAreas;
821
822 };
823
824};
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition Option.h:42
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
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:92
Instance responsible for building networks.
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
Represents a single node (junction) during network building.
Definition NBNode.h:66
Container for public transport stops during the net building process.
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.
int myPlacementLane
1-based lane index for placement specification
std::vector< SVCPermissions > myDisallowedLaneBackward
(optional) information about additional disallowed SVCs on backward lane(s)
DirLaneInfo myDirForward
per-direction lane counts and bus/PSV lane metadata
std::map< std::string, std::string > myExtraTags
Additionally tagged information.
std::vector< double > myWidthLanesForward
Information on lane width.
WayType mySidewalkType
Information about the kind of sidwalk along this road.
int myNoLanesBothWays
explicitly tagged center two-way lane count, or 0 if unknown
Edge & operator=(const Edge &s)=delete
invalidated assignment operator
std::vector< SVCPermissions > myDisallowedLaneForward
(optional) information about additional disallowed SVCs on forward lane(s)
bool myCurrentIsRoad
Information whether this is a road.
WayType myCyclewayType
Information about the kind of cycleway along this road.
SVCPermissions myOnewayContraPermissions
Vehicle classes exempted from oneway restriction via oneway:<mode>=no.
double myMaxSpeed
resolved forward maximum speed in m/s, or MAXSPEED_UNGIVEN
std::string ref
The edge's track name.
std::vector< SVCPermissions > myAllowedLaneForward
(optional) information about additional allowed SVCs on forward lane(s)
std::string myHighWayType
The type, stored in "highway" key.
const long long int id
The edge's id.
bool myAmInRoundabout
Information whether this road is part of a roundabout.
int myLayer
Information about the relative z-ordering of ways.
bool myRoundaboutGuessExcluded
Way metadata that rules out an inferred roundabout.
int myRailDirection
Information about the direction(s) of railway usage.
std::vector< bool > myDesignatedLaneBackward
(optional) information about whether the backward lanes are designated to some SVCs
SVCPermissions myExtraDisallowed
Extra permissions prohibited from tags instead of highway type.
double myMaxSpeedBase
direction-neutral base maximum speed (maxspeed / maxspeed:type / zone:maxspeed) in m/s,...
std::vector< SVCPermissions > myAllowedLaneBackward
(optional) information about additional allowed SVCs on backward lane(s)
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
explicitly tagged backward maximum speed in m/s, 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.
PlacementType myPlacement
placement of the OSM way geometry relative to lanes
bool myIsCircularJunction
Whether OSM explicitly classifies the way as a circular junction.
std::vector< bool > myDesignatedLaneForward
(optional) information about whether the forward lanes are designated to some SVCs
std::string myIsOneWay
Information whether this is an one-way road.
A class which extracts OSM-edges from a parsed OSM-file.
void addType(const std::string &singleTypeID)
Edge * myCurrentEdge
The currently built edge.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
void interpretLaneUse(const std::string &value, SUMOVehicleClass svc, const bool forward) const
int interpretChangeType(const std::string &value) const
void myEndElement(int element) override
Called when a closing tag occurs.
bool interpretPlacement(const std::string &value, NIImporter_OpenStreetMap::PlacementType &placement, int &laneIndex) const
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::vector< double > myUnsuffixedWidthLanes
Per-way staging cleared on <way> and resolved in resolveEdgeTags()
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.
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag;.
int parseBusLaneCount(const std::string &key, const std::string &value) const
EdgesHandler & operator=(const EdgesHandler &s)
invalidated assignment operator
A class which extracts OSM-nodes from a parsed OSM-file.
int myHierarchyLevel
The current hierarchy level.
const bool myImportElevation
whether elevation data should be imported
std::string myLastNodeID
id of the currently parsed node
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 & operator=(const NodesHandler &s)
invalidated assignment operator
void myEndElement(int element) override
Called when a closing tag occurs.
NIOSMNode * myCurrentNode
the currently parsed node
StringVector myRailSignalRules
custom requirements for rail signal tagging
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.
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
SVCPermissions myRestrictionException
exceptions to the restriction currenlty being parsed
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
RelationHandler & operator=(const RelationHandler &s)
invalidated assignment operator
long long int myStation
the station node for the current stop_area
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
bool myImportCrossings
import crossings
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
WayType
details on the kind of sidewalk, cycleway, busway along this road
void applyLaneUse(NBEdge *e, NIImporter_OpenStreetMap::Edge *nie, const bool forward)
Applies lane use information from nie to e.
bool myOnewayDualSidewalk
import sidewalks
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
static bool myAllAttributes
whether additional way and node attributes shall be imported
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
int myPlacementSkippedNonExplicitOneWay
number of placement skips due to non-explicit oneway
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.
bool myETCS_movingBlock
whether ETCS signals default to moving block
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 std::set< std::string > myExtraAttributes
extra attributes to import
bool myImportBikeAccess
import bike path specific permissions and directions
bool myAnnotateDefaults
whether edges should carry information on the use of typemap defaults
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.
static void mergeTurnSigns(std::vector< int > &signs, std::vector< int > signs2)
void extendRailwayDistances(Edge *e, NBTypeCont &tc)
extend kilometrage data for all nodes along railway
int myPlacementSkippedAuxOppositeDirection
number of placement skips due to generated opposite-direction auxiliary edges
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
static void applyChangeProhibition(NBEdge *e, int changeProhibition)
A storage for options typed value containers)
Definition OptionsCont.h:92
An upper class for objects with additional parameters.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
unsigned node
Definition json.hpp:5639
Per-direction lane counts and bus/PSV lane metadata.
Deferred unsuffixed per-lane access entry resolved once oneway is final.
An internal representation of an OSM-node.
SVCPermissions permissions
type of pt stop
NIOSMNode & operator=(const NIOSMNode &s)=delete
invalidated assignment operator
int railwaySignal
Whether this is a railway (main) signal.
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.
bool pedestrianCrossing
Whether this is a pedestrian crossing.
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.
WayType myRailDirection
Information about the direction(s) of railway usage.