60 #ifdef CHECK_MEMORY_LEAKS
62 #endif // CHECK_MEMORY_LEAKS
111 importer.
load(oc, nb);
124 for (std::map<SUMOLong, Edge*>::iterator i =
myEdges.begin(); i !=
myEdges.end(); ++i) {
133 if (!oc.
isSet(
"osm-files")) {
143 tc.
insert(
"highway.trunk_link", 1, (
SUMOReal)(80. / 3.6), 10, WIDTH);
144 tc.
insert(
"highway.primary", 2, (
SUMOReal)(100. / 3.6), 9, WIDTH);
145 tc.
insert(
"highway.primary_link", 1, (
SUMOReal)(80. / 3.6), 8, WIDTH);
146 tc.
insert(
"highway.secondary", 2, (
SUMOReal)(100. / 3.6), 7, WIDTH);
147 tc.
insert(
"highway.secondary_link", 1, (
SUMOReal)(80. / 3.6), 6, WIDTH);
148 tc.
insert(
"highway.tertiary", 1, (
SUMOReal)(80. / 3.6), 6, WIDTH);
149 tc.
insert(
"highway.tertiary_link", 1, (
SUMOReal)(80. / 3.6), 5, WIDTH);
150 tc.
insert(
"highway.unclassified", 1, (
SUMOReal)(80. / 3.6), 5, WIDTH);
151 tc.
insert(
"highway.residential", 1, (
SUMOReal)(50. / 3.6), 4, WIDTH);
152 tc.
insert(
"highway.living_street", 1, (
SUMOReal)(10. / 3.6), 3, WIDTH);
155 tc.
insert(
"highway.services", 1, (
SUMOReal)(30. / 3.6), 1, WIDTH);
156 tc.
insert(
"highway.unsurfaced", 1, (
SUMOReal)(30. / 3.6), 1, WIDTH);
171 const bool oneWay = oc.
getBool(
"osm.railway.oneway-default");
184 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
187 WRITE_ERROR(
"Could not open osm-file '" + *file +
"'.");
190 nodesHandler.setFileName(*file);
199 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
208 if (!oc.
getBool(
"osm.skip-duplicates-check")) {
211 std::set<const Edge*, CompareEdges> dupsFinder;
212 for (std::map<SUMOLong, Edge*>::iterator it =
myEdges.begin(); it !=
myEdges.end();) {
213 if (dupsFinder.count(it->second) > 0) {
218 dupsFinder.insert(it->second);
229 std::map<SUMOLong, int> nodeUsage;
231 for (std::map<SUMOLong, Edge*>::const_iterator i =
myEdges.begin(); i !=
myEdges.end(); ++i) {
232 Edge* e = (*i).second;
235 if (nodeUsage.find(*j) == nodeUsage.end()) {
238 nodeUsage[*j] = nodeUsage[*j] + 1;
242 for (std::map<SUMOLong, NIOSMNode*>::const_iterator nodesIt =
myOSMNodes.begin(); nodesIt !=
myOSMNodes.end(); ++nodesIt) {
243 if (nodesIt->second->tlsControlled) {
246 nodeUsage[nodesIt->first] += 1;
254 for (std::map<SUMOLong, Edge*>::iterator i =
myEdges.begin(); i !=
myEdges.end(); ++i) {
255 Edge* e = (*i).second;
268 std::vector<SUMOLong> passed;
270 passed.push_back(*j);
273 running =
insertEdge(e, running, currentFrom, currentTo, passed, nb);
274 currentFrom = currentTo;
281 insertEdge(e, running, currentFrom, last, passed, nb);
287 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
320 if (!tlsc.
insert(tlDef)) {
333 const std::vector<SUMOLong>& passed,
NBNetBuilder& nb) {
340 if (from == 0 || to == 0) {
341 WRITE_ERROR(
"Discarding edge " +
id +
" because the nodes could not be built.");
351 assert(passed.size() >= 2);
352 std::vector<SUMOLong> geom(passed);
355 index =
insertEdge(e, index, from, intermediate, geom, nb);
357 return insertEdge(e, index, intermediate, to, geom, nb);
359 const int newIndex = index + 1;
364 for (std::vector<SUMOLong>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
368 WRITE_ERROR(
"Unable to project coordinates for edge " +
id +
".");
375 if (!tc.
knows(type)) {
383 std::vector<std::string> types;
385 std::string t = tok.
next();
387 if (std::find(types.begin(), types.end(), t) == types.end()) {
390 }
else if (tok.
size() > 1) {
391 WRITE_WARNING(
"Discarding unknown compound \"" + t +
"\" in type \"" + type +
"\" (first occurence for edge \"" +
id +
"\").");
394 if (types.size() == 0) {
395 WRITE_WARNING(
"Discarding unusable type \"" + type +
"\" (first occurence for edge \"" +
id +
"\").");
400 if (tc.
knows(newType)) {
412 bool defaultIsOneWay =
false;
415 for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
431 WRITE_WARNING(
"Discarding compound type \"" + newType +
"\" (first occurence for edge \"" +
id +
"\").");
435 WRITE_MESSAGE(
"Adding new type \"" + type +
"\" (first occurence for edge \"" +
id +
"\").");
436 tc.
insert(newType, numLanes, maxSpeed, prio, permissions, width, defaultIsOneWay, sidewalkWidth);
454 bool addForward =
true;
455 bool addBackward =
true;
469 if (addForward && !addBackward) {
471 }
else if (!addForward && addBackward) {
479 numLanesForward = (int)std::ceil(e->
myNoLanes / 2.0);
481 numLanesBackward = e->
myNoLanes - numLanesForward;
484 numLanesForward =
MAX2(1, numLanesForward);
485 numLanesBackward =
MAX2(1, numLanesBackward);
488 WRITE_WARNING(
"Skipping edge '" +
id +
"' because it has zero lanes.");
502 assert(numLanesForward > 0);
516 assert(numLanesBackward > 0);
537 std::map<SUMOLong, NIOSMNode*>& toFill,
538 std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
539 bool importElevation) :
543 myIsInValidNodeTag(false),
545 myUniqueNodes(uniqueNodes),
546 myImportElevation(importElevation)
558 if (myHierarchyLevel != 2) {
564 if (action ==
"delete") {
571 if (myToFill.find(
id) == myToFill.end()) {
596 myIsInValidNodeTag =
true;
598 std::set<NIOSMNode*, CompareNodes>::iterator similarNode =
myUniqueNodes.find(toAdd);
603 toAdd = *similarNode;
606 myToFill[id] = toAdd;
610 if (myHierarchyLevel != 3) {
611 WRITE_ERROR(
"Tag element on wrong XML hierarchy level.");
617 if (key ==
"highway" || key ==
"ele") {
619 if (key ==
"highway" && value.find(
"traffic_signal") != std::string::npos) {
620 myToFill[myLastNodeID]->tlsControlled =
true;
621 }
else if (myImportElevation && key ==
"ele") {
625 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in node '" +
638 myIsInValidNodeTag =
false;
648 const std::map<SUMOLong, NIOSMNode*>& osmNodes,
649 std::map<SUMOLong, Edge*>& toFill) :
671 myParentElements.push_back(element);
677 if (action ==
"delete") {
685 myCurrentEdge =
new Edge(
id);
692 std::map<SUMOLong, NIOSMNode*>::const_iterator node =
myOSMNodes.find(ref);
697 ref = node->second->id;
698 if (myCurrentEdge->myCurrentNodes.size() == 0 ||
699 myCurrentEdge->myCurrentNodes.back() != ref) {
700 myCurrentEdge->myCurrentNodes.push_back(ref);
706 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_WAY) {
707 if (myCurrentEdge == 0) {
718 if (key ==
"highway" || key ==
"railway" || key ==
"waterway") {
719 const std::string singleTypeID = key +
"." + value;
720 if (myCurrentEdge->myHighWayType !=
"") {
725 myCurrentEdge->myHighWayType = singleTypeID;
727 myCurrentEdge->myCurrentIsRoad =
true;
728 }
else if (key ==
"lanes") {
734 std::vector<std::string> list = st.
getVector();
735 if (list.size() >= 2) {
738 for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) {
740 minLanes =
MIN2(minLanes, numLanes);
742 myCurrentEdge->myNoLanes = minLanes;
743 WRITE_WARNING(
"Using minimum lane number from list (" + value +
") for edge '" +
toString(myCurrentEdge->id) +
"'.");
745 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
746 toString(myCurrentEdge->id) +
"'.");
750 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
751 toString(myCurrentEdge->id) +
"'.");
753 }
else if (key ==
"lanes:forward") {
757 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
758 toString(myCurrentEdge->id) +
"'.");
760 }
else if (key ==
"lanes:backward") {
765 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
766 toString(myCurrentEdge->id) +
"'.");
768 }
else if (key ==
"maxspeed") {
769 if (mySpeedMap.find(value) != mySpeedMap.end()) {
770 myCurrentEdge->myMaxSpeed = mySpeedMap[value];
777 conversion = 1.609344;
782 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
783 toString(myCurrentEdge->id) +
"'.");
786 }
else if (key ==
"junction") {
787 if ((value ==
"roundabout") && (myCurrentEdge->myIsOneWay ==
"")) {
788 myCurrentEdge->myIsOneWay =
"yes";
790 }
else if (key ==
"oneway") {
791 myCurrentEdge->myIsOneWay = value;
792 }
else if (key ==
"name") {
793 myCurrentEdge->streetName = value;
794 }
else if (key ==
"tracks") {
797 myCurrentEdge->myIsOneWay =
"false";
799 myCurrentEdge->myIsOneWay =
"true";
802 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
803 toString(myCurrentEdge->id) +
"'.");
812 myParentElements.pop_back();
814 if (myCurrentEdge != 0 && myCurrentEdge->myCurrentIsRoad) {
815 myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
817 delete myCurrentEdge;
828 const std::map<SUMOLong, NIOSMNode*>& osmNodes,
829 const std::map<SUMOLong, Edge*>& osmEdges) :
832 myOSMEdges(osmEdges) {
843 myIsRestriction =
false;
848 myRestrictionType = RESTRICTION_UNKNOWN;
854 myParentElements.push_back(element);
860 if (action ==
"delete" || !ok) {
875 if (memberType ==
"way" && checkEdgeRef(ref)) {
877 }
else if (memberType ==
"node") {
884 }
else if (role ==
"from" && checkEdgeRef(ref)) {
886 }
else if (role ==
"to" && checkEdgeRef(ref)) {
896 if (key ==
"type" || key ==
"restriction") {
898 if (key ==
"type" && value ==
"restriction") {
899 myIsRestriction =
true;
902 if (key ==
"restriction") {
905 if (value.substr(0, 5) ==
"only_") {
906 myRestrictionType = RESTRICTION_ONLY;
907 }
else if (value.substr(0, 3) ==
"no_") {
908 myRestrictionType = RESTRICTION_NO;
910 WRITE_WARNING(
"Found unknown restriction type '" + value +
"' in relation '" +
toString(myCurrentRelation) +
"'");
921 if (myOSMEdges.find(ref) != myOSMEdges.end()) {
932 myParentElements.pop_back();
934 if (myIsRestriction) {
937 if (myRestrictionType == RESTRICTION_UNKNOWN) {
938 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown type.");
942 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown from-way.");
946 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown to-way.");
950 WRITE_WARNING(
"Ignoring restriction relation '" +
toString(myCurrentRelation) +
"' with unknown via.");
953 if (ok && !applyRestriction()) {
975 WRITE_WARNING(
"from-edge of restriction relation could not be determined");
979 WRITE_WARNING(
"to-edge of restriction relation could not be determined");
982 if (myRestrictionType == RESTRICTION_ONLY) {
989 WRITE_WARNING(
"direction of restriction relation could not be determined");
998 const std::string prefix =
toString(wayRef);
999 const std::string backPrefix =
"-" + prefix;
1002 for (EdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); ++it) {
1003 if (((*it)->getID().substr(0, prefix.size()) == prefix) ||
1004 ((*it)->getID().substr(0, backPrefix.size()) == backPrefix)) {
1010 WRITE_WARNING(
"Ambigous way reference '" + prefix +
"' in restriction relation");
NodesHandler(std::map< SUMOLong, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
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.
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
std::map< SUMOLong, Edge * > myEdges
the map from OSM way ids to edge objects
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...
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.
static SUMOReal _2SUMOReal(const E *const data)
vehicle is a not electrified rail
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.
vehicle is a small delivery vehicle
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.
const SUMOLong id
The edge's id.
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.
NBNode * insertNodeChecking(SUMOLong id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
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.
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)
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
std::vector< SUMOLong > myCurrentNodes
The list of nodes this edge is made of.
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.
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.
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.
A class which extracts OSM-edges from a parsed OSM-file.
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)
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;.
bool insert(const std::string &id, int noLanes, SUMOReal maxSpeed, int prio, SUMOReal width, SUMOVehicleClass vClasses=SVC_IGNORING, bool oneWayIsDefault=false, SUMOReal sidewalkWidth=NBEdge::UNSPECIFIED_WIDTH)
Adds a type into the list. This is a simplified convenience form of insert, if only one allowed vehic...
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
NBEdge * findEdgeRef(SUMOLong wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
std::vector< std::string > getVector()
const SUMOLong id
The node's id.
int myNoLanes
number of lanes, or -1 if unknown
void push_back(const PositionVector &p)
Appends all positions from the given vector.
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.
const SUMOReal lon
The longitude the node is located at.
EdgesHandler(const std::map< SUMOLong, NIOSMNode * > &osmNodes, std::map< SUMOLong, Edge * > &toFill)
Constructor.
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.
RelationHandler(const std::map< SUMOLong, NIOSMNode * > &osmNodes, const std::map< SUMOLong, Edge * > &osmEdges)
Constructor.
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 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...
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
T get(const std::string &str) const
bool checkEdgeRef(SUMOLong ref) const
check whether a referenced way has a corresponding edge
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.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< SUMOLong > &passed, NBNetBuilder &nb)
Builds an NBEdge.
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()
A traffic light logics which must be computed (only nodes/edges are given)
std::map< SUMOLong, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
#define WRITE_MESSAGE(msg)
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
static const SUMOLong INVALID_ID
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
vehicles ignoring classes
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.