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.");
307 assert(passed.size() >= 2);
308 if (passed.size() == 2) {
309 WRITE_WARNING(
"Discarding edge '" +
id +
"' which connects two identical nodes without geometry.");
313 size_t intermediateIndex = passed.size() / 2;
315 std::vector<long long int> part1(passed.begin(), passed.begin() + intermediateIndex);
316 std::vector<long long int> part2(passed.begin() + intermediateIndex + 1, passed.end());
317 index =
insertEdge(e, index, from, intermediate, part1, nb);
318 return insertEdge(e, index, intermediate, to, part2, nb);
320 const int newIndex = index + 1;
325 for (std::vector<long long int>::const_iterator i = passed.begin(); i != passed.end(); ++i) {
329 WRITE_ERROR(
"Unable to project coordinates for edge '" +
id +
"'.");
336 if (!tc.
knows(type)) {
344 std::vector<std::string> types;
346 std::string t = tok.
next();
348 if (std::find(types.begin(), types.end(), t) == types.end()) {
351 }
else if (tok.
size() > 1) {
352 WRITE_WARNING(
"Discarding unknown compound '" + t +
"' in type '" + type +
"' (first occurence for edge '" +
id +
"').");
355 if (types.size() == 0) {
356 WRITE_WARNING(
"Discarding unusable type '" + type +
"' (first occurence for edge '" +
id +
"').");
361 if (tc.
knows(newType)) {
374 bool defaultIsOneWay =
false;
377 for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
394 WRITE_WARNING(
"Discarding compound type '" + newType +
"' (first occurence for edge '" +
id +
"').");
398 WRITE_MESSAGE(
"Adding new type '" + type +
"' (first occurence for edge '" +
id +
"').");
399 tc.
insert(newType, numLanes, maxSpeed, prio, permissions, width, defaultIsOneWay, sidewalkWidth, bikelaneWidth);
400 for (std::vector<std::string>::iterator it = types.begin(); it != types.end(); it++) {
426 bool addForward =
true;
427 bool addBackward =
true;
441 if (addForward && !addBackward) {
443 }
else if (!addForward && addBackward) {
451 numLanesForward = (int)std::ceil(e->
myNoLanes / 2.0);
453 numLanesBackward = e->
myNoLanes - numLanesForward;
456 numLanesForward =
MAX2(1, numLanesForward);
457 numLanesBackward =
MAX2(1, numLanesBackward);
460 WRITE_WARNING(
"Skipping edge '" +
id +
"' because it has zero lanes.");
485 numLanesBackward = 1;
499 numLanesBackward = 1;
506 assert(numLanesForward > 0);
526 assert(numLanesBackward > 0);
542 throw ProcessError(
"Could not add edge '-" +
id +
"'.");
554 std::map<long long int, NIOSMNode*>& toFill,
555 std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
556 bool importElevation) :
560 myIsInValidNodeTag(false),
563 myImportElevation(importElevation) {
581 if (action ==
"delete") {
615 std::set<NIOSMNode*, CompareNodes>::iterator similarNode =
myUniqueNodes.find(toAdd);
620 toAdd = *similarNode;
628 WRITE_ERROR(
"Tag element on wrong XML hierarchy level.");
634 if (key ==
"highway" || key ==
"ele" || key ==
"crossing") {
636 if (key ==
"highway" && value.find(
"traffic_signal") != std::string::npos) {
638 }
else if (key ==
"crossing" && value.find(
"traffic_signals") != std::string::npos) {
644 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in node '" +
667 const std::map<long long int, NIOSMNode*>& osmNodes,
668 std::map<long long int, Edge*>& toFill) :
696 if (action ==
"delete") {
711 std::map<long long int, NIOSMNode*>::const_iterator node =
myOSMNodes.find(ref);
716 ref = node->second->id;
733 const std::string cyclewaySpec = key.substr(9);
735 if (cyclewaySpec ==
"right") {
737 }
else if (cyclewaySpec ==
"left") {
739 }
else if (cyclewaySpec ==
"both") {
750 const std::string buswaySpec = key.substr(7);
752 if (buswaySpec ==
"right") {
754 }
else if (buswaySpec ==
"left") {
756 }
else if (buswaySpec ==
"both") {
769 if (key ==
"highway" || key ==
"railway" || key ==
"waterway" || key ==
"cycleway" || key ==
"busway") {
772 if (key ==
"cycleway") {
775 }
else if (value ==
"opposite_track") {
777 }
else if (value ==
"opposite_lane") {
782 if (key ==
"busway") {
785 }
else if (value ==
"opposite_track") {
787 }
else if (value ==
"opposite_lane") {
794 const std::string singleTypeID = key +
"." + value;
799 types.push_back(singleTypeID);
804 }
else if (key ==
"lanes") {
810 std::vector<std::string> list = st.
getVector();
811 if (list.size() >= 2) {
814 for (std::vector<std::string>::iterator i = list.begin(); i != list.end(); ++i) {
816 minLanes =
MIN2(minLanes, numLanes);
821 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
826 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
829 }
else if (key ==
"lanes:forward") {
833 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
836 }
else if (key ==
"lanes:backward") {
841 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
844 }
else if (key ==
"maxspeed") {
853 conversion = 1.609344;
858 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
862 }
else if (key ==
"junction") {
866 }
else if (key ==
"oneway") {
868 }
else if (key ==
"name") {
870 }
else if (key ==
"tracks") {
878 WRITE_WARNING(
"Value of key '" + key +
"' is not numeric ('" + value +
"') in edge '" +
904 const std::map<long long int, NIOSMNode*>& osmNodes,
905 const std::map<long long int, Edge*>& osmEdges) :
908 myOSMEdges(osmEdges) {
936 if (action ==
"delete" || !ok) {
953 }
else if (memberType ==
"node") {
972 if (key ==
"type" || key ==
"restriction") {
974 if (key ==
"type" && value ==
"restriction") {
978 if (key ==
"restriction") {
981 if (value.substr(0, 5) ==
"only_") {
983 }
else if (value.substr(0, 3) ==
"no_") {
1051 WRITE_WARNING(
"from-edge of restriction relation could not be determined");
1055 WRITE_WARNING(
"to-edge of restriction relation could not be determined");
1065 WRITE_WARNING(
"direction of restriction relation could not be determined");
1074 const std::string prefix =
toString(wayRef);
1075 const std::string backPrefix =
"-" + prefix;
1078 for (EdgeVector::const_iterator it = candidates.begin(); it != candidates.end(); ++it) {
1079 if (((*it)->getID().substr(0, prefix.size()) == prefix) ||
1080 ((*it)->getID().substr(0, backPrefix.size()) == backPrefix)) {
1086 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.