本文整理汇总了C++中SUMOSAXAttributes::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ SUMOSAXAttributes::hasAttribute方法的具体用法?C++ SUMOSAXAttributes::hasAttribute怎么用?C++ SUMOSAXAttributes::hasAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SUMOSAXAttributes
的用法示例。
在下文中一共展示了SUMOSAXAttributes::hasAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pos
bool
NIXMLEdgesHandler::setNodes(const SUMOSAXAttributes &attrs) throw() {
// the names and the coordinates of the beginning and the end node
// may be found, try
bool ok = true;
std::string begNodeID = myIsUpdate ? myCurrentEdge->getFromNode()->getID() : "";
std::string endNodeID = myIsUpdate ? myCurrentEdge->getToNode()->getID() : "";
begNodeID = attrs.hasAttribute(SUMO_ATTR_FROMNODE) ? attrs.getStringReporting(SUMO_ATTR_FROMNODE, "edge", 0, ok) : begNodeID;
endNodeID = attrs.hasAttribute(SUMO_ATTR_TONODE) ? attrs.getStringReporting(SUMO_ATTR_TONODE, "edge", 0, ok) : endNodeID;
if (!ok) {
return false;
}
// or their positions !!! deprecated
SUMOReal begNodeXPos = tryGetPosition(attrs, SUMO_ATTR_XFROM, "XFrom");
SUMOReal begNodeYPos = tryGetPosition(attrs, SUMO_ATTR_YFROM, "YFrom");
SUMOReal endNodeXPos = tryGetPosition(attrs, SUMO_ATTR_XTO, "XTo");
SUMOReal endNodeYPos = tryGetPosition(attrs, SUMO_ATTR_YTO, "YTo");
if (begNodeXPos!=SUMOXML_INVALID_POSITION&&begNodeYPos!=SUMOXML_INVALID_POSITION) {
Position2D pos(begNodeXPos, begNodeYPos);
GeoConvHelper::x2cartesian(pos);
begNodeXPos = pos.x();
begNodeYPos = pos.y();
}
if (endNodeXPos!=SUMOXML_INVALID_POSITION&&endNodeYPos!=SUMOXML_INVALID_POSITION) {
Position2D pos(endNodeXPos, endNodeYPos);
GeoConvHelper::x2cartesian(pos);
endNodeXPos = pos.x();
endNodeYPos = pos.y();
}
// check the obtained values for nodes
myFromNode = insertNodeChecking(Position2D(begNodeXPos, begNodeYPos), begNodeID, "from");
myToNode = insertNodeChecking(Position2D(endNodeXPos, endNodeYPos), endNodeID, "to");
return myFromNode!=0&&myToNode!=0;
}
示例2: st
void
MSRouteHandler::openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) {
bool ok = true;
myCurrentVTypeDistributionID = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
if (ok) {
myCurrentVTypeDistribution = new RandomDistributor<MSVehicleType*>();
if (attrs.hasAttribute(SUMO_ATTR_VTYPES) || attrs.hasAttribute(SUMO_ATTR_VTYPES__DEPRECATED)) {
std::string vTypes;
if (!myHaveWarnedAboutDeprecatedVTypes && attrs.hasAttribute(SUMO_ATTR_VTYPES__DEPRECATED)) {
myHaveWarnedAboutDeprecatedVTypes = true;
WRITE_WARNING("'" + toString(SUMO_ATTR_VTYPES__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_ATTR_VTYPES) + "' instead.");
vTypes = attrs.getStringReporting(SUMO_ATTR_VTYPES__DEPRECATED, myCurrentVTypeDistributionID.c_str(), ok);
} else {
vTypes = attrs.getStringReporting(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
}
StringTokenizer st(vTypes);
while (st.hasNext()) {
std::string vtypeID = st.next();
MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(vtypeID);
if (type == 0) {
throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
}
myCurrentVTypeDistribution->add(type->getDefaultProbability(), type);
}
}
}
}
示例3: ProcessError
void
AGActivityGenHandler::parseStreets(const SUMOSAXAttributes& attrs) {
try {
SUMOReal pop = 0;
SUMOReal work = 0;
if (attrs.hasAttribute(AGEN_ATTR_POPULATION)) {
pop = attrs.getFloat(AGEN_ATTR_POPULATION);
}
if (attrs.hasAttribute(AGEN_ATTR_OUT_WORKPOSITION)) {
work = attrs.getFloat(AGEN_ATTR_OUT_WORKPOSITION);
}
std::string eid = attrs.getString(SUMO_ATTR_EDGE);
AGStreet* street = dynamic_cast<AGStreet*>(net->getEdge(eid));
if (street == 0) {
WRITE_ERROR("Edge '" + eid + "' is not known.");
return;
}
street->setPopulation(pop * street->getLength());
street->setWorkplaceNumber(work * street->getLength());
myCity.streets.push_back(street);
} catch (const std::exception& e) {
WRITE_ERROR("Error while parsing the element " +
SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
e.what());
throw ProcessError();
}
}
示例4: switch
void
TrajectoriesHandler::myStartElement(int element,
const SUMOSAXAttributes& attrs) {
bool ok = true;
switch (element) {
case SUMO_TAG_TRAJECTORIES:
myStepSize = attrs.getFloat("timeStepSize") / 1000.;
break;
case SUMO_TAG_TIMESTEP:
myCurrentTime = attrs.getSUMOTimeReporting(SUMO_ATTR_TIME, 0, ok);
break;
case SUMO_TAG_VEHICLE:
if (attrs.hasAttribute(SUMO_ATTR_SPEED)) {
SUMOReal v = attrs.getFloat(SUMO_ATTR_SPEED);
SUMOReal a = INVALID_VALUE;
SUMOReal s = INVALID_VALUE;
writeEmissions(std::cout, attrs.getString(SUMO_ATTR_ID), myDefaultClass, STEPS2TIME(myCurrentTime), v, a, s);
} else {
const std::string acId = attrs.getString(SUMO_ATTR_ACTORCONFIG);
const std::string id = attrs.getString(SUMO_ATTR_ID);
if (myEmissionClassByType.count(acId) == 0) {
WRITE_WARNING("Unknown actor configuration '" + acId + "' for vehicle '" + id + "'!");
} else {
myEmissionClassByVehicle[id] = myEmissionClassByType.count(acId) > 0 ? myEmissionClassByType[acId] : myDefaultClass;
}
}
break;
case SUMO_TAG_ACTORCONFIG: {
const std::string id = attrs.getString(SUMO_ATTR_ID);
const std::string vClass = attrs.getString(SUMO_ATTR_VEHICLECLASS);
const std::string fuel = attrs.getString(SUMO_ATTR_FUEL);
const std::string eClass = attrs.getString(SUMO_ATTR_EMISSIONCLASS);
const SUMOReal weight = attrs.getOpt<SUMOReal>(SUMO_ATTR_WEIGHT, id.c_str(), ok, 0.) * 10.;
myEmissionClassByType[id] = PollutantsInterface::getClass(myDefaultClass, vClass, fuel, eClass, weight);
break;
}
case SUMO_TAG_MOTIONSTATE: {
const std::string id = attrs.getString(SUMO_ATTR_VEHICLE);
if (myEmissionClassByVehicle.count(id) == 0) {
WRITE_WARNING("Motion state for unknown vehicle '" + id + "'!");
myEmissionClassByVehicle[id] = myDefaultClass;
}
const SUMOEmissionClass c = myEmissionClassByVehicle[id];
SUMOReal v = attrs.getFloat(SUMO_ATTR_SPEED) / 100.;
SUMOReal a = attrs.hasAttribute(SUMO_ATTR_ACCELERATION) ? attrs.get<SUMOReal>(SUMO_ATTR_ACCELERATION, id.c_str(), ok) / 1000. : INVALID_VALUE;
SUMOReal s = attrs.hasAttribute(SUMO_ATTR_SLOPE) ? RAD2DEG(asin(attrs.get<SUMOReal>(SUMO_ATTR_SLOPE, id.c_str(), ok) / 10000.)) : INVALID_VALUE;
const SUMOTime time = attrs.getOpt<int>(SUMO_ATTR_TIME, id.c_str(), ok, INVALID_VALUE);
if (myXMLOut != 0) {
writeXMLEmissions(id, c, time, v, a, s);
}
if (myStdOut != 0) {
writeEmissions(*myStdOut, id, c, STEPS2TIME(time), v, a, s);
}
break;
}
default:
break;
}
}
示例5: if
void
RORouteHandler::parseFromViaTo(std::string element,
const SUMOSAXAttributes& attrs) {
myActiveRoute.clear();
bool useTaz = OptionsCont::getOptions().getBool("with-taz");
if (useTaz && !myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET) && !myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET)) {
WRITE_WARNING("Taz usage was requested but no taz present in " + element + " '" + myVehicleParameter->id + "'!");
useTaz = false;
}
bool ok = true;
if ((useTaz || !attrs.hasAttribute(SUMO_ATTR_FROM)) && myVehicleParameter->wasSet(VEHPARS_FROM_TAZ_SET)) {
const ROEdge* fromTaz = myNet.getEdge(myVehicleParameter->fromTaz + "-source");
if (fromTaz == 0) {
myErrorOutput->inform("Source taz '" + myVehicleParameter->fromTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
} else if (fromTaz->getNumSuccessors() == 0) {
myErrorOutput->inform("Source taz '" + myVehicleParameter->fromTaz + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
} else {
myActiveRoute.push_back(fromTaz);
}
} else {
parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "", true),
myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
}
if (!attrs.hasAttribute(SUMO_ATTR_VIA)) {
myInsertStopEdgesAt = (int)myActiveRoute.size();
}
ConstROEdgeVector viaEdges;
parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
viaEdges, "for " + element + " '" + myVehicleParameter->id + "'");
for (ConstROEdgeVector::const_iterator i = viaEdges.begin(); i != viaEdges.end(); ++i) {
myActiveRoute.push_back(*i);
myVehicleParameter->via.push_back((*i)->getID());
}
if ((useTaz || !attrs.hasAttribute(SUMO_ATTR_TO)) && myVehicleParameter->wasSet(VEHPARS_TO_TAZ_SET)) {
const ROEdge* toTaz = myNet.getEdge(myVehicleParameter->toTaz + "-sink");
if (toTaz == 0) {
myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
} else if (toTaz->getNumPredecessors() == 0) {
myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
} else {
myActiveRoute.push_back(toTaz);
}
} else {
parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
}
myActiveRouteID = "!" + myVehicleParameter->id;
if (myVehicleParameter->routeid == "") {
myVehicleParameter->routeid = myActiveRouteID;
}
}
示例6: InvalidArgument
void
NLHandler::addDistrict(const SUMOSAXAttributes& attrs) {
bool ok = true;
myCurrentIsBroken = false;
// get the id, report an error if not given or empty...
myCurrentDistrictID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
if (!ok) {
myCurrentIsBroken = true;
return;
}
try {
MSEdge* sink = myEdgeControlBuilder.buildEdge(myCurrentDistrictID + "-sink", MSEdge::EDGEFUNCTION_DISTRICT);
if (!MSEdge::dictionary(myCurrentDistrictID + "-sink", sink)) {
delete sink;
throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-sink' exists.");
}
sink->initialize(new std::vector<MSLane*>());
MSEdge* source = myEdgeControlBuilder.buildEdge(myCurrentDistrictID + "-source", MSEdge::EDGEFUNCTION_DISTRICT);
if (!MSEdge::dictionary(myCurrentDistrictID + "-source", source)) {
delete source;
throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-source' exists.");
}
source->initialize(new std::vector<MSLane*>());
if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES);
for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
MSEdge* edge = MSEdge::dictionary(*i);
// check whether the edge exists
if (edge == 0) {
throw InvalidArgument("The edge '" + *i + "' within district '" + myCurrentDistrictID + "' is not known.");
}
source->addFollower(edge);
edge->addFollower(sink);
}
}
if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
PositionVector shape = attrs.get<PositionVector>(SUMO_ATTR_SHAPE, myCurrentDistrictID.c_str(), ok);
if (shape.size() != 0) {
if (!myNet.getShapeContainer().addPolygon(myCurrentDistrictID, "taz", RGBColor::parseColor("1.0,.33,.33"), 0, 0, "", shape, false)) {
WRITE_WARNING("Skipping visualization of taz '" + myCurrentDistrictID + "', polygon already exists.");
}
}
}
} catch (InvalidArgument& e) {
WRITE_ERROR(e.what());
myCurrentIsBroken = true;
}
}
示例7: ProcessError
void
RONetHandler::parseDistrict(const SUMOSAXAttributes& attrs) {
myCurrentEdge = 0;
bool ok = true;
myCurrentName = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
if (!ok) {
return;
}
ROEdge* sink = myEdgeBuilder.buildEdge(myCurrentName + "-sink", 0, 0, 0);
sink->setType(ROEdge::ET_DISTRICT);
myNet.addEdge(sink);
ROEdge* source = myEdgeBuilder.buildEdge(myCurrentName + "-source", 0, 0, 0);
source->setType(ROEdge::ET_DISTRICT);
myNet.addEdge(source);
if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES);
for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) {
ROEdge* edge = myNet.getEdge(*i);
// check whether the edge exists
if (edge == 0) {
throw ProcessError("The edge '" + *i + "' within district '" + myCurrentName + "' is not known.");
}
source->addFollower(edge);
edge->addFollower(sink);
}
}
}
示例8: toString
void
NIImporter_SUMO::addLane(const SUMOSAXAttributes& attrs) {
bool ok = true;
std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok);
if (!ok) {
return;
}
if (!myCurrentEdge) {
WRITE_ERROR("Found lane '" + id + "' not within edge element");
return;
}
myCurrentLane = new LaneAttrs;
if (myCurrentEdge->func == toString(EDGEFUNC_INTERNAL)) {
return; // skip internal lanes
}
if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED__DEPRECATED)) {
myCurrentLane->maxSpeed = attrs.getSUMORealReporting(SUMO_ATTR_MAXSPEED__DEPRECATED, id.c_str(), ok);
if (!myHaveWarnedAboutDeprecatedMaxSpeed) {
myHaveWarnedAboutDeprecatedMaxSpeed = true;
WRITE_WARNING("'" + toString(SUMO_ATTR_MAXSPEED__DEPRECATED) + "' is deprecated, please use '" + toString(SUMO_ATTR_SPEED) + "' instead.");
}
} else {
myCurrentLane->maxSpeed = attrs.getSUMORealReporting(SUMO_ATTR_SPEED, id.c_str(), ok);
}
myCurrentLane->allow = attrs.getOptStringReporting(SUMO_ATTR_ALLOW, id.c_str(), ok, "");
myCurrentLane->disallow = attrs.getOptStringReporting(SUMO_ATTR_DISALLOW, id.c_str(), ok, "");
myCurrentLane->width = attrs.getOptSUMORealReporting(SUMO_ATTR_WIDTH, id.c_str(), ok, (SUMOReal) NBEdge::UNSPECIFIED_WIDTH);
myCurrentLane->offset = attrs.getOptSUMORealReporting(SUMO_ATTR_ENDOFFSET, id.c_str(), ok, (SUMOReal) NBEdge::UNSPECIFIED_OFFSET);
myCurrentLane->shape = GeomConvHelper::parseShapeReporting(
attrs.getStringReporting(SUMO_ATTR_SHAPE, id.c_str(), ok),
attrs.getObjectType(), id.c_str(), ok, false);
// lane coordinates are derived (via lane spread) do not include them in convex boundary
NILoader::transformCoordinates(myCurrentLane->shape, false, myLocation);
}
示例9: ProcessError
void
SUMOVehicleParserHelper::parseLCParams(SUMOVTypeParameter& into, LaneChangeModel model, const SUMOSAXAttributes& attrs) {
if (allowedLCModelAttrs.size() == 0) {
// init static map
std::set<SumoXMLAttr> lc2013Params;
lc2013Params.insert(SUMO_ATTR_LCA_STRATEGIC_PARAM);
lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_PARAM);
lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAIN_PARAM);
lc2013Params.insert(SUMO_ATTR_LCA_KEEPRIGHT_PARAM);
allowedLCModelAttrs[LCM_LC2013] = lc2013Params;
std::set<SumoXMLAttr> sl2015Params = lc2013Params;
sl2015Params.insert(SUMO_ATTR_LCA_PUSHY);
sl2015Params.insert(SUMO_ATTR_LCA_SUBLANE_PARAM);
sl2015Params.insert(SUMO_ATTR_LCA_ASSERTIVE);
allowedLCModelAttrs[LCM_SL2015] = sl2015Params;
std::set<SumoXMLAttr> noParams;
allowedLCModelAttrs[LCM_DK2008] = noParams;
// default model may be either LC2013 or SL2013
// we allow both sets (sl2015 is a superset of lc2013Params)
allowedLCModelAttrs[LCM_DEFAULT] = sl2015Params;
}
bool ok = true;
std::set<SumoXMLAttr> allowed = allowedLCModelAttrs[model];
for (std::set<SumoXMLAttr>::const_iterator it = allowed.begin(); it != allowed.end(); it++) {
if (attrs.hasAttribute(*it)) {
into.lcParameter[*it] = attrs.get<SUMOReal>(*it, into.id.c_str(), ok);
}
}
if (!ok) {
throw ProcessError();
}
}
示例10: throw
void
NIXMLTypesHandler::myStartElement(SumoXMLTag element,
const SUMOSAXAttributes &attrs) throw(ProcessError) {
if (element!=SUMO_TAG_TYPE) {
return;
}
// get the id, report a warning if not given or empty...
std::string id;
if (!attrs.setIDFromAttributes("type", id), false) {
WRITE_WARNING("No type id given... Skipping.");
return;
}
// check deprecated (unused) attributes
if (!myHaveReportedAboutFunctionDeprecation&&attrs.hasAttribute(SUMO_ATTR_FUNCTION)) {
MsgHandler::getWarningInstance()->inform("While parsing type '" + id + "': 'function' is deprecated.\n All occurences are ignored.");
myHaveReportedAboutFunctionDeprecation = true;
}
bool ok = true;
int priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, "type", id.c_str(), ok, myTypeCont.getDefaultPriority());
int noLanes = attrs.getOptIntReporting(SUMO_ATTR_NOLANES, "type", id.c_str(), ok, myTypeCont.getDefaultNoLanes());
SUMOReal speed = attrs.getOptSUMORealReporting(SUMO_ATTR_SPEED, "type", id.c_str(), ok, (SUMOReal) myTypeCont.getDefaultSpeed());
bool discard = attrs.getOptBoolReporting(SUMO_ATTR_DISCARD, 0, 0, ok, false);
if (!ok) {
return;
}
// build the type
if (!myTypeCont.insert(id, noLanes, speed, priority)) {
MsgHandler::getErrorInstance()->inform("Duplicate type occured. ID='" + id + "'");
} else {
if (discard) {
myTypeCont.markAsToDiscard(id);
}
}
}
示例11: st
void
ROJTRTurnDefLoader::myStartElement(int element,
const SUMOSAXAttributes& attrs) {
bool ok = true;
switch (element) {
case SUMO_TAG_INTERVAL:
myIntervalBegin = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, 0, ok);
myIntervalEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, 0, ok);
break;
case SUMO_TAG_FROMEDGE:
beginFromEdge(attrs);
break;
case SUMO_TAG_TOEDGE:
addToEdge(attrs);
break;
case SUMO_TAG_SINK:
if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
StringTokenizer st(edges, StringTokenizer::WHITECHARS);
while (st.hasNext()) {
std::string id = st.next();
ROEdge* edge = myNet.getEdge(id);
if (edge == 0) {
throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
}
edge->setType(ROEdge::ET_SINK);
}
}
break;
case SUMO_TAG_SOURCE:
if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
StringTokenizer st(edges, StringTokenizer::WHITECHARS);
while (st.hasNext()) {
std::string id = st.next();
ROEdge* edge = myNet.getEdge(id);
if (edge == 0) {
throw ProcessError("The edge '" + id + "' declared as a source is not known.");
}
edge->setType(ROEdge::ET_SOURCE);
}
}
break;
default:
break;
}
}
示例12: toString
void
NIXMLEdgesHandler::addLane(const SUMOSAXAttributes& attrs) {
if (myCurrentEdge == 0) {
if (!OptionsCont::getOptions().isInStringVector("remove-edges.explicit", myCurrentID)) {
WRITE_ERROR("Additional lane information could not be set - the edge with id '" + myCurrentID + "' is not known.");
}
return;
}
bool ok = true;
int lane;
if (attrs.hasAttribute(SUMO_ATTR_ID)) {
lane = attrs.get<int>(SUMO_ATTR_ID, myCurrentID.c_str(), ok);
if (!myHaveWarnedAboutDeprecatedLaneId) {
myHaveWarnedAboutDeprecatedLaneId = true;
WRITE_WARNING("'" + toString(SUMO_ATTR_ID) + "' is deprecated, please use '" + toString(SUMO_ATTR_INDEX) + "' instead.");
}
} else {
lane = attrs.get<int>(SUMO_ATTR_INDEX, myCurrentID.c_str(), ok);
}
std::string allowed, disallowed, preferred;
allowed = attrs.getOpt<std::string>(SUMO_ATTR_ALLOW, 0, ok, "");
disallowed = attrs.getOpt<std::string>(SUMO_ATTR_DISALLOW, 0, ok, "");
preferred = attrs.getOpt<std::string>(SUMO_ATTR_PREFER, 0, ok, "");
if (!ok) {
return;
}
// check whether this lane exists
if (lane >= (int) myCurrentEdge->getNumLanes()) {
WRITE_ERROR("Lane index is larger than number of lanes (edge '" + myCurrentID + "').");
return;
}
// set information about allowed / disallowed vehicle classes
myCurrentEdge->setPermissions(parseVehicleClasses(allowed, disallowed), lane);
myCurrentEdge->setPreferredVehicleClass(parseVehicleClasses(preferred), lane);
// try to get the width
if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
myCurrentEdge->setLaneWidth(lane, attrs.get<SUMOReal>(SUMO_ATTR_WIDTH, myCurrentID.c_str(), ok));
}
// try to get the end-offset (lane shortened due to pedestrian crossing etc..)
if (attrs.hasAttribute(SUMO_ATTR_ENDOFFSET)) {
myCurrentEdge->setOffset(lane, attrs.get<SUMOReal>(SUMO_ATTR_ENDOFFSET, myCurrentID.c_str(), ok));
}
// try to get lane specific speed (should not occur for german networks)
if (attrs.hasAttribute(SUMO_ATTR_SPEED)) {
myCurrentEdge->setSpeed(lane, attrs.get<SUMOReal>(SUMO_ATTR_SPEED, myCurrentID.c_str(), ok));
}
}
示例13: lon
void
NIImporter_OpenStreetMap::NodesHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
++myHierarchyLevel;
if (element == SUMO_TAG_NODE) {
bool ok = true;
if (myHierarchyLevel != 2) {
WRITE_ERROR("Node element on wrong XML hierarchy level (id='" + toString(attrs.getIntReporting(SUMO_ATTR_ID, 0, ok)) + "', level='" + toString(myHierarchyLevel) + "').");
return;
}
int id = attrs.getIntReporting(SUMO_ATTR_ID, 0, ok);
std::string action = attrs.hasAttribute("action") ? attrs.getStringSecure("action", "") : "";
if (action == "delete") {
return;
}
if (!ok) {
return;
}
myLastNodeID = -1;
if (myToFill.find(id) == myToFill.end()) {
myLastNodeID = id;
// assume we are loading multiple files...
// ... so we won't report duplicate nodes
bool ok = true;
double tlat, tlon;
std::istringstream lon(attrs.getStringReporting(SUMO_ATTR_LON, toString(id).c_str(), ok));
if (!ok) {
return;
}
lon >> tlon;
if (lon.fail()) {
WRITE_ERROR("Node's '" + toString(id) + "' lon information is not numeric.");
return;
}
std::istringstream lat(attrs.getStringReporting(SUMO_ATTR_LAT, toString(id).c_str(), ok));
if (!ok) {
return;
}
lat >> tlat;
if (lat.fail()) {
WRITE_ERROR("Node's '" + toString(id) + "' lat information is not numeric.");
return;
}
NIOSMNode* toAdd = new NIOSMNode();
toAdd->id = id;
toAdd->tlsControlled = false;
toAdd->lat = tlat;
toAdd->lon = tlon;
myIsInValidNodeTag = true;
std::set<NIOSMNode*, CompareNodes>::iterator similarNode = myUniqueNodes.find(toAdd);
if (similarNode == myUniqueNodes.end()) {
myUniqueNodes.insert(toAdd);
} else {
delete toAdd;
toAdd = *similarNode;
WRITE_MESSAGE("Found duplicate nodes. Substituting " + toString(id) + " with " + toString(toAdd->id));
}
myToFill[id] = toAdd;
}
示例14:
void
NIImporter_SUMO::addRoundabout(const SUMOSAXAttributes& attrs) {
if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
myRoundabouts.push_back(attrs.getStringVector(SUMO_ATTR_EDGES));
} else {
WRITE_ERROR("Empty edges in roundabout.");
}
}
示例15: PositionVector
PositionVector
NIXMLEdgesHandler::tryGetShape(const SUMOSAXAttributes& attrs) {
if (!attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
return myShape;
}
// try to build shape
bool ok = true;
if (!attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
myReinitKeepEdgeShape = false;
return PositionVector();
}
PositionVector shape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, 0, ok, PositionVector());
if (!NILoader::transformCoordinates(shape)) {
WRITE_ERROR("Unable to project coordinates for edge '" + myCurrentID + "'.");
}
myReinitKeepEdgeShape = myKeepEdgeShape;
return shape;
}