PCLoaderDlrNavteq Class Reference

#include <PCLoaderDlrNavteq.h>


Detailed Description

A reader of pois and polygons stored in DLR-Navteq (Elmar)-format.

Reads pois stored in "pointcollection.txt" and polygons stored in "...polygons.txt"/"...water_polygons.txt", applies the given projection and network offset and stores the so build pois/polys into the given map.

Definition at line 55 of file PCLoaderDlrNavteq.h.


Static Public Member Functions

static void loadIfSet (OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError)
 Loads pois/polygons assumed to be stored as according DLR-Navteq (Elmar)-files.

Static Protected Member Functions

static void loadPOIFile (const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError)
 Loads DLR-Navteq (Elmar)-pois from the given file.
static void loadPOIFiles (OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError)
 Loads pois assumed to be stored as according DLR-Navteq (Elmar)-files.
static void loadPolyFile (const std::string &file, OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError)
 Loads DLR-Navteq (Elmar)-polygons from the given file.
static void loadPolyFiles (OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError)
 Loads polygons assumed to be stored as according DLR-Navteq (Elmar)-files.

Member Function Documentation

void PCLoaderDlrNavteq::loadIfSet ( OptionsCont oc,
PCPolyContainer toFill,
PCTypeMap tm 
) throw (ProcessError) [static]

Loads pois/polygons assumed to be stored as according DLR-Navteq (Elmar)-files.

If the option "elmar-poi-files" is set within the given options container, the files stored herein are parsed using "loadPOIFiles", assuming this option contains file paths to files containing pois stored in DLR-Navteq "pointcollection.txt"-format.

If the option "elmar-poly-files" is set within the given options container, the files stored herein are parsed using "loadPolyFiles", assuming this option contains file paths to files containing polygons stored in DLR-Navteq "...polygons.txt"/"...water_polygons.txt"-format.

Parameters:
[in] oc The options container to get further options from
[in] toFill The poly/pois container to add loaded polys/pois to
[in] tm The type map to use for setting values of loaded polys/pois
Exceptions:
ProcessError if something fails

Definition at line 63 of file PCLoaderDlrNavteq.cpp.

Referenced by main().

00064                                                                 {
00065     if (oc.isSet("dlr-navteq-poly-files")) {
00066         loadPolyFiles(oc, toFill, tm);
00067     }
00068     if (oc.isSet("dlr-navteq-poi-files")) {
00069         loadPOIFiles(oc, toFill, tm);
00070     }
00071 }

void PCLoaderDlrNavteq::loadPOIFile ( const std::string &  file,
OptionsCont oc,
PCPolyContainer toFill,
PCTypeMap tm 
) throw (ProcessError) [static, protected]

Loads DLR-Navteq (Elmar)-pois from the given file.

Parameters:
[in] file The name of the file to parse
[in] oc The options container to get further options from
[in] toFill The poly/pois container to add loaded polys to
[in] tm The type map to use for setting values of loaded polys
Exceptions:
ProcessError if something fails

Definition at line 105 of file PCLoaderDlrNavteq.cpp.

References PCTypeMap::TypeDef::color, PCTypeMap::TypeDef::discard, MsgHandler::getErrorInstance(), OptionsCont::getOptions(), LineReader::hasMore(), PCTypeMap::TypeDef::id, MsgHandler::inform(), PCTypeMap::TypeDef::layer, RGBColor::parseColor(), PCTypeMap::TypeDef::prefix, StringUtils::prune(), LineReader::readLine(), toString(), and GeoConvHelper::x2cartesian().

