void NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) { // write the edge's begin into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID()); into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID()); into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID()); if (!noNames && e.getStreetName() != "") { into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName())); } into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority()); if (e.getTypeID() != "") { into.writeAttr(SUMO_ATTR_TYPE, e.getTypeID()); } if (e.isMacroscopicConnector()) { into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR); } // write the spread type if not default ("right") if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) { into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction()); } if (e.hasLoadedLength()) { into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength()); } if (!e.hasDefaultGeometry()) { into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry()); } // write the lanes const std::vector<NBEdge::Lane>& lanes = e.getLanes(); SUMOReal length = e.getLoadedLength(); if (OptionsCont::getOptions().getBool("no-internal-links") && !e.hasLoadedLength()) { // use length to junction center even if a modified geometry was given PositionVector geom = e.cutAtIntersection(e.getGeometry()); geom.push_back_noDoublePos(e.getToNode()->getCenter()); geom.push_front_noDoublePos(e.getFromNode()->getCenter()); length = geom.length(); } if (length <= 0) { length = POSITION_EPS; } for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) { const NBEdge::Lane& l = lanes[i]; writeLane(into, e.getID(), e.getLaneID(i), l.speed, l.permissions, l.preferred, l.endOffset, l.width, l.shape, l.origID, length, i, origNames); } // close the edge into.closeTag(); }
void NWWriter_SUMO::writeEdge(OutputDevice& into, const NBEdge& e, bool noNames, bool origNames) { // write the edge's begin into.openTag(SUMO_TAG_EDGE).writeAttr(SUMO_ATTR_ID, e.getID()); into.writeAttr(SUMO_ATTR_FROM, e.getFromNode()->getID()); into.writeAttr(SUMO_ATTR_TO, e.getToNode()->getID()); if (!noNames && e.getStreetName() != "") { into.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e.getStreetName())); } into.writeAttr(SUMO_ATTR_PRIORITY, e.getPriority()); if (e.getTypeName() != "") { into.writeAttr(SUMO_ATTR_TYPE, e.getTypeName()); } if (e.isMacroscopicConnector()) { into.writeAttr(SUMO_ATTR_FUNCTION, EDGEFUNC_CONNECTOR); } // write the spread type if not default ("right") if (e.getLaneSpreadFunction() != LANESPREAD_RIGHT) { into.writeAttr(SUMO_ATTR_SPREADTYPE, e.getLaneSpreadFunction()); } if (e.hasLoadedLength()) { into.writeAttr(SUMO_ATTR_LENGTH, e.getLoadedLength()); } if (!e.hasDefaultGeometry()) { into.writeAttr(SUMO_ATTR_SHAPE, e.getGeometry()); } // write the lanes const std::vector<NBEdge::Lane>& lanes = e.getLanes(); SUMOReal length = e.getLoadedLength(); if (length <= 0) { length = (SUMOReal) .1; } for (unsigned int i = 0; i < (unsigned int) lanes.size(); i++) { writeLane(into, e.getID(), e.getLaneID(i), lanes[i], length, i, origNames); } // close the edge into.closeTag(); }
void NBEdgeCont::joinSameNodeConnectingEdges(NBDistrictCont& dc, NBTrafficLightLogicCont& tlc, EdgeVector edges) { // !!! Attention! // No merging of the geometry to come is being done // The connections are moved from one edge to another within // the replacement where the edge is a node's incoming edge. // count the number of lanes, the speed and the id unsigned int nolanes = 0; SUMOReal speed = 0; int priority = 0; std::string id; sort(edges.begin(), edges.end(), NBContHelper::same_connection_edge_sorter()); // retrieve the connected nodes NBEdge* tpledge = *(edges.begin()); NBNode* from = tpledge->getFromNode(); NBNode* to = tpledge->getToNode(); EdgeVector::const_iterator i; for (i = edges.begin(); i != edges.end(); i++) { // some assertions assert((*i)->getFromNode() == from); assert((*i)->getToNode() == to); // ad the number of lanes the current edge has nolanes += (*i)->getNumLanes(); // build the id if (i != edges.begin()) { id += "+"; } id += (*i)->getID(); // compute the speed speed += (*i)->getSpeed(); // build the priority priority = MAX2(priority, (*i)->getPriority()); } speed /= edges.size(); // build the new edge // @bug new edge does not know about allowed vclass of old edges // @bug both the width and the offset are not regarded NBEdge* newEdge = new NBEdge(id, from, to, "", speed, nolanes, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, tpledge->getStreetName(), tpledge->myLaneSpreadFunction); insert(newEdge, true); // replace old edge by current within the nodes // and delete the old from->replaceOutgoing(edges, newEdge); to->replaceIncoming(edges, newEdge); // patch connections // add edge2edge-information for (i = edges.begin(); i != edges.end(); i++) { EdgeVector ev = (*i)->getConnectedEdges(); for (EdgeVector::iterator j = ev.begin(); j != ev.end(); j++) { newEdge->addEdge2EdgeConnection(*j); } } // move lane2lane-connections unsigned int currLane = 0; for (i = edges.begin(); i != edges.end(); i++) { newEdge->moveOutgoingConnectionsFrom(*i, currLane); currLane += (*i)->getNumLanes(); } // patch tl-information currLane = 0; for (i = edges.begin(); i != edges.end(); i++) { unsigned int noLanes = (*i)->getNumLanes(); for (unsigned int j = 0; j < noLanes; j++, currLane++) { // replace in traffic lights tlc.replaceRemoved(*i, j, newEdge, currLane); } } // delete joined edges for (i = edges.begin(); i != edges.end(); i++) { erase(dc, *i); } }
void NWWriter_XML::writeEdgesAndConnections(const OptionsCont& oc, NBNodeCont& nc, NBEdgeCont& ec) { const GeoConvHelper& gch = GeoConvHelper::getFinal(); bool useGeo = oc.exists("proj.plain-geo") && oc.getBool("proj.plain-geo"); const bool geoAccuracy = useGeo || gch.usingInverseGeoProjection(); OutputDevice& edevice = OutputDevice::getDevice(oc.getString("plain-output-prefix") + ".edg.xml"); edevice.writeXMLHeader("edges", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/edges_file.xsd\""); OutputDevice& cdevice = OutputDevice::getDevice(oc.getString("plain-output-prefix") + ".con.xml"); cdevice.writeXMLHeader("connections", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/connections_file.xsd\""); bool noNames = !oc.getBool("output.street-names"); for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { // write the edge itself to the edges-files NBEdge* e = (*i).second; edevice.openTag(SUMO_TAG_EDGE); edevice.writeAttr(SUMO_ATTR_ID, e->getID()); edevice.writeAttr(SUMO_ATTR_FROM, e->getFromNode()->getID()); edevice.writeAttr(SUMO_ATTR_TO, e->getToNode()->getID()); if (!noNames && e->getStreetName() != "") { edevice.writeAttr(SUMO_ATTR_NAME, StringUtils::escapeXML(e->getStreetName())); } edevice.writeAttr(SUMO_ATTR_PRIORITY, e->getPriority()); // write the type if given if (e->getTypeID() != "") { edevice.writeAttr(SUMO_ATTR_TYPE, e->getTypeID()); } edevice.writeAttr(SUMO_ATTR_NUMLANES, e->getNumLanes()); if (!e->hasLaneSpecificSpeed()) { edevice.writeAttr(SUMO_ATTR_SPEED, e->getSpeed()); } // write non-default geometry if (!e->hasDefaultGeometry()) { PositionVector geom = e->getGeometry(); if (useGeo) { for (int i = 0; i < (int) geom.size(); i++) { gch.cartesian2geo(geom[i]); } } if (geoAccuracy) { edevice.setPrecision(GEO_OUTPUT_ACCURACY); } edevice.writeAttr(SUMO_ATTR_SHAPE, geom); if (geoAccuracy) { edevice.setPrecision(); } } // write the spread type if not default ("right") if (e->getLaneSpreadFunction() != LANESPREAD_RIGHT) { edevice.writeAttr(SUMO_ATTR_SPREADTYPE, toString(e->getLaneSpreadFunction())); } // write the length if it was specified if (e->hasLoadedLength()) { edevice.writeAttr(SUMO_ATTR_LENGTH, e->getLoadedLength()); } // some attributes can be set by edge default or per lane. Write as default if possible (efficiency) if (e->getLaneWidth() != NBEdge::UNSPECIFIED_WIDTH && !e->hasLaneSpecificWidth()) { edevice.writeAttr(SUMO_ATTR_WIDTH, e->getLaneWidth()); } if (e->getOffset() != NBEdge::UNSPECIFIED_OFFSET && !e->hasLaneSpecificOffset()) { edevice.writeAttr(SUMO_ATTR_OFFSET, e->getOffset()); } if (!e->needsLaneSpecificOutput()) { edevice.closeTag(); } else { for (unsigned int i = 0; i < e->getLanes().size(); ++i) { const NBEdge::Lane& lane = e->getLanes()[i]; edevice.openTag(SUMO_TAG_LANE); edevice.writeAttr(SUMO_ATTR_INDEX, i); // write allowed lanes NWWriter_SUMO::writePermissions(edevice, lane.permissions); NWWriter_SUMO::writePreferences(edevice, lane.preferred); // write other attributes if (lane.width != NBEdge::UNSPECIFIED_WIDTH && e->hasLaneSpecificWidth()) { edevice.writeAttr(SUMO_ATTR_WIDTH, lane.width); } if (lane.offset != NBEdge::UNSPECIFIED_OFFSET && e->hasLaneSpecificOffset()) { edevice.writeAttr(SUMO_ATTR_OFFSET, lane.offset); } if (e->hasLaneSpecificSpeed()) { edevice.writeAttr(SUMO_ATTR_SPEED, lane.speed); } edevice.closeTag(); } edevice.closeTag(); } // write this edge's connections to the connections-files e->sortOutgoingConnectionsByIndex(); const std::vector<NBEdge::Connection> connections = e->getConnections(); for (std::vector<NBEdge::Connection>::const_iterator c = connections.begin(); c != connections.end(); ++c) { NWWriter_SUMO::writeConnection(cdevice, *e, *c, false, NWWriter_SUMO::PLAIN); } if (connections.size() > 0) { cdevice << "\n"; } } // write loaded prohibitions to the connections-file for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NWWriter_SUMO::writeProhibitions(cdevice, i->second->getProhibitions()); } edevice.close(); cdevice.close(); }