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); } } }
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 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"; } } }