void NIImporter_SUMO::_loadNetwork(const OptionsCont& oc) { // check whether the option is set (properly) if (!oc.isUsableFileList("sumo-net-file")) { return; } // parse file(s) std::vector<std::string> files = oc.getStringVector("sumo-net-file"); for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) { if (!FileHelpers::exists(*file)) { WRITE_ERROR("Could not open sumo-net-file '" + *file + "'."); return; } setFileName(*file); PROGRESS_BEGIN_MESSAGE("Parsing sumo-net from '" + *file + "'"); XMLSubSys::runParser(*this, *file); PROGRESS_DONE_MESSAGE(); } // build edges for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) { EdgeAttrs* ed = (*i).second; // skip internal edges if (ed->func == toString(EDGEFUNC_INTERNAL)) { continue; } // get and check the nodes NBNode* from = myNodeCont.retrieve(ed->fromNode); NBNode* to = myNodeCont.retrieve(ed->toNode); if (from == 0) { WRITE_ERROR("Edge's '" + ed->id + "' from-node '" + ed->fromNode + "' is not known."); continue; } if (to == 0) { WRITE_ERROR("Edge's '" + ed->id + "' to-node '" + ed->toNode + "' is not known."); continue; } // edge shape PositionVector geom; if (ed->shape.size() > 0) { geom = ed->shape; mySuspectKeepShape = false; // no problem with reconstruction if edge shape is given explicit } else { // either the edge has default shape consisting only of the two node // positions or we have a legacy network geom = reconstructEdgeShape(ed, from->getPosition(), to->getPosition()); } // build and insert the edge NBEdge* e = new NBEdge(ed->id, from, to, ed->type, ed->maxSpeed, (unsigned int) ed->lanes.size(), ed->priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, geom, ed->streetName, ed->lsf, true); // always use tryIgnoreNodePositions to keep original shape e->setLoadedLength(ed->length); if (!myNetBuilder.getEdgeCont().insert(e)) { WRITE_ERROR("Could not insert edge '" + ed->id + "'."); delete e; continue; } ed->builtEdge = myNetBuilder.getEdgeCont().retrieve(ed->id); } // assign further lane attributes (edges are built) for (std::map<std::string, EdgeAttrs*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) { EdgeAttrs* ed = (*i).second; NBEdge* nbe = ed->builtEdge; if (nbe == 0) { // inner edge or removed by explicit list, vclass, ... continue; } for (unsigned int fromLaneIndex = 0; fromLaneIndex < (unsigned int) ed->lanes.size(); ++fromLaneIndex) { LaneAttrs* lane = ed->lanes[fromLaneIndex]; // connections const std::vector<Connection> &connections = lane->connections; for (std::vector<Connection>::const_iterator c_it = connections.begin(); c_it != connections.end(); c_it++) { const Connection& c = *c_it; if (myEdges.count(c.toEdgeID) == 0) { WRITE_ERROR("Unknown edge '" + c.toEdgeID + "' given in connection."); continue; } NBEdge* toEdge = myEdges[c.toEdgeID]->builtEdge; if (toEdge == 0) { // removed by explicit list, vclass, ... continue; } nbe->addLane2LaneConnection( fromLaneIndex, toEdge, c.toLaneIdx, NBEdge::L2L_VALIDATED, false, c.mayDefinitelyPass); // maybe we have a tls-controlled connection if (c.tlID != "") { const std::map<std::string, NBTrafficLightDefinition*>& programs = myTLLCont.getPrograms(c.tlID); if (programs.size() > 0) { std::map<std::string, NBTrafficLightDefinition*>::const_iterator it; for (it = programs.begin(); it != programs.end(); it++) { NBLoadedSUMOTLDef* tlDef = dynamic_cast<NBLoadedSUMOTLDef*>(it->second); if (tlDef) { tlDef->addConnection(nbe, toEdge, fromLaneIndex, c.toLaneIdx, c.tlLinkNo); } else { throw ProcessError("Corrupt traffic light definition '" + c.tlID + "' (program '" + it->first + "')"); } } } else { WRITE_ERROR("The traffic light '" + c.tlID + "' is not known."); } } } // allow/disallow SUMOVehicleClasses allowed; SUMOVehicleClasses disallowed; parseVehicleClasses(lane->allow, lane->disallow, allowed, disallowed); nbe->setVehicleClasses(allowed, disallowed, fromLaneIndex); // width, offset nbe->setWidth(fromLaneIndex, lane->width); nbe->setOffset(fromLaneIndex, lane->offset); nbe->setSpeed(fromLaneIndex, lane->maxSpeed); } nbe->declareConnectionsAsLoaded(); } // insert loaded prohibitions for (std::vector<Prohibition>::const_iterator it = myProhibitions.begin(); it != myProhibitions.end(); it++) { NBEdge* prohibitedFrom = myEdges[it->prohibitedFrom]->builtEdge; if (prohibitedFrom == 0) { WRITE_ERROR("Edge '" + it->prohibitedFrom + "' in prohibition was not built"); } else { NBNode* n = prohibitedFrom->getToNode(); n->addSortedLinkFoes( NBConnection(myEdges[it->prohibitorFrom]->builtEdge, myEdges[it->prohibitorTo]->builtEdge), NBConnection(prohibitedFrom, myEdges[it->prohibitedTo]->builtEdge)); } } // final warning if (mySuspectKeepShape) { WRITE_WARNING("The input network may have been built using option 'xml.keep-shape'.\n... Accuracy of junction positions cannot be guaranteed."); } }
void NIImporter_OpenStreetMap::insertEdge(Edge* e, int index, NBNode* from, NBNode* to, const std::vector<int> &passed, NBEdgeCont& ec, NBTypeCont& tc) { // patch the id std::string id = e->id; if (index >= 0) { id = id + "#" + toString(index); } // convert the shape PositionVector shape; for (std::vector<int>::const_iterator i = passed.begin(); i != passed.end(); ++i) { NIOSMNode* n = myOSMNodes.find(*i)->second; Position pos(n->lon, n->lat); if (!NILoader::transformCoordinates(pos, true)) { throw ProcessError("Unable to project coordinates for edge " + id + "."); } shape.push_back_noDoublePos(pos); } std::string type = e->myHighWayType; if (!tc.knows(type)) { if (type.find(compoundTypeSeparator) != std::string::npos) { // this edge has a combination type which does not yet exist in the TypeContainer StringTokenizer tok = StringTokenizer(type, compoundTypeSeparator); std::set<std::string> types; while (tok.hasNext()) { std::string t = tok.next(); if (tc.knows(t)) { types.insert(t); } else { WRITE_WARNING("Discarding edge " + id + " with type \"" + type + "\" (unknown compound \"" + t + "\")."); return; } } if (types.size() == 2 && types.count("railway.tram") == 1) { // compound types concern mostly the special case of tram tracks on a normal road. // in this case we simply discard the tram information since the default for road is to allow all vclasses types.erase("railway.tram"); std::string otherCompound = *(types.begin()); // XXX if otherCompound does not allow all vehicles (e.g. SVC_DELIVERY), tram will still not be allowed type = otherCompound; } else { // other cases not implemented yet WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\"."); return; } } else { // we do not know the type -> something else, ignore //WRITE_WARNING("Discarding edge " + id + " with unknown type \"" + type + "\"."); return; } } // otherwise it is not an edge and will be ignored int noLanes = tc.getNumLanes(type); SUMOReal speed = tc.getSpeed(type); bool defaultsToOneWay = tc.getIsOneWay(type); SUMOVehicleClasses allowedClasses = tc.getAllowedClasses(type); SUMOVehicleClasses disallowedClasses = tc.getDisallowedClasses(type); // check directions bool addSecond = true; if (e->myIsOneWay == "true" || e->myIsOneWay == "yes" || e->myIsOneWay == "1" || (defaultsToOneWay && e->myIsOneWay != "no" && e->myIsOneWay != "false" && e->myIsOneWay != "0")) { addSecond = false; } // if we had been able to extract the number of lanes, override the highway type default if (e->myNoLanes >= 0) { if (!addSecond) { noLanes = e->myNoLanes; } else { noLanes = e->myNoLanes / 2; } } // if we had been able to extract the maximum speed, override the type's default if (e->myMaxSpeed != MAXSPEED_UNGIVEN) { speed = (SUMOReal)(e->myMaxSpeed / 3.6); } if (noLanes != 0 && speed != 0) { if (e->myIsOneWay != "" && e->myIsOneWay != "false" && e->myIsOneWay != "no" && e->myIsOneWay != "true" && e->myIsOneWay != "yes" && e->myIsOneWay != "-1" && e->myIsOneWay != "1") { WRITE_WARNING("New value for oneway found: " + e->myIsOneWay); } LaneSpreadFunction lsf = addSecond ? LANESPREAD_RIGHT : LANESPREAD_CENTER; if (e->myIsOneWay != "-1") { NBEdge* nbe = new NBEdge(id, from, to, type, speed, noLanes, tc.getPriority(type), tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, e->streetName, lsf); nbe->setVehicleClasses(allowedClasses, disallowedClasses); if (!ec.insert(nbe)) { delete nbe; throw ProcessError("Could not add edge '" + id + "'."); } } if (addSecond) { if (e->myIsOneWay != "-1") { id = "-" + id; } NBEdge* nbe = new NBEdge(id, to, from, type, speed, noLanes, tc.getPriority(type), tc.getWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape.reverse(), e->streetName, lsf); nbe->setVehicleClasses(allowedClasses, disallowedClasses); if (!ec.insert(nbe)) { delete nbe; throw ProcessError("Could not add edge '-" + id + "'."); } } } }