SUMOTime RONet::saveAndRemoveRoutesUntil(OptionsCont& options, SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime time) { checkFlows(time); SUMOTime lastTime = -1; // write all vehicles (and additional structures) while (myVehicles.size() != 0 || myPersons.size() != 0) { // get the next vehicle and person const ROVehicle* const veh = myVehicles.getTopVehicle(); const SUMOTime vehicleTime = veh == 0 ? SUMOTime_MAX : veh->getDepartureTime(); PersonMap::iterator person = myPersons.begin(); const SUMOTime personTime = person == myPersons.end() ? SUMOTime_MAX : person->first; // check whether it shall not yet be computed if (vehicleTime > time && personTime > time) { lastTime = MIN2(vehicleTime, personTime); break; } if (vehicleTime < personTime) { // check whether to print the output if (lastTime != vehicleTime && lastTime != -1) { // report writing progress if (options.getInt("stats-period") >= 0 && ((int) vehicleTime % options.getInt("stats-period")) == 0) { WRITE_MESSAGE("Read: " + toString(myReadRouteNo) + ", Discarded: " + toString(myDiscardedRouteNo) + ", Written: " + toString(myWrittenRouteNo)); } } lastTime = vehicleTime; // ok, compute the route (try it) if (computeRoute(options, router, veh)) { // write the route veh->saveAllAsXML(*myRoutesOutput, myRouteAlternativesOutput, myTypesOutput, options.getBool("exit-times")); myWrittenRouteNo++; } else { myDiscardedRouteNo++; } // delete routes and the vehicle if (veh->getRouteDefinition()->getID()[0] == '!') { if (!myRoutes.erase(veh->getRouteDefinition()->getID())) { delete veh->getRouteDefinition(); } } myVehicles.erase(veh->getID()); } else { myRoutesOutput->writePreformattedTag(person->second); if (myRouteAlternativesOutput != 0) { myRouteAlternativesOutput->writePreformattedTag(person->second); } myPersons.erase(person); } } return lastTime; }
void MSFrame::setMSGlobals(OptionsCont& oc) { // pre-initialise the network // set whether empty edges shall be printed on dump MSGlobals::gOmitEmptyEdgesOnDump = !oc.getBool("netstate-dump.empty-edges"); #ifdef HAVE_INTERNAL_LANES // set whether internal lanes shall be used MSGlobals::gUsingInternalLanes = !oc.getBool("no-internal-links"); #else MSGlobals::gUsingInternalLanes = false; #endif // set the grid lock time MSGlobals::gTimeToGridlock = string2time(oc.getString("time-to-teleport")) < 0 ? 0 : string2time(oc.getString("time-to-teleport")); MSGlobals::gCheck4Accidents = !oc.getBool("ignore-accidents"); MSGlobals::gCheckRoutes = !oc.getBool("ignore-route-errors"); #ifdef HAVE_INTERNAL MSGlobals::gStateLoaded = oc.isSet("load-state"); MSGlobals::gUseMesoSim = oc.getBool("mesosim"); MSGlobals::gMesoLimitedJunctionControl = oc.getBool("meso-junction-control.limited"); if (MSGlobals::gUseMesoSim) { MSGlobals::gUsingInternalLanes = false; } #endif #ifdef HAVE_SUBSECOND_TIMESTEPS DELTA_T = string2time(oc.getString("step-length")); #endif if (oc.isSet("routeDist.maxsize")) { MSRoute::setMaxRouteDistSize(oc.getInt("routeDist.maxsize")); } }
void NWWriter_DlrNavteq::writeTrafficSignals(const OptionsCont& oc, NBNodeCont& nc) { OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_traffic_signals.txt"); writeHeader(device, oc); const GeoConvHelper& gch = GeoConvHelper::getFinal(); const bool haveGeo = gch.usingGeoProjection(); const double geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE device.setPrecision(oc.getInt("dlr-navteq.precision")); // write format specifier device << "#Traffic signal related to LINK_ID and NODE_ID with location relative to driving direction.\n#column format like pointcollection.\n#DESCRIPTION->LOCATION: 1-rechts von LINK; 2-links von LINK; 3-oberhalb LINK -1-keineAngabe\n#RELATREC_ID\tPOICOL_TYPE\tDESCRIPTION\tLONGITUDE\tLATITUDE\tLINK_ID\n"; // write record for every edge incoming to a tls controlled node for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* n = (*i).second; if (n->isTLControlled()) { Position pos = n->getPosition(); gch.cartesian2geo(pos); pos.mul(geoScale); const EdgeVector& incoming = n->getIncomingEdges(); for (EdgeVector::const_iterator it = incoming.begin(); it != incoming.end(); ++it) { NBEdge* e = *it; device << e->getID() << "\t" << "12\t" // POICOL_TYPE << "LSA;NODEIDS#" << n->getID() << "#;LOCATION#-1#;\t" << pos.x() << "\t" << pos.y() << "\t" << e->getID() << "\n"; } } } device.close(); }
// =========================================================================== // method definitions // =========================================================================== PCTypeMap::PCTypeMap(const OptionsCont& oc) { myDefaultType.id = oc.getString("type"); myDefaultType.color = RGBColor::parseColor(oc.getString("color")); myDefaultType.layer = oc.getInt("layer"); myDefaultType.discard = oc.getBool("discard"); myDefaultType.allowFill = true; myDefaultType.prefix = oc.getString("prefix"); }
void NBNetBuilder::applyOptions(OptionsCont& oc) { // apply options to type control myTypeCont.setDefaults(oc.getInt("default.lanenumber"), oc.getFloat("default.lanewidth"), oc.getFloat("default.speed"), oc.getInt("default.priority")); // apply options to edge control myEdgeCont.applyOptions(oc); // apply options to traffic light logics control myTLLCont.applyOptions(oc); }
bool ROFrame::checkOptions(OptionsCont& oc) { // check whether the output is valid and can be build if (!oc.isSet("output-file")) { WRITE_ERROR("No output specified."); return false; } // if (oc.getInt("max-alternatives") < 2) { WRITE_ERROR("At least two alternatives should be enabled."); return false; } #ifndef HAVE_FOX if (oc.getInt("routing-threads") > 1) { WRITE_ERROR("Parallel routing is only possible when compiled with Fox."); return false; } #endif return true; }
bool ROFrame::checkOptions(OptionsCont& oc) { // check whether the output is valid and can be build if (!oc.isSet("output-file")) { WRITE_ERROR("No output specified."); return false; } // if (oc.getInt("max-alternatives") < 2) { WRITE_ERROR("At least two alternatives should be enabled"); return false; } return true; }
bool ROFrame::checkOptions(OptionsCont &oc) { // check whether the output is valid and can be build if (!oc.isSet("output")) { MsgHandler::getErrorInstance()->inform("No output specified."); return false; } // if (oc.getInt("max-alternatives")<2) { MsgHandler::getErrorInstance()->inform("At least two alternatives should be enabled"); return false; } // check departure/arrival options return true; }
bool GeoConvHelper::init(OptionsCont& oc) { std::string proj = "!"; // the default int shift = oc.getInt("proj.scale"); Position offset = Position(oc.getFloat("offset.x"), oc.getFloat("offset.y")); bool inverse = oc.exists("proj.inverse") && oc.getBool("proj.inverse"); if (oc.getBool("simple-projection")) { proj = "-"; } #ifdef HAVE_PROJ if (oc.getBool("proj.inverse") && oc.getString("proj") == "!") { WRITE_ERROR("Inverse projection works only with explicit proj parameters."); return false; } unsigned numProjections = oc.getBool("simple-projection") + oc.getBool("proj.utm") + oc.getBool("proj.dhdn") + oc.getBool("proj.dhdnutm") + (oc.getString("proj").length() > 1); if (numProjections > 1) { WRITE_ERROR("The projection method needs to be uniquely defined."); return false; } if (oc.getBool("proj.utm")) { proj = "UTM"; } else if (oc.getBool("proj.dhdn")) { proj = "DHDN"; } else if (oc.getBool("proj.dhdnutm")) { proj = "DHDN_UTM"; } else if (!oc.isDefault("proj")) { proj = oc.getString("proj"); } #endif myProcessing = GeoConvHelper(proj, offset, Boundary(), Boundary(), shift, inverse); myFinal = myProcessing; return true; }
void NWWriter_DlrNavteq::writeNodesUnsplitted(const OptionsCont& oc, NBNodeCont& nc, NBEdgeCont& ec, std::map<NBEdge*, std::string>& internalNodes) { // For "real" nodes we simply use the node id. // For internal nodes (geometry vectors describing edge geometry in the parlance of this format) // we use the id of the edge and do not bother with // compression (each direction gets its own internal node). OutputDevice& device = OutputDevice::getDevice(oc.getString("dlr-navteq-output") + "_nodes_unsplitted.txt"); writeHeader(device, oc); const GeoConvHelper& gch = GeoConvHelper::getFinal(); const bool haveGeo = gch.usingGeoProjection(); const double geoScale = pow(10.0f, haveGeo ? 5 : 2); // see NIImporter_DlrNavteq::GEO_SCALE device.setPrecision(oc.getInt("dlr-navteq.precision")); if (!haveGeo) { WRITE_WARNING("DlrNavteq node data will be written in (floating point) cartesian coordinates"); } // write format specifier device << "# NODE_ID\tIS_BETWEEN_NODE\tamount_of_geocoordinates\tx1\ty1\t[x2 y2 ... xn yn]\n"; // write header Boundary boundary = gch.getConvBoundary(); Position min(boundary.xmin(), boundary.ymin()); Position max(boundary.xmax(), boundary.ymax()); gch.cartesian2geo(min); min.mul(geoScale); gch.cartesian2geo(max); max.mul(geoScale); int multinodes = 0; for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { if ((*i).second->getGeometry().size() > 2) { multinodes++; } } device << "# [xmin_region] " << min.x() << "\n"; device << "# [xmax_region] " << max.x() << "\n"; device << "# [ymin_region] " << min.y() << "\n"; device << "# [ymax_region] " << max.y() << "\n"; device << "# [elements_multinode] " << multinodes << "\n"; device << "# [elements_normalnode] " << nc.size() << "\n"; device << "# [xmin] " << min.x() << "\n"; device << "# [xmax] " << max.x() << "\n"; device << "# [ymin] " << min.y() << "\n"; device << "# [ymax] " << max.y() << "\n"; // write normal nodes for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* n = (*i).second; Position pos = n->getPosition(); gch.cartesian2geo(pos); pos.mul(geoScale); device << n->getID() << "\t0\t1\t" << pos.x() << "\t" << pos.y() << "\n"; } // write "internal" nodes std::vector<std::string> avoid; std::set<std::string> reservedNodeIDs; const bool numericalIDs = oc.getBool("numerical-ids"); if (oc.isSet("reserved-ids")) { NBHelpers::loadPrefixedIDsFomFile(oc.getString("reserved-ids"), "node:", reservedNodeIDs); // backward compatibility NBHelpers::loadPrefixedIDsFomFile(oc.getString("reserved-ids"), "junction:", reservedNodeIDs); // selection format } if (numericalIDs) { avoid = nc.getAllNames(); std::vector<std::string> avoid2 = ec.getAllNames(); avoid.insert(avoid.end(), avoid2.begin(), avoid2.end()); avoid.insert(avoid.end(), reservedNodeIDs.begin(), reservedNodeIDs.end()); } IDSupplier idSupplier("", avoid); for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { NBEdge* e = (*i).second; PositionVector geom = e->getGeometry(); if (geom.size() > 2) { // the import NIImporter_DlrNavteq checks for the presence of a // negated edge id to determine spread type. We may need to do some // shifting to make this consistent const bool hasOppositeID = ec.getOppositeByID(e->getID()) != nullptr; if (e->getLaneSpreadFunction() == LANESPREAD_RIGHT && !hasOppositeID) { // need to write center-line geometry instead try { geom.move2side(e->getTotalWidth() / 2); } catch (InvalidArgument& exception) { WRITE_WARNING("Could not reconstruct shape for edge:'" + e->getID() + "' (" + exception.what() + ")."); } } else if (e->getLaneSpreadFunction() == LANESPREAD_CENTER && hasOppositeID) { // need to write left-border geometry instead try { geom.move2side(-e->getTotalWidth() / 2); } catch (InvalidArgument& exception) { WRITE_WARNING("Could not reconstruct shape for edge:'" + e->getID() + "' (" + exception.what() + ")."); } } std::string internalNodeID = e->getID(); if (internalNodeID == UNDEFINED || (nc.retrieve(internalNodeID) != nullptr) || reservedNodeIDs.count(internalNodeID) > 0 ) { // need to invent a new name to avoid clashing with the id of a 'real' node or a reserved name if (numericalIDs) { internalNodeID = idSupplier.getNext(); } else { internalNodeID += "_geometry"; } } internalNodes[e] = internalNodeID; device << internalNodeID << "\t1\t" << geom.size() - 2; for (int ii = 1; ii < (int)geom.size() - 1; ++ii) { Position pos = geom[(int)ii]; gch.cartesian2geo(pos); pos.mul(geoScale); device << "\t" << pos.x() << "\t" << pos.y(); } device << "\n"; } } device.close(); }
/** * Computes the routes saving them */ void computeRoutes(RONet& net, ROLoader& loader, OptionsCont& oc) { // initialise the loader loader.openRoutes(net); // build the router auto ttFunction = gWeightsRandomFactor > 1 ? &ROEdge::getTravelTimeStaticRandomized : &ROEdge::getTravelTimeStatic; SUMOAbstractRouter<ROEdge, ROVehicle>* router; const std::string measure = oc.getString("weight-attribute"); const std::string routingAlgorithm = oc.getString("routing-algorithm"); const SUMOTime begin = string2time(oc.getString("begin")); const SUMOTime end = string2time(oc.getString("end")); if (measure == "traveltime") { if (routingAlgorithm == "dijkstra") { if (net.hasPermissions()) { router = new DijkstraRouter<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), ttFunction); } else { router = new DijkstraRouter<ROEdge, ROVehicle, SUMOAbstractRouter<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), ttFunction); } } else if (routingAlgorithm == "astar") { if (net.hasPermissions()) { typedef AStarRouter<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> > AStar; std::shared_ptr<const AStar::LookupTable> lookup; if (oc.isSet("astar.all-distances")) { lookup = std::make_shared<const AStar::FLT>(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size()); } else if (oc.isSet("astar.landmark-distances")) { CHRouterWrapper<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> > router( ROEdge::getAllEdges(), true, &ROEdge::getTravelTimeStatic, begin, end, std::numeric_limits<int>::max(), 1); ROVehicle defaultVehicle(SUMOVehicleParameter(), nullptr, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net); lookup = std::make_shared<const AStar::LMLT>(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &router, &defaultVehicle, oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads")); } router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), ttFunction, lookup); } else { typedef AStarRouter<ROEdge, ROVehicle, SUMOAbstractRouter<ROEdge, ROVehicle> > AStar; std::shared_ptr<const AStar::LookupTable> lookup; if (oc.isSet("astar.all-distances")) { lookup = std::make_shared<const AStar::FLT>(oc.getString("astar.all-distances"), (int)ROEdge::getAllEdges().size()); } else if (oc.isSet("astar.landmark-distances")) { CHRouterWrapper<ROEdge, ROVehicle, SUMOAbstractRouter<ROEdge, ROVehicle> > router( ROEdge::getAllEdges(), true, &ROEdge::getTravelTimeStatic, begin, end, std::numeric_limits<int>::max(), 1); ROVehicle defaultVehicle(SUMOVehicleParameter(), nullptr, net.getVehicleTypeSecure(DEFAULT_VTYPE_ID), &net); lookup = std::make_shared<const AStar::LMLT>(oc.getString("astar.landmark-distances"), ROEdge::getAllEdges(), &router, &defaultVehicle, oc.isSet("astar.save-landmark-distances") ? oc.getString("astar.save-landmark-distances") : "", oc.getInt("routing-threads")); } router = new AStar(ROEdge::getAllEdges(), oc.getBool("ignore-errors"), ttFunction, lookup); } } else if (routingAlgorithm == "CH") { const SUMOTime weightPeriod = (oc.isSet("weight-files") ? string2time(oc.getString("weight-period")) : std::numeric_limits<int>::max()); if (net.hasPermissions()) { router = new CHRouter<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, true); } else { router = new CHRouter<ROEdge, ROVehicle, SUMOAbstractRouter<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, SVC_IGNORING, weightPeriod, false); } } else if (routingAlgorithm == "CHWrapper") { const SUMOTime weightPeriod = (oc.isSet("weight-files") ? string2time(oc.getString("weight-period")) : std::numeric_limits<int>::max()); router = new CHRouterWrapper<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), &ROEdge::getTravelTimeStatic, begin, end, weightPeriod, oc.getInt("routing-threads")); } else { throw ProcessError("Unknown routing Algorithm '" + routingAlgorithm + "'!"); } } else { DijkstraRouter<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> >::Operation op; if (measure == "CO") { op = &ROEdge::getEmissionEffort<PollutantsInterface::CO>; } else if (measure == "CO2") { op = &ROEdge::getEmissionEffort<PollutantsInterface::CO2>; } else if (measure == "PMx") { op = &ROEdge::getEmissionEffort<PollutantsInterface::PM_X>; } else if (measure == "HC") { op = &ROEdge::getEmissionEffort<PollutantsInterface::HC>; } else if (measure == "NOx") { op = &ROEdge::getEmissionEffort<PollutantsInterface::NO_X>; } else if (measure == "fuel") { op = &ROEdge::getEmissionEffort<PollutantsInterface::FUEL>; } else if (measure == "electricity") { op = &ROEdge::getEmissionEffort<PollutantsInterface::ELEC>; } else if (measure == "noise") { op = &ROEdge::getNoiseEffort; } else { throw ProcessError("Unknown measure (weight attribute '" + measure + "')!"); } if (net.hasPermissions()) { router = new DijkstraRouter<ROEdge, ROVehicle, SUMOAbstractRouterPermissions<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, ttFunction); } else { router = new DijkstraRouter<ROEdge, ROVehicle, SUMOAbstractRouter<ROEdge, ROVehicle> >( ROEdge::getAllEdges(), oc.getBool("ignore-errors"), op, ttFunction); } } int carWalk = 0; for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) { if (opt == "parkingAreas") { carWalk |= ROIntermodalRouter::Network::PARKING_AREAS; } else if (opt == "ptStops") { carWalk |= ROIntermodalRouter::Network::PT_STOPS; } else if (opt == "allJunctions") { carWalk |= ROIntermodalRouter::Network::ALL_JUNCTIONS; } } RORouterProvider provider(router, new PedestrianRouter<ROEdge, ROLane, RONode, ROVehicle>(), new ROIntermodalRouter(RONet::adaptIntermodalRouter, carWalk, routingAlgorithm)); // process route definitions try { net.openOutput(oc); loader.processRoutes(begin, end, string2time(oc.getString("route-steps")), net, provider); net.writeIntermodal(oc, provider.getIntermodalRouter()); // end the processing net.cleanup(); } catch (ProcessError&) { net.cleanup(); throw; } }
void PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap&) { #ifdef HAVE_GDAL GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing(); // get defaults std::string prefix = oc.getString("prefix"); std::string type = oc.getString("type"); RGBColor color = RGBColor::parseColor(oc.getString("color")); int layer = oc.getInt("layer"); std::string idField = oc.getString("shapefile.id-column"); bool useRunningID = oc.getBool("shapefile.use-running-id"); // start parsing std::string shpName = file + ".shp"; OGRRegisterAll(); OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE); if (poDS == NULL) { throw ProcessError("Could not open shape description '" + shpName + "'."); } // begin file parsing OGRLayer* poLayer = poDS->GetLayer(0); poLayer->ResetReading(); // build coordinate transformation OGRSpatialReference* origTransf = poLayer->GetSpatialRef(); OGRSpatialReference destTransf; // use wgs84 as destination destTransf.SetWellKnownGeogCS("WGS84"); OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf); if (poCT == NULL) { if (oc.isSet("shapefile.guess-projection")) { OGRSpatialReference origTransf2; origTransf2.SetWellKnownGeogCS("WGS84"); poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf); } if (poCT == 0) { WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); } } OGRFeature* poFeature; poLayer->ResetReading(); unsigned int runningID = 0; while ((poFeature = poLayer->GetNextFeature()) != NULL) { // read in edge attributes std::string id = useRunningID ? toString(runningID) : poFeature->GetFieldAsString(idField.c_str()); ++runningID; id = StringUtils::prune(id); if (id == "") { throw ProcessError("Missing id under '" + idField + "'"); } id = prefix + id; // read in the geometry OGRGeometry* poGeometry = poFeature->GetGeometryRef(); if (poGeometry == 0) { OGRFeature::DestroyFeature(poFeature); continue; } // try transform to wgs84 poGeometry->transform(poCT); OGRwkbGeometryType gtype = poGeometry->getGeometryType(); switch (gtype) { case wkbPoint: { OGRPoint* cgeom = (OGRPoint*) poGeometry; Position pos((SUMOReal) cgeom->getX(), (SUMOReal) cgeom->getY()); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for POI '" + id + "'."); } PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer); if (!toFill.insert(id, poi, layer)) { WRITE_ERROR("POI '" + id + "' could not be added."); delete poi; } } break; case wkbLineString: { OGRLineString* cgeom = (OGRLineString*) poGeometry; PositionVector shape; for (int j = 0; j < cgeom->getNumPoints(); j++) { Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(id, type, color, shape, false, (SUMOReal)layer); if (!toFill.insert(id, poly, layer)) { WRITE_ERROR("Polygon '" + id + "' could not be added."); delete poly; } } break; case wkbPolygon: { OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing(); PositionVector shape; for (int j = 0; j < cgeom->getNumPoints(); j++) { Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(id, type, color, shape, true, (SUMOReal)layer); if (!toFill.insert(id, poly, layer)) { WRITE_ERROR("Polygon '" + id + "' could not be added."); delete poly; } } break; case wkbMultiPoint: { OGRMultiPoint* cgeom = (OGRMultiPoint*) poGeometry; for (int i = 0; i < cgeom->getNumGeometries(); ++i) { OGRPoint* cgeom2 = (OGRPoint*) cgeom->getGeometryRef(i); Position pos((SUMOReal) cgeom2->getX(), (SUMOReal) cgeom2->getY()); std::string tid = id + "#" + toString(i); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for POI '" + tid + "'."); } PointOfInterest* poi = new PointOfInterest(tid, type, color, pos, (SUMOReal)layer); if (!toFill.insert(tid, poi, layer)) { WRITE_ERROR("POI '" + tid + "' could not be added."); delete poi; } } } break; case wkbMultiLineString: { OGRMultiLineString* cgeom = (OGRMultiLineString*) poGeometry; for (int i = 0; i < cgeom->getNumGeometries(); ++i) { OGRLineString* cgeom2 = (OGRLineString*) cgeom->getGeometryRef(i); PositionVector shape; std::string tid = id + "#" + toString(i); for (int j = 0; j < cgeom2->getNumPoints(); j++) { Position pos((SUMOReal) cgeom2->getX(j), (SUMOReal) cgeom2->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + tid + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(tid, type, color, shape, false, (SUMOReal)layer); if (!toFill.insert(tid, poly, layer)) { WRITE_ERROR("Polygon '" + tid + "' could not be added."); delete poly; } } } break; case wkbMultiPolygon: { OGRMultiPolygon* cgeom = (OGRMultiPolygon*) poGeometry; for (int i = 0; i < cgeom->getNumGeometries(); ++i) { OGRLinearRing* cgeom2 = ((OGRPolygon*) cgeom->getGeometryRef(i))->getExteriorRing(); PositionVector shape; std::string tid = id + "#" + toString(i); for (int j = 0; j < cgeom2->getNumPoints(); j++) { Position pos((SUMOReal) cgeom2->getX(j), (SUMOReal) cgeom2->getY(j)); if (!geoConvHelper.x2cartesian(pos)) { WRITE_ERROR("Unable to project coordinates for polygon '" + tid + "'."); } shape.push_back_noDoublePos(pos); } Polygon* poly = new Polygon(tid, type, color, shape, true, (SUMOReal)layer); if (!toFill.insert(tid, poly, layer)) { WRITE_ERROR("Polygon '" + tid + "' could not be added."); delete poly; } } } break; default: WRITE_WARNING("Unsupported shape type occured (id='" + id + "')."); break; } OGRFeature::DestroyFeature(poFeature); } PROGRESS_DONE_MESSAGE(); #else WRITE_ERROR("SUMO was compiled without GDAL support."); #endif }
void PCLoaderDlrNavteq::loadPolyFile(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { // get the defaults RGBColor c = RGBColor::parseColor(oc.getString("color")); // attributes of the poly // parse int l = 0; LineReader lr(file); while (lr.hasMore()) { std::string line = lr.readLine(); ++l; // skip invalid/empty lines if (line.length() == 0 || line.find("#") != std::string::npos) { continue; } if (StringUtils::prune(line) == "") { continue; } // parse the poi StringTokenizer st(line, "\t"); std::vector<std::string> values = st.getVector(); if (values.size() < 6 || values.size() % 2 != 0) { throw ProcessError("Invalid dlr-navteq-polygon - line: '" + line + "'."); } std::string id = values[0]; std::string ort = values[1]; std::string type = values[2]; std::string name = values[3]; PositionVector vec; size_t index = 4; // now collect the positions while (values.size() > index) { std::string xpos = values[index]; std::string ypos = values[index + 1]; index += 2; SUMOReal x = TplConvert::_2SUMOReal(xpos.c_str()); SUMOReal y = TplConvert::_2SUMOReal(ypos.c_str()); Position pos(x, y); if (!GeoConvHelper::getProcessing().x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for polygon '" + id + "'."); } vec.push_back(pos); } name = StringUtils::convertUmlaute(name); if (name == "noname" || toFill.containsPolygon(name)) { name = name + "#" + toString(toFill.getEnumIDFor(name)); } // check the polygon if (vec.size() == 0) { WRITE_WARNING("The polygon '" + id + "' is empty."); continue; } if (id == "") { WRITE_WARNING("The name of a polygon is missing; it will be discarded."); continue; } // patch the values bool fill = vec.front() == vec.back(); bool discard = oc.getBool("discard"); int layer = oc.getInt("layer"); RGBColor color; if (tm.has(type)) { const PCTypeMap::TypeDef& def = tm.get(type); name = def.prefix + name; type = def.id; color = def.color; fill = fill && def.allowFill; discard = def.discard; layer = def.layer; } else { name = oc.getString("prefix") + name; type = oc.getString("type"); color = c; } if (!discard) { Polygon* poly = new Polygon(name, type, color, vec, fill, (SUMOReal)layer); toFill.insert(name, poly, layer); } vec.clear(); } }
void PCLoaderDlrNavteq::loadPOIFile(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { // get the defaults RGBColor c = RGBColor::parseColor(oc.getString("color")); // parse int l = 0; LineReader lr(file); while (lr.hasMore()) { std::string line = lr.readLine(); ++l; // skip invalid/empty lines if (line.length() == 0 || line.find("#") != std::string::npos) { continue; } if (StringUtils::prune(line) == "") { continue; } // parse the poi std::istringstream stream(line); // attributes of the poi std::string name, skip, type, desc; std::getline(stream, name, '\t'); std::getline(stream, skip, '\t'); std::getline(stream, type, '\t'); std::getline(stream, desc, '\t'); if (stream.fail()) { throw ProcessError("Invalid dlr-navteq-poi in line " + toString(l) + ":\n" + line); } double x, y; stream >> x; if (stream.fail()) { throw ProcessError("Invalid x coordinate for POI '" + name + "'."); } stream >> y; if (stream.fail()) { throw ProcessError("Invalid y coordinate for POI '" + name + "'."); } Position pos(x, y); // check the poi if (name == "") { throw ProcessError("The name of a POI is missing."); } if (!GeoConvHelper::getProcessing().x2cartesian(pos, true)) { throw ProcessError("Unable to project coordinates for POI '" + name + "'."); } // patch the values bool discard = oc.getBool("discard"); int layer = oc.getInt("layer"); RGBColor color; if (tm.has(type)) { const PCTypeMap::TypeDef& def = tm.get(type); name = def.prefix + name; type = def.id; color = def.color; discard = def.discard; layer = def.layer; } else { name = oc.getString("prefix") + name; type = oc.getString("type"); color = c; } if (!discard) { bool ignorePrunning = false; if (OptionsCont::getOptions().isInStringVector("prune.keep-list", name)) { ignorePrunning = true; } PointOfInterest* poi = new PointOfInterest(name, type, color, pos, (SUMOReal)layer); toFill.insert(name, poi, layer, ignorePrunning); } } }
// =========================================================================== // method definitions // =========================================================================== // --------------------------------------------------------------------------- // static methods // --------------------------------------------------------------------------- void NWWriter_SUMO::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) { // check whether a sumo net-file shall be generated if (!oc.isSet("output-file")) { return; } OutputDevice& device = OutputDevice::getDevice(oc.getString("output-file")); const std::string lefthand = oc.getBool("lefthand") ? " " + toString(SUMO_ATTR_LEFTHAND) + "=\"true\"" : ""; const int cornerDetail = oc.getInt("junctions.corner-detail"); const int linkDetail = oc.getInt("junctions.internal-link-detail"); const std::string junctionCornerDetail = (cornerDetail > 0 ? " " + toString(SUMO_ATTR_CORNERDETAIL) + "=\"" + toString(cornerDetail) + "\"" : ""); const std::string junctionLinkDetail = (oc.isDefault("junctions.internal-link-detail") ? "" : " " + toString(SUMO_ATTR_LINKDETAIL) + "=\"" + toString(linkDetail) + "\""); device.writeXMLHeader("net", NWFrame::MAJOR_VERSION + lefthand + junctionCornerDetail + junctionLinkDetail + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/net_file.xsd\""); // street names may contain non-ascii chars device.lf(); // get involved container const NBNodeCont& nc = nb.getNodeCont(); const NBEdgeCont& ec = nb.getEdgeCont(); const NBDistrictCont& dc = nb.getDistrictCont(); // write network offsets and projection GeoConvHelper::writeLocation(device); // write edge types and restrictions nb.getTypeCont().writeTypes(device); // write inner lanes bool origNames = oc.getBool("output.original-names"); if (!oc.getBool("no-internal-links")) { bool hadAny = false; for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { hadAny |= writeInternalEdges(device, *(*i).second, origNames); } if (hadAny) { device.lf(); } } // write edges with lanes and connected edges bool noNames = !oc.getBool("output.street-names"); for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { writeEdge(device, *(*i).second, noNames, origNames); } device.lf(); // write tls logics writeTrafficLights(device, nb.getTLLogicCont()); // write the nodes (junctions) std::set<NBNode*> roundaboutNodes; const bool checkLaneFoesAll = oc.getBool("check-lane-foes.all"); const bool checkLaneFoesRoundabout = !checkLaneFoesAll && oc.getBool("check-lane-foes.roundabout"); if (checkLaneFoesRoundabout) { const std::set<EdgeSet>& roundabouts = ec.getRoundabouts(); for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) { for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) { roundaboutNodes.insert((*j)->getToNode()); } } } for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { const bool checkLaneFoes = checkLaneFoesAll || (checkLaneFoesRoundabout && roundaboutNodes.count((*i).second) > 0); writeJunction(device, *(*i).second, checkLaneFoes); } device.lf(); const bool includeInternal = !oc.getBool("no-internal-links"); if (includeInternal) { // ... internal nodes if not unwanted bool hadAny = false; for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { hadAny |= writeInternalNodes(device, *(*i).second); } if (hadAny) { device.lf(); } } // write the successors of lanes unsigned int numConnections = 0; for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.begin(); it_edge != ec.end(); it_edge++) { NBEdge* from = it_edge->second; from->sortOutgoingConnectionsByIndex(); const std::vector<NBEdge::Connection> connections = from->getConnections(); numConnections += (unsigned int)connections.size(); for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) { writeConnection(device, *from, *it_c, includeInternal); } } if (numConnections > 0) { device.lf(); } if (includeInternal) { // ... internal successors if not unwanted bool hadAny = false; for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { hadAny |= writeInternalConnections(device, *(*i).second); } if (hadAny) { device.lf(); } } for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { NBNode* node = (*i).second; // write connections from pedestrian crossings const std::vector<NBNode::Crossing>& crossings = node->getCrossings(); for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) { NWWriter_SUMO::writeInternalConnection(device, (*it).id, (*it).nextWalkingArea, 0, 0, ""); } // write connections from pedestrian walking areas const std::vector<NBNode::WalkingArea>& WalkingAreas = node->getWalkingAreas(); for (std::vector<NBNode::WalkingArea>::const_iterator it = WalkingAreas.begin(); it != WalkingAreas.end(); it++) { if ((*it).nextCrossing != "") { const NBNode::Crossing& nextCrossing = node->getCrossing((*it).nextCrossing); // connection to next crossing (may be tls-controlled) device.openTag(SUMO_TAG_CONNECTION); device.writeAttr(SUMO_ATTR_FROM, (*it).id); device.writeAttr(SUMO_ATTR_TO, (*it).nextCrossing); device.writeAttr(SUMO_ATTR_FROM_LANE, 0); device.writeAttr(SUMO_ATTR_TO_LANE, 0); if (node->isTLControlled()) { device.writeAttr(SUMO_ATTR_TLID, (*node->getControllingTLS().begin())->getID()); assert(nextCrossing.tlLinkNo >= 0); device.writeAttr(SUMO_ATTR_TLLINKINDEX, nextCrossing.tlLinkNo); } device.writeAttr(SUMO_ATTR_DIR, LINKDIR_STRAIGHT); device.writeAttr(SUMO_ATTR_STATE, nextCrossing.priority ? LINKSTATE_MAJOR : LINKSTATE_MINOR); device.closeTag(); } // optional connections from/to sidewalk for (std::vector<std::string>::const_iterator it_sw = (*it).nextSidewalks.begin(); it_sw != (*it).nextSidewalks.end(); ++it_sw) { NWWriter_SUMO::writeInternalConnection(device, (*it).id, (*it_sw), 0, 0, ""); } for (std::vector<std::string>::const_iterator it_sw = (*it).prevSidewalks.begin(); it_sw != (*it).prevSidewalks.end(); ++it_sw) { NWWriter_SUMO::writeInternalConnection(device, (*it_sw), (*it).id, 0, 0, ""); } } } // write loaded prohibitions for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { writeProhibitions(device, i->second->getProhibitions()); } // write roundabout information writeRoundabouts(device, ec.getRoundabouts(), ec); // write the districts for (std::map<std::string, NBDistrict*>::const_iterator i = dc.begin(); i != dc.end(); i++) { writeDistrict(device, *(*i).second); } if (dc.size() != 0) { device.lf(); } device.close(); }
void startComputation(RODFNet* optNet, RODFDetectorFlows& flows, RODFDetectorCon& detectors, OptionsCont& oc) { if (oc.getBool("print-absolute-flows")) { flows.printAbsolute(); } // if a network was loaded... (mode1) if (optNet != 0) { if (oc.getBool("remove-empty-detectors")) { PROGRESS_BEGIN_MESSAGE("Removing empty detectors"); optNet->removeEmptyDetectors(detectors, flows); PROGRESS_DONE_MESSAGE(); } else if (oc.getBool("report-empty-detectors")) { PROGRESS_BEGIN_MESSAGE("Scanning for empty detectors"); optNet->reportEmptyDetectors(detectors, flows); PROGRESS_DONE_MESSAGE(); } // compute the detector types (optionally) if (!detectors.detectorsHaveCompleteTypes() || oc.getBool("revalidate-detectors")) { optNet->computeTypes(detectors, oc.getBool("strict-sources")); } std::vector<RODFDetector*>::const_iterator i = detectors.getDetectors().begin(); for (; i != detectors.getDetectors().end(); ++i) { if ((*i)->getType() == SOURCE_DETECTOR) { break; } } if (i == detectors.getDetectors().end() && !oc.getBool("routes-for-all")) { throw ProcessError("No source detectors found."); } // compute routes between the detectors (optionally) if (!detectors.detectorsHaveRoutes() || oc.getBool("revalidate-routes") || oc.getBool("guess-empty-flows")) { PROGRESS_BEGIN_MESSAGE("Computing routes"); optNet->buildRoutes(detectors, oc.getBool("all-end-follower"), oc.getBool("keep-unfinished-routes"), oc.getBool("routes-for-all"), !oc.getBool("keep-longer-routes"), oc.getInt("max-search-depth")); PROGRESS_DONE_MESSAGE(); } } // check // whether the detectors are valid if (!detectors.detectorsHaveCompleteTypes()) { throw ProcessError("The detector types are not defined; use in combination with a network"); } // whether the detectors have routes if (!detectors.detectorsHaveRoutes()) { throw ProcessError("The emitters have no routes; use in combination with a network"); } // save the detectors if wished if (oc.isSet("detector-output")) { detectors.save(oc.getString("detector-output")); } // save their positions as POIs if wished if (oc.isSet("detectors-poi-output")) { detectors.saveAsPOIs(oc.getString("detectors-poi-output")); } // save the routes file if it was changed or it's wished if (detectors.detectorsHaveRoutes() && oc.isSet("routes-output")) { detectors.saveRoutes(oc.getString("routes-output")); } // guess flows if wished if (oc.getBool("guess-empty-flows")) { optNet->buildDetectorDependencies(detectors); detectors.guessEmptyFlows(flows); } const SUMOTime begin = string2time(oc.getString("begin")); const SUMOTime end = string2time(oc.getString("end")); const SUMOTime step = string2time(oc.getString("time-step")); // save emitters if wished if (oc.isSet("emitters-output") || oc.isSet("emitters-poi-output")) { optNet->buildEdgeFlowMap(flows, detectors, begin, end, step); // !!! if (oc.getBool("revalidate-flows")) { PROGRESS_BEGIN_MESSAGE("Rechecking loaded flows"); optNet->revalidateFlows(detectors, flows, begin, end, step); PROGRESS_DONE_MESSAGE(); } if (oc.isSet("emitters-output")) { PROGRESS_BEGIN_MESSAGE("Writing emitters"); detectors.writeEmitters(oc.getString("emitters-output"), flows, begin, end, step, *optNet, oc.getBool("calibrator-output"), oc.getBool("include-unused-routes"), oc.getFloat("scale"), // oc.getInt("max-search-depth"), oc.getBool("emissions-only")); PROGRESS_DONE_MESSAGE(); } if (oc.isSet("emitters-poi-output")) { PROGRESS_BEGIN_MESSAGE("Writing emitter pois"); detectors.writeEmitterPOIs(oc.getString("emitters-poi-output"), flows); PROGRESS_DONE_MESSAGE(); } } // save end speed trigger if wished if (oc.isSet("variable-speed-sign-output")) { PROGRESS_BEGIN_MESSAGE("Writing speed triggers"); detectors.writeSpeedTrigger(optNet, oc.getString("variable-speed-sign-output"), flows, begin, end, step); PROGRESS_DONE_MESSAGE(); } // save checking detectors if wished if (oc.isSet("validation-output")) { PROGRESS_BEGIN_MESSAGE("Writing validation detectors"); detectors.writeValidationDetectors(oc.getString("validation-output"), oc.getBool("validation-output.add-sources"), true, true); // !!! PROGRESS_DONE_MESSAGE(); } // build global rerouter on end if wished if (oc.isSet("end-reroute-output")) { PROGRESS_BEGIN_MESSAGE("Writing highway end rerouter"); detectors.writeEndRerouterDetectors(oc.getString("end-reroute-output")); // !!! PROGRESS_DONE_MESSAGE(); } /* // save the insertion definitions if(oc.isSet("flow-definitions")) { buildVehicleEmissions(oc.getString("flow-definitions")); } */ // }
void PCLoaderVisum::load(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill, PCTypeMap& tm) { GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing(); std::string what; std::map<long, Position> punkte; std::map<long, PositionVector> kanten; std::map<long, PositionVector> teilflaechen; std::map<long, long> flaechenelemente; NamedColumnsParser lineParser; LineReader lr(file); while (lr.hasMore()) { std::string line = lr.readLine(); // reset if current is over if (line.length() == 0 || line[0] == '*' || line[0] == '$') { what = ""; } // read items if (what == "$PUNKT") { lineParser.parseLine(line); long id = TplConvert<char>::_2long(lineParser.get("ID").c_str()); SUMOReal x = TplConvert<char>::_2SUMOReal(lineParser.get("XKOORD").c_str()); SUMOReal y = TplConvert<char>::_2SUMOReal(lineParser.get("YKOORD").c_str()); Position pos(x, y); if (!geoConvHelper.x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for point '" + toString(id) + "'."); } punkte[id] = pos; continue; } else if (what == "$KANTE") { lineParser.parseLine(line); long id = TplConvert<char>::_2long(lineParser.get("ID").c_str()); long fromID = TplConvert<char>::_2long(lineParser.get("VONPUNKTID").c_str()); long toID = TplConvert<char>::_2long(lineParser.get("NACHPUNKTID").c_str()); PositionVector vec; vec.push_back(punkte[fromID]); vec.push_back(punkte[toID]); kanten[id] = vec; continue; } else if (what == "$ZWISCHENPUNKT") { lineParser.parseLine(line); long id = TplConvert<char>::_2long(lineParser.get("KANTEID").c_str()); int index = TplConvert<char>::_2int(lineParser.get("INDEX").c_str()); SUMOReal x = TplConvert<char>::_2SUMOReal(lineParser.get("XKOORD").c_str()); SUMOReal y = TplConvert<char>::_2SUMOReal(lineParser.get("YKOORD").c_str()); Position pos(x, y); if (!geoConvHelper.x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for edge '" + toString(id) + "'."); } kanten[id].insertAt(index, pos); continue; } else if (what == "$TEILFLAECHENELEMENT") { lineParser.parseLine(line); long id = TplConvert<char>::_2long(lineParser.get("TFLAECHEID").c_str()); int index = TplConvert<char>::_2int(lineParser.get("INDEX").c_str()); index = 0; /// hmmmm - assume it's sorted... long kid = TplConvert<char>::_2long(lineParser.get("KANTEID").c_str()); int dir = TplConvert<char>::_2int(lineParser.get("RICHTUNG").c_str()); if (teilflaechen.find(id) == teilflaechen.end()) { teilflaechen[id] = PositionVector(); } if (dir == 0) { for (int i = 0; i < (int) kanten[kid].size(); ++i) { teilflaechen[id].push_back_noDoublePos(kanten[kid][i]); } } else { for (int i = (int) kanten[kid].size() - 1; i >= 0; --i) { teilflaechen[id].push_back_noDoublePos(kanten[kid][i]); } } continue; } else if (what == "$FLAECHENELEMENT") { lineParser.parseLine(line); long id = TplConvert<char>::_2long(lineParser.get("FLAECHEID").c_str()); long tid = TplConvert<char>::_2long(lineParser.get("TFLAECHEID").c_str()); int enklave = TplConvert<char>::_2int(lineParser.get("ENKLAVE").c_str()); // !!! unused enklave = 0; flaechenelemente[id] = tid; continue; } // set if read if (line[0] == '$') { what = ""; if (line.find("$PUNKT") == 0) { what = "$PUNKT"; } else if (line.find("$KANTE") == 0) { what = "$KANTE"; } else if (line.find("$ZWISCHENPUNKT") == 0) { what = "$ZWISCHENPUNKT"; } else if (line.find("$TEILFLAECHENELEMENT") == 0) { what = "$TEILFLAECHENELEMENT"; } else if (line.find("$FLAECHENELEMENT") == 0) { what = "$FLAECHENELEMENT"; } if (what != "") { lineParser.reinit(line.substr(what.length() + 1)); } } } // do some more sane job... RGBColor c = RGBColor::parseColor(oc.getString("color")); std::map<std::string, std::string> typemap; // load the pois/polys lr.reinit(); bool parsingCategories = false; bool parsingPOIs = false; bool parsingDistrictsDirectly = false; PositionVector vec; std::string polyType, lastID; bool first = true; while (lr.hasMore()) { std::string line = lr.readLine(); // do not parse empty lines if (line.length() == 0) { continue; } // do not parse comment lines if (line[0] == '*') { continue; } if (line[0] == '$') { // reset parsing on new entry type parsingCategories = false; parsingPOIs = false; parsingDistrictsDirectly = false; polyType = ""; } if (parsingCategories) { // parse the category StringTokenizer st(line, ";"); std::string catid = st.next(); std::string catname = st.next(); typemap[catid] = catname; } if (parsingPOIs) { // parse the poi // $POI:Nr;CATID;CODE;NAME;Kommentar;XKoord;YKoord; StringTokenizer st(line, ";"); std::string num = st.next(); std::string catid = st.next(); std::string code = st.next(); std::string name = st.next(); std::string comment = st.next(); std::string xpos = st.next(); std::string ypos = st.next(); // process read values SUMOReal x = TplConvert<char>::_2SUMOReal(xpos.c_str()); SUMOReal y = TplConvert<char>::_2SUMOReal(ypos.c_str()); Position pos(x, y); if (!geoConvHelper.x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for POI '" + num + "'."); } std::string type = typemap[catid]; // check the poi name = num; // patch the values bool discard = oc.getBool("discard"); int layer = oc.getInt("layer"); RGBColor color; if (tm.has(type)) { const PCTypeMap::TypeDef& def = tm.get(type); name = def.prefix + name; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = def.layer; } else { name = oc.getString("prefix") + name; type = oc.getString("type"); color = c; } if (!discard) { PointOfInterest* poi = new PointOfInterest(name, type, pos, color); if (!toFill.insert(name, poi, layer)) { WRITE_ERROR("POI '" + name + "' could not been added."); delete poi; } } } // poly if (polyType != "") { StringTokenizer st(line, ";"); std::string id = st.next(); std::string type; if (!first && lastID != id) { // we have parsed a polygon completely RGBColor color; int layer = oc.getInt("layer"); bool discard = oc.getBool("discard"); if (tm.has(polyType)) { const PCTypeMap::TypeDef& def = tm.get(polyType); id = def.prefix + id; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = def.layer; } else { id = oc.getString("prefix") + id; type = oc.getString("type"); color = c; } if (!discard) { Polygon* poly = new Polygon(id, type, color, vec, false); if (!toFill.insert(id, poly, 1)) { WRITE_ERROR("Polygon '" + id + "' could not been added."); delete poly; } } vec.clear(); } lastID = id; first = false; // parse current poly std::string index = st.next(); std::string xpos = st.next(); std::string ypos = st.next(); Position pos2D((SUMOReal) atof(xpos.c_str()), (SUMOReal) atof(ypos.c_str())); if (!geoConvHelper.x2cartesian(pos2D)) { WRITE_WARNING("Unable to project coordinates for polygon '" + id + "'."); } vec.push_back(pos2D); } // district refering a shape if (parsingDistrictsDirectly) { //$BEZIRK:NR CODE NAME TYPNR XKOORD YKOORD FLAECHEID BEZART IVANTEIL_Q IVANTEIL_Z OEVANTEIL METHODEANBANTEILE ZWERT1 ZWERT2 ZWERT3 ISTINAUSWAHL OBEZNR NOM_COM COD_COM StringTokenizer st(line, ";"); std::string num = st.next(); std::string code = st.next(); std::string name = st.next(); st.next(); // typntr std::string xpos = st.next(); std::string ypos = st.next(); long id = TplConvert<char>::_2long(st.next().c_str()); // patch the values std::string type = "district"; name = num; bool discard = oc.getBool("discard"); int layer = oc.getInt("layer"); RGBColor color; if (tm.has(type)) { const PCTypeMap::TypeDef& def = tm.get(type); name = def.prefix + name; type = def.id; color = RGBColor::parseColor(def.color); discard = def.discard; layer = def.layer; } else { name = oc.getString("prefix") + name; type = oc.getString("type"); color = c; } if (!discard) { if (teilflaechen[flaechenelemente[id]].size() > 0) { Polygon* poly = new Polygon(name, type, color, teilflaechen[flaechenelemente[id]], false); if (!toFill.insert(name, poly, layer)) { WRITE_ERROR("Polygon '" + name + "' could not been added."); delete poly; } } else { SUMOReal x = TplConvert<char>::_2SUMOReal(xpos.c_str()); SUMOReal y = TplConvert<char>::_2SUMOReal(ypos.c_str()); Position pos(x, y); if (!geoConvHelper.x2cartesian(pos)) { WRITE_WARNING("Unable to project coordinates for POI '" + name + "'."); } PointOfInterest* poi = new PointOfInterest(name, type, pos, color); if (!toFill.insert(name, poi, layer)) { WRITE_ERROR("POI '" + name + "' could not been added."); delete poi; } } } } if (line.find("$POIKATEGORIEDEF:") == 0 || line.find("$POIKATEGORIE:") == 0) { // ok, got categories, begin parsing from next line parsingCategories = true; } if (line.find("$POI:") == 0) { // ok, got pois, begin parsing from next line parsingPOIs = true; } if (line.find("$BEZIRK") == 0 && line.find("FLAECHEID") != std::string::npos) { // ok, have a district header, and it seems like districts would reference shapes... parsingDistrictsDirectly = true; } if (line.find("$BEZIRKPOLY") != std::string::npos) { polyType = "district"; } if (line.find("$GEBIETPOLY") != std::string::npos) { polyType = "area"; } } }