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.getShapeReporting(SUMO_ATTR_SHAPE, 0, ok, true); if (!NILoader::transformCoordinates(shape)) { WRITE_ERROR("Unable to project coordinates for edge '" + myCurrentID + "'."); } myReinitKeepEdgeShape = myKeepEdgeShape; return shape; }
void NIImporter_SUMO::addJunction(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } if (id[0] == ':') { // internal node return; } SumoXMLNodeType type = attrs.getNodeType(ok); if (ok) { if (type == NODETYPE_DEAD_END_DEPRECATED) { // patch legacy type type = NODETYPE_DEAD_END; } } else { WRITE_WARNING("Unknown node type for junction '" + id + "'."); } Position pos = readPosition(attrs, id, ok); NILoader::transformCoordinates(pos, true, myLocation); // the network may have non-default edge geometry. // accurate reconstruction of legacy networks is not possible. We ought to warn about this if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) { PositionVector shape = attrs.getShapeReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, true); if (shape.size() > 0) { shape.push_back_noDoublePos(shape[0]); // need closed shape if (!shape.around(pos) && shape.distance(pos) > 1) { // MAGIC_THRESHOLD // WRITE_WARNING("Junction '" + id + "': distance between pos and shape is " + toString(shape.distance(pos))); mySuspectKeepShape = true; } } } NBNode* node = new NBNode(id, pos, type); if (!myNodeCont.insert(node)) { WRITE_ERROR("Problems on adding junction '" + id + "'."); delete node; return; } }
void NIImporter_SUMO::addEdge(const SUMOSAXAttributes& attrs) { // get the id, report an error if not given or empty... bool ok = true; std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); if (!ok) { return; } myCurrentEdge = new EdgeAttrs(); myCurrentEdge->builtEdge = 0; myCurrentEdge->id = id; // get the function myCurrentEdge->func = attrs.getEdgeFunc(ok); if (myCurrentEdge->func == EDGEFUNC_INTERNAL) { return; // skip internal edges } // get the type myCurrentEdge->type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, ""); // get the origin and the destination node myCurrentEdge->fromNode = attrs.getOptStringReporting(SUMO_ATTR_FROM, id.c_str(), ok, ""); myCurrentEdge->toNode = attrs.getOptStringReporting(SUMO_ATTR_TO, id.c_str(), ok, ""); myCurrentEdge->priority = attrs.getOptIntReporting(SUMO_ATTR_PRIORITY, id.c_str(), ok, -1); myCurrentEdge->type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, ""); myCurrentEdge->shape = attrs.getShapeReporting(SUMO_ATTR_SHAPE, id.c_str(), ok, true); NILoader::transformCoordinates(myCurrentEdge->shape, true, myLocation); myCurrentEdge->length = attrs.getOptSUMORealReporting(SUMO_ATTR_LENGTH, id.c_str(), ok, NBEdge::UNSPECIFIED_LOADED_LENGTH); myCurrentEdge->maxSpeed = 0; myCurrentEdge->streetName = attrs.getOptStringReporting(SUMO_ATTR_NAME, id.c_str(), ok, ""); std::string lsfS = toString(LANESPREAD_RIGHT); lsfS = attrs.getOptStringReporting(SUMO_ATTR_SPREADTYPE, id.c_str(), ok, lsfS); if (SUMOXMLDefinitions::LaneSpreadFunctions.hasString(lsfS)) { myCurrentEdge->lsf = SUMOXMLDefinitions::LaneSpreadFunctions.get(lsfS); } else { WRITE_ERROR("Unknown spreadType '" + lsfS + "' for edge '" + id + "'."); } }
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 == EDGEFUNC_INTERNAL) { return; // skip internal lanes } 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 = attrs.getShapeReporting(SUMO_ATTR_SHAPE, 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); }
void PCLoaderXML::myStartElement(int element, const SUMOSAXAttributes& attrs) { if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) { return; } if (element == SUMO_TAG_POI) { bool ok = true; // get the id, report an error if not given or empty... std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); SUMOReal x = attrs.getSUMORealReporting(SUMO_ATTR_X, id.c_str(), ok); SUMOReal y = attrs.getSUMORealReporting(SUMO_ATTR_Y, id.c_str(), ok); std::string type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, id.c_str(), ok, myOptions.getString("type")); if (!ok) { return; } Position pos(x, y); if (!GeoConvHelper::getProcessing().x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for POI '" + id + "'."); } // patch the values bool discard = myOptions.getBool("discard"); SUMOReal layer = (SUMOReal)myOptions.getInt("layer"); RGBColor color; if (myTypeMap.has(type)) { const PCTypeMap::TypeDef& def = myTypeMap.get(type); id = def.prefix + id; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = (SUMOReal)def.layer; } else { id = myOptions.getString("prefix") + id; color = RGBColor::parseColor(myOptions.getString("color")); } layer = attrs.getOptSUMORealReporting(SUMO_ATTR_LAYER, id.c_str(), ok, layer); if (attrs.hasAttribute(SUMO_ATTR_COLOR)) { color = attrs.getColorReporting(id.c_str(), ok); } SUMOReal angle = attrs.getOptSUMORealReporting(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE); std::string imgFile = attrs.getOptStringReporting(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE); if (imgFile != "" && !FileHelpers::isAbsolute(imgFile)) { imgFile = FileHelpers::getConfigurationRelative(getFileName(), imgFile); } SUMOReal imgWidth = attrs.getOptSUMORealReporting(SUMO_ATTR_WIDTH, id.c_str(), ok, Shape::DEFAULT_IMG_WIDTH); SUMOReal imgHeight = attrs.getOptSUMORealReporting(SUMO_ATTR_HEIGHT, id.c_str(), ok, Shape::DEFAULT_IMG_HEIGHT); if (!ok) { return; } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", id)) { ignorePrunning = true; } PointOfInterest* poi = new PointOfInterest(id, type, color, pos, layer, angle, imgFile, imgWidth, imgHeight); if (!myCont.insert(id, poi, (int)layer, ignorePrunning)) { WRITE_ERROR("POI '" + id + "' could not be added."); delete poi; } } } if (element == SUMO_TAG_POLY) { bool discard = myOptions.getBool("discard"); SUMOReal layer = (SUMOReal)myOptions.getInt("layer"); bool ok = true; std::string id = attrs.getOptStringReporting(SUMO_ATTR_ID, myCurrentID.c_str(), ok, ""); std::string type = attrs.getOptStringReporting(SUMO_ATTR_TYPE, myCurrentID.c_str(), ok, myOptions.getString("type")); if (!ok) { return; } RGBColor color; if (myTypeMap.has(type)) { const PCTypeMap::TypeDef& def = myTypeMap.get(type); id = def.prefix + id; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = (SUMOReal)def.layer; } else { id = myOptions.getString("prefix") + id; color = RGBColor::parseColor(myOptions.getString("color")); } layer = attrs.getOptSUMORealReporting(SUMO_ATTR_LAYER, id.c_str(), ok, layer); if (attrs.hasAttribute(SUMO_ATTR_COLOR)) { color = attrs.getColorReporting(id.c_str(), ok); } SUMOReal angle = attrs.getOptSUMORealReporting(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE); std::string imgFile = attrs.getOptStringReporting(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE); if (imgFile != "" && !FileHelpers::isAbsolute(imgFile)) { imgFile = FileHelpers::getConfigurationRelative(getFileName(), imgFile); } bool fill = attrs.getOptBoolReporting(SUMO_ATTR_FILL, id.c_str(), ok, false); if (!ok) { return; } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", id)) { ignorePrunning = true; } myCurrentID = id; myCurrentType = type; myCurrentColor = color; myCurrentIgnorePrunning = ignorePrunning; myCurrentLayer = layer; PositionVector pshape = attrs.getShapeReporting(SUMO_ATTR_SHAPE, myCurrentID.c_str(), ok, false); if (!ok) { return; } PositionVector shape; for (PositionVector::ContType::const_iterator i = pshape.begin(); i != pshape.end(); ++i) { Position pos((*i)); if (!GeoConvHelper::getProcessing().x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for polygon '" + myCurrentID + "'."); } shape.push_back(pos); } Polygon* poly = new Polygon(myCurrentID, myCurrentType, myCurrentColor, shape, fill, layer, angle, imgFile); if (!myCont.insert(myCurrentID, poly, (int)myCurrentLayer, myCurrentIgnorePrunning)) { WRITE_ERROR("Polygon '" + myCurrentID + "' could not be added."); delete poly; } } } }