60 #ifdef CHECK_MEMORY_LEAKS
62 #endif // CHECK_MEMORY_LEAKS
111 importer.
load(oc, nb);
124 for (std::map<long long int, Edge*>::iterator i =
myEdges.begin(); i !=
myEdges.end(); ++i) {
133 if (!oc.
isSet(
"osm-files")) {
141 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
144 WRITE_ERROR(
"Could not open osm-file '" + *file +
"'.");
147 nodesHandler.setFileName(*file);
156 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
165 if (!oc.
getBool(
"osm.skip-duplicates-check")) {
168 std::set<const Edge*, CompareEdges> dupsFinder;
169 for (std::map<long long int, Edge*>::iterator it =
myEdges.begin(); it !=
myEdges.end();) {
170 if (dupsFinder.count(it->second) > 0) {
175 dupsFinder.insert(it->second);
186 std::map<long long int, int> nodeUsage;
188 for (std::map<long long int, Edge*>::const_iterator i =
myEdges.begin(); i !=
myEdges.end(); ++i) {
189 Edge* e = (*i).second;
192 if (nodeUsage.find(*j) == nodeUsage.end()) {
195 nodeUsage[*j] = nodeUsage[*j] + 1;
199 for (std::map<long long int, NIOSMNode*>::const_iterator nodesIt =
myOSMNodes.begin(); nodesIt !=
myOSMNodes.end(); ++nodesIt) {
200 if (nodesIt->second->tlsControlled) {
203 nodeUsage[nodesIt->first] += 1;
211 for (std::map<long long int, Edge*>::iterator i =
myEdges.begin(); i !=
myEdges.end(); ++i) {
212 Edge* e = (*i).second;
225 std::vector<long long int> passed;
227 passed.push_back(*j);
230 running =
insertEdge(e, running, currentFrom, currentTo, passed, nb);
231 currentFrom = currentTo;
238 insertEdge(e, running, currentFrom, last, passed, nb);
244 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
277 if (!tlsc.
insert(tlDef)) {
290 const std::vector<long long int>& passed,
NBNetBuilder& nb) {
297 if (from == 0 || to == 0) {
298 WRITE_ERROR(
"Discarding edge " +
id +
" because the nodes could not be built.");
308 assert(passed.size() >= 2);
309 std::vector<long long int> geom(passed);
312 index =
insertEdge(e, index, from, intermediate, geom, nb);
314 return insertEdge(e, index, intermediate, to, geom, nb);
316 const int newIndex = index + 1;
321 for (std::vector<long long int>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
325 WRITE_ERROR(
"Unable to project coordinates for edge " +
id +
".");
332 if (!tc.
knows(type)) {
340 std::vector<std::string> types;
342 std::string t = tok.
next();
344 if (std::find(types.begin(), types.end(), t) == types.end()) {
347 }
else if (tok.
size() > 1) {
348 WRITE_WARNING(
"Discarding unknown compound \"" + t +
"\" in type \"" + type +
"\" (first occurence for edge \"" +
id +
"\").");
351 if (types.size() == 0) {
352 WRITE_WARNING(
"Discarding unusable type \"" + type +
"\" (first occurence for edge \"" +
id +
"\").");
357 if (tc.
knows(newType)) {
370 bool defaultIsOneWay =
false;
373 for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
390 WRITE_WARNING(
"Discarding compound type \"" + newType +
"\" (first occurence for edge \"" +
id +
"\").");
394 WRITE_MESSAGE(
"Adding new type \"" + type +
"\" (first occurence for edge \"" +
id +
"\").");
395 tc.
insert(newType, numLanes, maxSpeed, prio, permissions, width, defaultIsOneWay, sidewalkWidth, bikelaneWidth);
396 for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
422 bool addForward =
true;
423 bool addBackward =
true;
437 if (addForward && !addBackward) {
439 }
else if (!addForward && addBackward) {
447 numLanesForward = (int)std::ceil(e->
myNoLanes / 2.0);
449 numLanesBackward = e->
myNoLanes - numLanesForward;
452 numLanesForward =
MAX2(1, numLanesForward);
453 numLanesBackward =
MAX2(1, numLanesBackward);
456 WRITE_WARNING(
"Skipping edge '" +
id +
"' because it has zero lanes.");
481 numLanesBackward = 1;
495 numLanesBackward = 1;
501 assert(numLanesForward > 0);
521 assert(numLanesBackward > 0);
548 std::map<long long int, NIOSMNode*>& toFill,
549 std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
550 bool importElevation) :
554 myIsInValidNodeTag(false),
556 myUniqueNodes(uniqueNodes),
557 myImportElevation(importElevation)
569 if (myHierarchyLevel != 2) {
575 if (action ==
"delete") {
582 if (myToFill.find(
id) == myToFill.end()) {
607 myIsInValidNodeTag =
true;
609 std::set<NIOSMNode*, CompareNodes>::iterator similarNode =
myUniqueNodes.find(toAdd);
614 toAdd = *similarNode;
617 myToFill[id] = toAdd;
621 if (myHierarchyLevel != 3) {
622 WRITE_ERROR(
"Tag element on wrong XML hierarchy level.");
628 if (key ==
"highway" || key ==
"ele" || key ==
"crossing") {
630 if (key ==
"highway" && value.find(
"traffic_signal") != std::string::npos) {
631 myToFill[myLastNodeID]->tlsControlled =
true;
632 }
else if (key ==
"crossing" && value.find(
"traffic_signals") != std::string::npos) {
633 myToFill[myLastNodeID]->tlsControlled =
true;
634 }
else if (myImportElevation && key ==
"ele") {
638 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in node '" +
651 myIsInValidNodeTag =
false;
661 const std::map<long long int, NIOSMNode*>& osmNodes,
662 std::map<long long int, Edge*>& toFill) :
684 myParentElements.push_back(element);
690 if (action ==
"delete") {
698 myCurrentEdge =
new Edge(
id);
705 std::map<long long int, NIOSMNode*>::const_iterator node =
myOSMNodes.find(ref);
710 ref = node->second->id;
711 if (myCurrentEdge->myCurrentNodes.size() == 0 ||
712 myCurrentEdge->myCurrentNodes.back() != ref) {
713 myCurrentEdge->myCurrentNodes.push_back(ref);
719 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_WAY) {
720 if (myCurrentEdge == 0) {
727 const std::string cyclewaySpec = key.substr(9);
729 if (cyclewaySpec ==
"right") {
730 myCurrentEdge->myCyclewayType = (
WayType)(myCurrentEdge->myCyclewayType |
WAY_FORWARD);
731 }
else if (cyclewaySpec ==
"left") {
733 }
else if (cyclewaySpec ==
"both") {
734 myCurrentEdge->myCyclewayType = (
WayType)(myCurrentEdge->myCyclewayType |
WAY_BOTH);
738 if ((myCurrentEdge->myCyclewayType &
WAY_BOTH) != 0) {
740 myCurrentEdge->myCyclewayType = (
WayType)(myCurrentEdge->myCyclewayType & !
WAY_UNKNOWN);
744 const std::string buswaySpec = key.substr(7);
746 if (buswaySpec ==
"right") {
748 }
else if (buswaySpec ==
"left") {
750 }
else if (buswaySpec ==
"both") {
751 myCurrentEdge->myBuswayType = (
WayType)(myCurrentEdge->myBuswayType |
WAY_BOTH);
763 if (key ==
"highway" || key ==
"railway" || key ==
"waterway" || key ==
"cycleway" || key ==
"busway") {
764 myCurrentEdge->myCurrentIsRoad =
true;
766 if (key ==
"cycleway") {
769 }
else if (value ==
"opposite_track") {
771 }
else if (value ==
"opposite_lane") {
776 if (key ==
"busway") {
779 }
else if (value ==
"opposite_track") {
781 }
else if (value ==
"opposite_lane") {
788 const std::string singleTypeID = key +
"." + value;
789 if (myCurrentEdge->myHighWayType !=
"") {
793 types.push_back(singleTypeID);
796 myCurrentEdge->myHighWayType = singleTypeID;
798 }
else if (key ==
"lanes") {
804 std::vector<std::string> list = st.
getVector();
805 if (list.size() >= 2) {
808 for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) {
810 minLanes =
MIN2(minLanes, numLanes);
812 myCurrentEdge->myNoLanes = minLanes;
813 WRITE_WARNING(
"Using minimum lane number from list (" + value +
") for edge '" +
toString(myCurrentEdge->id) +
"'.");
815 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
816 toString(myCurrentEdge->id) +
"'.");
820 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
821 toString(myCurrentEdge->id) +
"'.");
823 }
else if (key ==
"lanes:forward") {
827 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
828 toString(myCurrentEdge->id) +
"'.");
830 }
else if (key ==
"lanes:backward") {
835 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
836 toString(myCurrentEdge->id) +
"'.");
838 }
else if (key ==
"maxspeed") {
839 if (mySpeedMap.find(value) != mySpeedMap.end()) {
840 myCurrentEdge->myMaxSpeed = mySpeedMap[value];
847 conversion = 1.609344;
852 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
853 toString(myCurrentEdge->id) +
"'.");
856 }
else if (key ==
"junction") {
857 if ((value ==
"roundabout") && (myCurrentEdge->myIsOneWay ==
"")) {
858 myCurrentEdge->myIsOneWay =
"yes";
860 }
else if (key ==
"oneway") {
861 myCurrentEdge->myIsOneWay = value;
862 }
else if (key ==
"name") {
863 myCurrentEdge->streetName = value;
864 }
else if (key ==
"tracks") {
867 myCurrentEdge->myIsOneWay =
"false";
869 myCurrentEdge->myIsOneWay =
"true";
872 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
873 toString(myCurrentEdge->id) +
"'.");
882 myParentElements.pop_back();
884 if (myCurrentEdge != 0 && myCurrentEdge->myCurrentIsRoad) {
885 myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
887 delete myCurrentEdge;
898 const std::map<long long int, NIOSMNode*>& osmNodes,
899 const std::map<long long int, Edge*>& osmEdges) :
902 myOSMEdges(osmEdges) {
913 myIsRestriction =
false;
918 myRestrictionType = RESTRICTION_UNKNOWN;
924 myParentElements.push_back(element);
930 if (action ==
"delete" || !ok) {
945 if (memberType ==
"way" && checkEdgeRef(ref)) {
947 }
else if (memberType ==
"node") {
954 }
else if (role ==
"from" && checkEdgeRef(ref)) {
956 }
else if (role ==
"to" && checkEdgeRef(ref)) {
966 if (key ==
"type" || key ==
"restriction") {
968 if (key ==
"type" && value ==
"restriction") {
969 myIsRestriction =
true;
972 if (key ==
"restriction") {
975 if (value.substr(0, 5) ==
"only_") {
976 myRestrictionType = RESTRICTION_ONLY;
977 }
else if (value.substr(0, 3) ==
"no_") {
978 myRestrictionType = RESTRICTION_NO;
980 WRITE_WARNING(
"Found unknown restriction type '" + value +
"' in relation '" +
toString(myCurrentRelation) +
"'");
991 if (myOSMEdges.find(ref) != myOSMEdges.end()) {
1002 myParentElements.pop_back();
1004 if (myIsRestriction) {
1007 if (myRestrictionType == RESTRICTION_UNKNOWN) {
1008 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown type.");
1012 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown from-way.");
1016 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown to-way.");
1020 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown via.");
1023 if (ok && !applyRestriction()) {
1045 WRITE_WARNING(
"from-edge of restriction relation could not be determined");
1049 WRITE_WARNING(
"to-edge of restriction relation could not be determined");
1052 if (myRestrictionType == RESTRICTION_ONLY) {
1059 WRITE_WARNING(
"direction of restriction relation could not be determined");
1068 const std::string prefix =
toString(wayRef);
1069 const std::string backPrefix =
"-" + prefix;
1072 for (EdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); ++it) {
1073 if (((*it)->getID().substr(0, prefix.size()) == prefix) ||
1074 ((*it)->getID().substr(0, backPrefix.size()) == backPrefix)) {
1080 WRITE_WARNING(
"Ambigous way reference '" + prefix +
"' in restriction relation");
const SUMOReal lat
The latitude the node is located at.
An internal definition of a loaded edge.
An internal representation of an OSM-node.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
const long long int id
The edge's id.
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
std::string streetName
The edge's street name.
NBTypeCont & getTypeCont()
Returns the type container.
const SUMOReal SUMO_const_laneWidth
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static bool transformCoordinates(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
const long long int id
The node's id.
static bool isReadable(std::string path)
Checks whether the given file is readable.
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
WayType myBuswayType
Information about the kind of busway along this road.
static SUMOReal _2SUMOReal(const E *const data)
A container for traffic light definitions and built programs.
~RelationHandler()
Destructor.
bool applyRestriction() const
try to apply the parsed restriction and return whether successful
void addSidewalk(SUMOReal width)
add a pedestrian sidewalk of the given width and shift existing connctions
NIImporter_OpenStreetMap()
void myEndElement(int element)
Called when a closing tag occurs.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given ...
void myEndElement(int element)
Called when a closing tag occurs.
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
SAX-handler base for SUMO-files.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SUMOReal getWidth(const std::string &type) const
Returns the lane width for the given type [m].
#define WRITE_WARNING(msg)
std::string joinToStringSorting(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
static OptionsCont & getOptions()
Retrieves the options.
SUMOReal ele
The elevation of this node.
NBNode * node
the NBNode that was instantiated
PositionVector reverse() const
static const SUMOReal MAXSPEED_UNGIVEN
SUMOReal getSidewalkWidth(const std::string &type) const
Returns the lane width for a sidewalk to be added [m].
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.
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges.
int myNoLanesForward
number of lanes in forward direction or 0 if unknown, negative if backwards lanes are meant ...
~EdgesHandler()
Destructor.
bool addEdge2EdgeConnection(NBEdge *dest)
Adds a connection to another edge.
const Position & getPosition() const
Returns the position of this node.
RelationHandler(const std::map< long long int, NIOSMNode * > &osmNodes, const std::map< long long int, Edge * > &osmEdges)
Constructor.
void load(const OptionsCont &oc, NBNetBuilder &nb)
SUMOReal getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
void setFileName(const std::string &name)
Sets the current file name.
SUMOReal getBikeLaneWidth(const std::string &type) const
Returns the lane width for a bike lane to be added [m].
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.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Encapsulated SAX-Attributes.
static StringBijection< TrafficLightType > TrafficLightTypes
A point in 2D or 3D with translation and scaling methods.
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
NBEdgeCont & getEdgeCont()
Returns the edge container.
int getPriority(const std::string &type) const
Returns the priority for the given type.
void myEndElement(int element)
Called when a closing tag occurs.
Storage for edges, including some functionality operating on multiple edges.
#define PROGRESS_BEGIN_MESSAGE(msg)
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
bool knows(const std::string &type) const
Returns whether the named type is in the container.
~NIImporter_OpenStreetMap()
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
void removeFromConnections(NBEdge *toEdge, int fromLane=-1, int toLane=-1, bool tryLater=false)
Removes the specified connection(s)
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
void insert(const std::string &id, int numLanes, SUMOReal maxSpeed, int prio, SVCPermissions permissions, SUMOReal width, bool oneWayIsDefault, SUMOReal sidewalkWidth, SUMOReal bikeLaneWidth)
Adds a type into the list.
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
std::vector< std::string > getVector()
int myNoLanes
number of lanes, or -1 if unknown
void push_back(const PositionVector &p)
Appends all positions from the given vector.
void addBikeLane(SUMOReal width)
add a bicycle lane of the given width and shift existing connctions
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
static int _2int(const E *const data)
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.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
EdgesHandler(const std::map< long long int, NIOSMNode * > &osmNodes, std::map< long long int, Edge * > &toFill)
Constructor.
const SUMOReal lon
The longitude the node is located at.
NBNodeCont & getNodeCont()
Returns the node container.
Instance responsible for building networks.
bool getShallBeDiscarded(const std::string &type) const
Returns the information whether edges of this type shall be discarded.
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
std::map< std::string, SUMOReal > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
A storage for options typed value containers)
bool copyRestrictionsAndAttrs(const std::string &fromId, const std::string &toId)
Copy restrictions to a type.
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
NBTrafficLightLogicCont & getTLLogicCont()
Returns the traffic light logics container.
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
NBEdge * findEdgeRef(long long int wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
void resetValues()
reset members to their defaults for parsing a new relation
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
T get(const std::string &str) const
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
std::string myHighWayType
The type, stored in "highway" key.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Importer for networks stored in OpenStreetMap format.
static const long long int INVALID_ID
bool myCurrentIsRoad
Information whether this is a road.
bool operator()(const Edge *e1, const Edge *e2) const
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
void push_back_noDoublePos(const Position &p)
~NodesHandler()
Destructor.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Container for nodes during the netbuilding process.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
#define PROGRESS_DONE_MESSAGE()
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
A traffic light logics which must be computed (only nodes/edges are given)
#define WRITE_MESSAGE(msg)
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
A storage for available types of edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.