00107                                                                   {
00108     // get the defaults
00109     RGBColor c = RGBColor::parseColor(oc.getString("color"));
00110     // parse
00111     int l = 0;
00112     LineReader lr(file);
00113     while (lr.hasMore()) {
00114         std::string line = lr.readLine();
00115         ++l;
00116         // skip invalid/empty lines
00117         if (line.length()==0||line.find("#") != std::string::npos) {
00118             continue;
00119         }
00120         if (StringUtils::prune(line)=="") {
00121             continue;
00122         }
00123         // parse the poi
00124         std::istringstream stream(line);
00125         // attributes of the poi
00126         std::string name, skip, type, desc;
00127         std::getline(stream, name, '\t');
00128         std::getline(stream, skip, '\t');
00129         std::getline(stream, type, '\t');
00130         std::getline(stream, desc, '\t');
00131         if (stream.fail()) {
00132             throw ProcessError("Invalid dlr-navteq-poi in line " + toString(l) +":\n" + line);
00133         }
00134         double x, y;
00135         stream >> x;
00136         if (stream.fail()) {
00137             throw ProcessError("Invalid x coordinate for POI '" + name + "'.");
00138         }
00139         stream >> y;
00140         if (stream.fail()) {
00141             throw ProcessError("Invalid y coordinate for POI '" + name + "'.");
00142         }
00143         Position2D pos(x, y);
00144         // check the poi
00145         if (name=="") {
00146             throw ProcessError("The name of a POI is missing.");
00147         }
00148         if (!GeoConvHelper::x2cartesian(pos, true, x, y)) {
00149             throw ProcessError("Unable to project coordinates for POI '" + name + "'.");
00150         }
00151 
00152         // patch the values
00153         bool discard = false;
00154         int layer = oc.getInt("layer");
00155         RGBColor color;
00156         if (tm.has(type)) {
00157             const PCTypeMap::TypeDef &def = tm.get(type);
00158             name = def.prefix + name;
00159             type = def.id;
00160             color = RGBColor::parseColor(def.color);
00161             discard = def.discard;
00162             layer = def.layer;
00163         } else {
00164             name = oc.getString("prefix") + name;
00165             type = oc.getString("type");
00166             color = c;
00167         }
00168         if (!discard) {
00169             bool ignorePrunning = false;
00170             if (OptionsCont::getOptions().isInStringVector("prune.ignore", name)) {
00171                 ignorePrunning = true;
00172             }
00173             PointOfInterest *poi = new PointOfInterest(name, type, pos, color);
00174             if (!toFill.insert(name, poi, layer, ignorePrunning)) {
00175                 MsgHandler::getErrorInstance()->inform("POI '" + name + "' could not been added.");
00176                 delete poi;
00177             }
00178         }
00179     }
00180 }

void PCLoaderDlrNavteq::loadPOIFiles ( OptionsCont oc,
PCPolyContainer toFill,
PCTypeMap tm 
) throw (ProcessError) [static, protected]

Loads pois assumed to be stored as according DLR-Navteq (Elmar)-files.

Goes through the list of files given in "elmar-poi-files". Calls "loadPOIFile" using each of these as the first parameter.

Parameters:
[in] oc The options container to get further options from
[in] toFill The poly/pois container to add loaded pois to
[in] tm The type map to use for setting values of loaded pois
Exceptions:
ProcessError if something fails

Definition at line 75 of file PCLoaderDlrNavteq.cpp.

References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), and MsgHandler::getMessageInstance().

00076                                                                    {
00077     std::vector<std::string> files = oc.getStringVector("dlr-navteq-poi-files");
00078     for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) {
00079         if (!FileHelpers::exists(*file)) {
00080             throw ProcessError("Could not open dlr-navteq-poi-file '" + *file + "'.");
00081         }
00082         MsgHandler::getMessageInstance()->beginProcessMsg("Parsing pois from dlr-navteq-poi-file '" + *file + "'...");
00083         loadPOIFile(*file, oc, toFill, tm);
00084         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00085     }
00086 }

void PCLoaderDlrNavteq::loadPolyFile ( const std::string &  file,
OptionsCont oc,
PCPolyContainer toFill,
PCTypeMap tm 
) throw (ProcessError) [static, protected]

Loads DLR-Navteq (Elmar)-polygons from the given file.

Parameters:
[in] file The name of the file to parse
[in] oc The options container to get further options from
[in] toFill The poly/pois container to add loaded polys to
[in] tm The type map to use for setting values of loaded polys
Exceptions:
ProcessError if something fails

Definition at line 184 of file PCLoaderDlrNavteq.cpp.

References TplConvert< E >::_2SUMOReal(), PCTypeMap::TypeDef::allowFill, Position2DVector::clear(), PCTypeMap::TypeDef::color, StringUtils::convertUmlaute(), PCTypeMap::TypeDef::discard, Position2DVector::getBegin(), Position2DVector::getEnd(), MsgHandler::getErrorInstance(), StringTokenizer::getVector(), MsgHandler::getWarningInstance(), LineReader::hasMore(), PCTypeMap::TypeDef::id, MsgHandler::inform(), PCTypeMap::TypeDef::layer, RGBColor::parseColor(), PCTypeMap::TypeDef::prefix, StringUtils::prune(), Position2DVector::push_back(), LineReader::readLine(), Position2DVector::size(), SUMOReal, toString(), and GeoConvHelper::x2cartesian().

