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;
502 assert(numLanesForward > 0);
522 assert(numLanesBackward > 0);
538 throw ProcessError(
"Could not add edge '-" +
id +
"'.");
550 std::map<long long int, NIOSMNode*>& toFill,
551 std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
552 bool importElevation) :
556 myIsInValidNodeTag(false),
559 myImportElevation(importElevation)
577 if (action ==
"delete") {
611 std::set<NIOSMNode*, CompareNodes>::iterator similarNode =
myUniqueNodes.find(toAdd);
616 toAdd = *similarNode;
624 WRITE_ERROR(
"Tag element on wrong XML hierarchy level.");
630 if (key ==
"highway" || key ==
"ele" || key ==
"crossing") {
632 if (key ==
"highway" && value.find(
"traffic_signal") != std::string::npos) {
634 }
else if (key ==
"crossing" && value.find(
"traffic_signals") != std::string::npos) {
640 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in node '" +
663 const std::map<long long int, NIOSMNode*>& osmNodes,
664 std::map<long long int, Edge*>& toFill) :
692 if (action ==
"delete") {
707 std::map<long long int, NIOSMNode*>::const_iterator node =
myOSMNodes.find(ref);
712 ref = node->second->id;
729 const std::string cyclewaySpec = key.substr(9);
731 if (cyclewaySpec ==
"right") {
733 }
else if (cyclewaySpec ==
"left") {
735 }
else if (cyclewaySpec ==
"both") {
746 const std::string buswaySpec = key.substr(7);
748 if (buswaySpec ==
"right") {
750 }
else if (buswaySpec ==
"left") {
752 }
else if (buswaySpec ==
"both") {
765 if (key ==
"highway" || key ==
"railway" || key ==
"waterway" || key ==
"cycleway" || key ==
"busway") {
768 if (key ==
"cycleway") {
771 }
else if (value ==
"opposite_track") {
773 }
else if (value ==
"opposite_lane") {
778 if (key ==
"busway") {
781 }
else if (value ==
"opposite_track") {
783 }
else if (value ==
"opposite_lane") {
790 const std::string singleTypeID = key +
"." + value;
795 types.push_back(singleTypeID);
800 }
else if (key ==
"lanes") {
806 std::vector<std::string> list = st.
getVector();
807 if (list.size() >= 2) {
810 for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) {
812 minLanes =
MIN2(minLanes, numLanes);
817 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
822 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
825 }
else if (key ==
"lanes:forward") {
829 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
832 }
else if (key ==
"lanes:backward") {
837 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
840 }
else if (key ==
"maxspeed") {
849 conversion = 1.609344;
854 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
858 }
else if (key ==
"junction") {
862 }
else if (key ==
"oneway") {
864 }
else if (key ==
"name") {
866 }
else if (key ==
"tracks") {
874 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
900 const std::map<long long int, NIOSMNode*>& osmNodes,
901 const std::map<long long int, Edge*>& osmEdges) :
904 myOSMEdges(osmEdges) {
932 if (action ==
"delete" || !ok) {
949 }
else if (memberType ==
"node") {
968 if (key ==
"type" || key ==
"restriction") {
970 if (key ==
"type" && value ==
"restriction") {
974 if (key ==
"restriction") {
977 if (value.substr(0, 5) ==
"only_") {
979 }
else if (value.substr(0, 3) ==
"no_") {
1047 WRITE_WARNING(
"from-edge of restriction relation could not be determined");
1051 WRITE_WARNING(
"to-edge of restriction relation could not be determined");
1061 WRITE_WARNING(
"direction of restriction relation could not be determined");
1070 const std::string prefix =
toString(wayRef);
1071 const std::string backPrefix =
"-" + prefix;
1074 for (EdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); ++it) {
1075 if (((*it)->getID().substr(0, prefix.size()) == prefix) ||
1076 ((*it)->getID().substr(0, backPrefix.size()) == backPrefix)) {
1082 WRITE_WARNING(
"Ambigous way reference '" + prefix +
"' in restriction relation");
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const SUMOReal lat
The latitude the node is located at.
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.
The only invalid connection is declared.
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.
RestrictionType myRestrictionType
const SUMOReal SUMO_const_laneWidth
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
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.
The only valid connection is declared.
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)
The relation tag was missing.
long long int myFromWay
the origination way for the current restriction
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.
long long int myCurrentRelation
The currently parsed relation.
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.
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
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.
std::vector< int > myParentElements
The element stack.
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)
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
bool myIsRestriction
whether the currently parsed relation is a restriction
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
bool myIsInValidNodeTag
Hierarchy helper for parsing a node's tags.
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 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.
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
const SUMOReal lon
The longitude the node is located at.
NBNodeCont & getNodeCont()
Returns the node container.
long long int myToWay
the destination way for the current restriction
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)
long long int myViaNode
the via node/way for the current restriction
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)
int myHierarchyLevel
The current hierarchy level.
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
Edge * myCurrentEdge
The currently built edge.
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)
std::vector< int > myParentElements
The element stack.
#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.