00186                                                                    {
00187     // get the defaults
00188     RGBColor c = RGBColor::parseColor(oc.getString("color"));
00189     // attributes of the poly
00190     // parse
00191     int l = 0;
00192     LineReader lr(file);
00193     while (lr.hasMore()) {
00194         std::string line = lr.readLine();
00195         ++l;
00196         // skip invalid/empty lines
00197         if (line.length()==0||line.find("#") != std::string::npos) {
00198             continue;
00199         }
00200         if (StringUtils::prune(line)=="") {
00201             continue;
00202         }
00203         // parse the poi
00204         StringTokenizer st(line, "\t");
00205         std::vector<std::string> values = st.getVector();
00206         if (values.size()<6||values.size()%2!=0) {
00207             throw ProcessError("Invalid dlr-navteq-polygon - line: '" + line + "'.");
00208         }
00209         std::string id = values[0];
00210         std::string ort = values[1];
00211         std::string type = values[2];
00212         std::string name = values[3];
00213         Position2DVector vec;
00214         size_t index = 4;
00215         // now collect the positions
00216         while (values.size()>index) {
00217             std::string xpos = values[index];
00218             std::string ypos = values[index+1];
00219             index += 2;
00220             SUMOReal x = TplConvert<char>::_2SUMOReal(xpos.c_str());
00221             SUMOReal y = TplConvert<char>::_2SUMOReal(ypos.c_str());
00222             Position2D pos(x, y);
00223             if (!GeoConvHelper::x2cartesian(pos)) {
00224                 MsgHandler::getWarningInstance()->inform("Unable to project coordinates for polygon '" + id + "'.");
00225             }
00226             vec.push_back(pos);
00227         }
00228 
00229         name = StringUtils::convertUmlaute(name);
00230         if (name=="noname"||toFill.containsPolygon(name)) {
00231             name = name + "#" + toString(toFill.getEnumIDFor(name));
00232         }
00233 
00234         // check the polygon
00235         if (vec.size()==0) {
00236             MsgHandler::getWarningInstance()->inform("The polygon '" + id + "' is empty.");
00237             continue;
00238         }
00239         if (id=="") {
00240             MsgHandler::getWarningInstance()->inform("The name of a polygon is missing; it will be discarded.");
00241             continue;
00242         }
00243 
00244         // patch the values
00245         bool fill = vec.getBegin()==vec.getEnd();
00246         bool discard = false;
00247         int layer = oc.getInt("layer");
00248         RGBColor color;
00249         if (tm.has(type)) {
00250             const PCTypeMap::TypeDef &def = tm.get(type);
00251             name = def.prefix + name;
00252             type = def.id;
00253             color = RGBColor::parseColor(def.color);
00254             fill = fill && def.allowFill;
00255             discard = def.discard;
00256             layer = def.layer;
00257         } else {
00258             name = oc.getString("prefix") + name;
00259             type = oc.getString("type");
00260             color = c;
00261         }
00262         if (!discard) {
00263             Polygon2D *poly = new Polygon2D(name, type, color, vec, fill);
00264             if (!toFill.insert(name, poly, layer)) {
00265                 MsgHandler::getErrorInstance()->inform("Polygon '" + name + "' could not been added.");
00266                 delete poly;
00267             }
00268         }
00269         vec.clear();
00270     }
00271 }

void PCLoaderDlrNavteq::loadPolyFiles ( OptionsCont oc,
PCPolyContainer toFill,
PCTypeMap tm 
) throw (ProcessError) [static, protected]

Loads polygons assumed to be stored as according DLR-Navteq (Elmar)-files.

Goes through the list of files given in "elmar-poly-files". Calls "loadPolyFile" using each of these as the first parameter.

Parameters:
[in] oc The options container to get further options from
[in] toFill The poly/pois container to add loaded polys to
[in] tm The type map to use for setting values of loaded polys
Exceptions:
ProcessError if something fails

Definition at line 90 of file PCLoaderDlrNavteq.cpp.

References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), and MsgHandler::getMessageInstance().

00091                                                                     {
00092     std::vector<std::string> files = oc.getStringVector("dlr-navteq-poly-files");
00093     for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) {
00094         if (!FileHelpers::exists(*file)) {
00095             throw ProcessError("Could not open dlr-navteq-poly-file '" + *file + "'.");
00096         }
00097         MsgHandler::getMessageInstance()->beginProcessMsg("Parsing pois from dlr-navteq-poly-file '" + *file + "'...");
00098         loadPolyFile(*file, oc, toFill, tm);
00099         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00100     }
00101 }


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:58 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6