#include <PCLoaderOSM.h>

Reads pois stored as XML definition as given by the OpenStreetMap-API.
Definition at line 53 of file PCLoaderOSM.h.
Public Member Functions | |
| void | characters (const XMLCh *const chars, const XERCES3_SIZE_t length) |
| The inherited method called when characters occured. | |
| void | endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) |
| The inherited method called when a tag is being closed. | |
| const std::string & | getFileName () const throw () |
| returns the current file name | |
| void | registerParent (const SumoXMLTag tag, GenericSAXHandler *handler) |
| Assigning a parent handler which is enabled when the specified tag is closed. | |
| void | setFileName (const std::string &name) throw () |
| Sets the current file name. | |
| void | startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs) |
| The inherited method called when a new tag opens. | |
SAX ErrorHandler callbacks | |
| void | error (const SAXParseException &exception) throw (ProcessError) |
| Handler for XML-errors. | |
| void | fatalError (const SAXParseException &exception) throw (ProcessError) |
| Handler for XML-errors. | |
| void | warning (const SAXParseException &exception) throw () |
| Handler for XML-warnings. | |
Static Public Member Functions | |
| static void | loadIfSet (OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm) throw (ProcessError) |
| Loads pois/polygons assumed to be stored as OSM-XML. | |
Protected Member Functions | |
| std::string | buildErrorMessage (const SAXParseException &exception) throw () |
| Builds an error message. | |
| virtual void | myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError) |
| Callback method for characters to implement by derived classes. | |
| virtual void | myEndElement (SumoXMLTag element) throw (ProcessError) |
| Callback method for a closing tag to implement by derived classes. | |
| virtual void | myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError) |
| Callback method for an opening tag to implement by derived classes. | |
Data Structures | |
| class | EdgesHandler |
| A class which extracts OSM-edges from a parsed OSM-file. More... | |
| class | NodesHandler |
| A class which extracts OSM-nodes from a parsed OSM-file. More... | |
| struct | PCOSMEdge |
| An internal definition of a loaded edge. More... | |
| struct | PCOSMNode |
| An internal representation of an OSM-node. More... | |
| std::string SUMOSAXHandler::buildErrorMessage | ( | const SAXParseException & | exception | ) | throw () [protected, inherited] |
Builds an error message.
The error message includes the file name and the line/column information as supported by the given SAXParseException
| [in] | exception | The name of the currently processed file |
Definition at line 55 of file SUMOSAXHandler.cpp.
References GenericSAXHandler::getFileName().
Referenced by SUMOSAXHandler::error(), SUMOSAXHandler::fatalError(), and SUMOSAXHandler::warning().
00055 { 00056 std::ostringstream buf; 00057 char *pMsg = XMLString::transcode(exception.getMessage()); 00058 buf << pMsg << std::endl; 00059 buf << " In file '" << getFileName() << "'" << std::endl; 00060 buf << " At line/column " << exception.getLineNumber()+1 00061 << '/' << exception.getColumnNumber() << "." << std::endl; 00062 XMLString::release(&pMsg); 00063 return buf.str(); 00064 }
| void GenericSAXHandler::characters | ( | const XMLCh *const | chars, | |
| const XERCES3_SIZE_t | length | |||
| ) | [inherited] |
The inherited method called when characters occured.
The retrieved characters are converted into a string and appended into a private buffer. They are reported as soon as the element ends.
Definition at line 168 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myCharactersVector.
00169 { 00170 myCharactersVector.push_back(TplConvert<XMLCh>::_2str(chars, length)); 00171 }
| void GenericSAXHandler::endElement | ( | const XMLCh *const | uri, | |
| const XMLCh *const | localname, | |||
| const XMLCh *const | qname | |||
| ) | [inherited] |
The inherited method called when a tag is being closed.
This method calls the user-implemented methods myCharacters with the previously collected and converted characters.
Then, myEndElement is called, supplying it the qname converted to its enum- and string-representations.
Definition at line 118 of file GenericSAXHandler.cpp.
References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), GenericSAXHandler::myCharacters(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myEndElement(), GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.
00120 { 00121 std::string name = TplConvert<XMLCh>::_2str(qname); 00122 SumoXMLTag element = convertTag(name); 00123 // collect characters 00124 if (myCharactersVector.size()!=0) { 00125 size_t len = 0; 00126 unsigned i; 00127 for (i=0; i<myCharactersVector.size(); ++i) { 00128 len += myCharactersVector[i].length(); 00129 } 00130 char *buf = new char[len+1]; 00131 size_t pos = 0; 00132 for (i=0; i<myCharactersVector.size(); ++i) { 00133 memcpy((unsigned char*) buf+pos, (unsigned char*) myCharactersVector[i].c_str(), 00134 sizeof(char)*myCharactersVector[i].length()); 00135 pos += myCharactersVector[i].length(); 00136 } 00137 buf[pos] = 0; 00138 00139 // call user handler 00140 try { 00141 myCharacters(element, buf); 00142 } catch (std::runtime_error &) { 00143 delete[] buf; 00144 throw; 00145 } 00146 delete[] buf; 00147 } 00148 if (element != SUMO_TAG_INCLUDE) { 00149 myEndElement(element); 00150 if (myParentHandler && myParentIndicator == element) { 00151 XMLSubSys::setHandler(*myParentHandler); 00152 myParentIndicator = SUMO_TAG_NOTHING; 00153 myParentHandler = 0; 00154 } 00155 } 00156 }
| void SUMOSAXHandler::error | ( | const SAXParseException & | exception | ) | throw (ProcessError) [inherited] |
Handler for XML-errors.
The message is built using buildErrorMessage and thrown within a ProcessError.
| [in] | exception | The occured exception to process |
| ProcessError | On any call |
Definition at line 74 of file SUMOSAXHandler.cpp.
References SUMOSAXHandler::buildErrorMessage().
00074 { 00075 throw ProcessError(buildErrorMessage(exception)); 00076 }
| void SUMOSAXHandler::fatalError | ( | const SAXParseException & | exception | ) | throw (ProcessError) [inherited] |
Handler for XML-errors.
The message is built using buildErrorMessage and thrown within a ProcessError.
| ProcessError | On any call |
| [in] | exception | The occured exception to process |
Definition at line 80 of file SUMOSAXHandler.cpp.
References SUMOSAXHandler::buildErrorMessage().
00080 { 00081 throw ProcessError(buildErrorMessage(exception)); 00082 }
| const std::string & GenericSAXHandler::getFileName | ( | ) | const throw () [inherited] |
returns the current file name
Definition at line 78 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myFileName.
Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addRouteProbeDetector(), NLHandler::addSource(), NLHandler::addTrigger(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), SUMOSAXHandler::buildErrorMessage(), MSRouteLoader::init(), PCNetProjectionLoader::loadIfSet(), NILoader::loadXMLType(), MSTriggeredXMLReader::myInit(), RODFDetectorHandler::myStartElement(), NLHandler::myStartElement(), NIImporter_OpenDrive::myStartElement(), MSLaneSpeedTrigger::myStartElement(), GUISettingsHandler::myStartElement(), RORDGenerator_ODAmounts::RORDGenerator_ODAmounts(), and GenericSAXHandler::startElement().
00078 { 00079 return myFileName; 00080 }
| void PCLoaderOSM::loadIfSet | ( | OptionsCont & | oc, | |
| PCPolyContainer & | toFill, | |||
| PCTypeMap & | tm | |||
| ) | throw (ProcessError) [static] |
Loads pois/polygons assumed to be stored as OSM-XML.
If the option "osm-files" is set within the given options container, an instance of PCLoaderOSM is built and used as a handler for the files given in this option.
| [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 |
| ProcessError | if something fails |
Definition at line 61 of file PCLoaderOSM.cpp.
References PCTypeMap::TypeDef::allowFill, MsgHandler::beginProcessMsg(), PCTypeMap::TypeDef::color, PCTypeMap::TypeDef::discard, MsgHandler::endProcessMsg(), FileHelpers::exists(), Position2DVector::getBegin(), Position2DVector::getEnd(), MsgHandler::getErrorInstance(), MsgHandler::getMessageInstance(), OptionsCont::getOptions(), MsgHandler::getWarningInstance(), PCLoaderOSM::PCOSMNode::id, PCTypeMap::TypeDef::id, PCLoaderOSM::PCOSMEdge::id, MsgHandler::inform(), OptionsCont::isInStringVector(), PCLoaderOSM::PCOSMNode::lat, PCTypeMap::TypeDef::layer, PCLoaderOSM::PCOSMNode::lon, PCLoaderOSM::PCOSMEdge::myCurrentNodes, PCLoaderOSM::PCOSMNode::myIsAdditional, PCLoaderOSM::PCOSMEdge::myIsAdditional, PCLoaderOSM::PCOSMNode::myType, PCLoaderOSM::PCOSMEdge::myType, RGBColor::parseColor(), PCTypeMap::TypeDef::prefix, Position2DVector::push_back_noDoublePos(), XMLSubSys::runParser(), toString(), and GeoConvHelper::x2cartesian().
Referenced by main().
00062 { 00063 if (!oc.isSet("osm-files")) { 00064 return; 00065 } 00066 // parse file(s) 00067 std::vector<std::string> files = oc.getStringVector("osm-files"); 00068 // load nodes, first 00069 std::map<int, PCOSMNode*> nodes; 00070 NodesHandler nodesHandler(nodes); 00071 for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) { 00072 // nodes 00073 if (!FileHelpers::exists(*file)) { 00074 MsgHandler::getErrorInstance()->inform("Could not open osm-file '" + *file + "'."); 00075 return; 00076 } 00077 MsgHandler::getMessageInstance()->beginProcessMsg("Parsing nodes from osm-file '" + *file + "'..."); 00078 if (!XMLSubSys::runParser(nodesHandler, *file)) { 00079 throw ProcessError(); 00080 } 00081 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00082 } 00083 // load edges, then 00084 std::map<std::string, PCOSMEdge*> edges; 00085 EdgesHandler edgesHandler(nodes, edges); 00086 for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) { 00087 // edges 00088 MsgHandler::getMessageInstance()->beginProcessMsg("Parsing edges from osm-file '" + *file + "'..."); 00089 XMLSubSys::runParser(edgesHandler, *file); 00090 MsgHandler::getMessageInstance()->endProcessMsg("done."); 00091 } 00092 // build all 00093 RGBColor c = RGBColor::parseColor(oc.getString("color")); 00094 // instatiate polygons 00095 for (std::map<std::string, PCOSMEdge*>::iterator i=edges.begin(); i!=edges.end(); ++i) { 00096 PCOSMEdge *e = (*i).second; 00097 if (!e->myIsAdditional) { 00098 continue; 00099 } 00100 // compute shape 00101 Position2DVector vec; 00102 for (std::vector<int>::iterator j=e->myCurrentNodes.begin(); j!=e->myCurrentNodes.end(); ++j) { 00103 PCOSMNode *n = nodes.find(*j)->second; 00104 Position2D pos(n->lon, n->lat); 00105 if (!GeoConvHelper::x2cartesian(pos)) { 00106 MsgHandler::getWarningInstance()->inform("Unable to project coordinates for polygon '" + e->id + "'."); 00107 } 00108 vec.push_back_noDoublePos(pos); 00109 } 00110 // set type etc. 00111 std::string name = e->id; 00112 std::string type; 00113 RGBColor color; 00114 bool fill = vec.getBegin()==vec.getEnd(); 00115 bool discard = false; 00116 int layer = oc.getInt("layer"); 00117 if (tm.has(e->myType)) { 00118 const PCTypeMap::TypeDef &def = tm.get(e->myType); 00119 name = def.prefix + name; 00120 type = def.id; 00121 color = RGBColor::parseColor(def.color); 00122 fill = fill && def.allowFill; 00123 discard = def.discard; 00124 layer = def.layer; 00125 } else if (e->myType.find(".")!=std::string::npos&&tm.has(e->myType.substr(0, e->myType.find(".")))) { 00126 const PCTypeMap::TypeDef &def = tm.get(e->myType.substr(0, e->myType.find("."))); 00127 name = def.prefix + name; 00128 type = def.id; 00129 color = RGBColor::parseColor(def.color); 00130 fill = fill && def.allowFill; 00131 discard = def.discard; 00132 layer = def.layer; 00133 } else { 00134 name = oc.getString("prefix") + name; 00135 type = oc.getString("type"); 00136 color = c; 00137 } 00138 if (!discard) { 00139 if (oc.getBool("osm.keep-full-type")) { 00140 type = e->myType; 00141 } 00142 Polygon2D *poly = new Polygon2D(name, type, color, vec, fill); 00143 if (!toFill.insert(name, poly, layer)) { 00144 MsgHandler::getErrorInstance()->inform("Polygon '" + name + "' could not been added."); 00145 delete poly; 00146 } 00147 } 00148 } 00149 // instantiate pois 00150 for (std::map<int, PCOSMNode*>::iterator i=nodes.begin(); i!=nodes.end(); ++i) { 00151 PCOSMNode *n = (*i).second; 00152 if (!n->myIsAdditional) { 00153 continue; 00154 } 00155 00156 // patch the values 00157 bool discard = false; 00158 int layer = oc.getInt("layer"); 00159 std::string name = toString(n->id); 00160 std::string type; 00161 RGBColor color; 00162 if (tm.has(n->myType)) { 00163 const PCTypeMap::TypeDef &def = tm.get(n->myType); 00164 name = def.prefix + name; 00165 type = def.id; 00166 color = RGBColor::parseColor(def.color); 00167 discard = def.discard; 00168 layer = def.layer; 00169 } else if (type.find(".")!=std::string::npos&&tm.has(type.substr(0, type.find(".")))) { 00170 const PCTypeMap::TypeDef &def = tm.get(type.substr(0, type.find("."))); 00171 name = def.prefix + name; 00172 type = def.id; 00173 color = RGBColor::parseColor(def.color); 00174 discard = def.discard; 00175 layer = def.layer; 00176 } else { 00177 name = oc.getString("prefix") + name; 00178 type = oc.getString("type"); 00179 color = c; 00180 } 00181 if (!discard) { 00182 if (oc.getBool("osm.keep-full-type")) { 00183 type = n->myType; 00184 } 00185 bool ignorePrunning = false; 00186 if (OptionsCont::getOptions().isInStringVector("prune.ignore", name)) { 00187 ignorePrunning = true; 00188 } 00189 Position2D pos(n->lon, n->lat); 00190 if (!GeoConvHelper::x2cartesian(pos)) { 00191 MsgHandler::getWarningInstance()->inform("Unable to project coordinates for POI '" + name + "'."); 00192 } 00193 PointOfInterest *poi = new PointOfInterest(name, type, pos, color); 00194 if (!toFill.insert(name, poi, layer, ignorePrunning)) { 00195 MsgHandler::getErrorInstance()->inform("POI '" + name + "' could not been added."); 00196 delete poi; 00197 } 00198 } 00199 } 00200 00201 00202 // delete nodes 00203 for (std::map<int, PCOSMNode*>::const_iterator i=nodes.begin(); i!=nodes.end(); ++i) { 00204 delete(*i).second; 00205 } 00206 // delete edges 00207 for (std::map<std::string, PCOSMEdge*>::iterator i=edges.begin(); i!=edges.end(); ++i) { 00208 delete(*i).second; 00209 } 00210 }
| void GenericSAXHandler::myCharacters | ( | SumoXMLTag | element, | |
| const std::string & | chars | |||
| ) | throw (ProcessError) [protected, virtual, inherited] |
Callback method for characters to implement by derived classes.
Called by "endElement" (see there).
| [in] | element | The opened element, given as a SumoXMLTag |
| [in] | chars | The complete embedded character string ProcessError These method may throw a ProcessError if something fails |
Reimplemented in ROJTRTurnDefLoader, MSRouteHandler, NIImporter_OpenDrive, NIImporter_SUMO, NLHandler, PCLoaderXML, PCNetProjectionLoader, and RORDLoader_SUMOBase.
Definition at line 189 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler::endElement().
| void GenericSAXHandler::myEndElement | ( | SumoXMLTag | element | ) | throw (ProcessError) [protected, virtual, inherited] |
Callback method for a closing tag to implement by derived classes.
Called by "endElement" (see there).
| [in] | element | The closed element, given as a SumoXMLTag ProcessError These method may throw a ProcessError if something fails |
Reimplemented in MSRouteHandler, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLEdgesHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, traci::TraCIHandler, and SAXWeightsHandler.
Definition at line 193 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler::endElement().
| void GenericSAXHandler::myStartElement | ( | SumoXMLTag | element, | |
| const SUMOSAXAttributes & | attrs | |||
| ) | throw (ProcessError) [protected, virtual, inherited] |
Callback method for an opening tag to implement by derived classes.
Called by "startElement" (see there).
| [in] | element | The element that contains the characters, given as a SumoXMLTag |
| [in] | attrs | The SAX-attributes, wrapped as SUMOSAXAttributes ProcessError These method may throw a ProcessError if something fails |
Reimplemented in RODFDetectorHandler, ROJTRTurnDefLoader, MSRouteHandler, MSCalibrator::MSCalibrator_FileTriggeredChild, MSEmitter::MSEmitter_FileTriggeredChild, MSLaneSpeedTrigger, MSTriggeredRerouter, NIImporter_OpenDrive, NIImporter_OpenStreetMap::NodesHandler, NIImporter_OpenStreetMap::EdgesHandler, NIImporter_SUMO, NIXMLConnectionsHandler, NIXMLEdgesHandler, NIXMLNodesHandler, NIXMLTypesHandler, NLHandler, ODDistrictHandler, PCLoaderOSM::NodesHandler, PCLoaderOSM::EdgesHandler, PCLoaderXML, PCNetProjectionLoader, PCTypeDefHandler, RONetHandler, RORDGenerator_ODAmounts, RORDLoader_SUMOBase, RORDLoader_TripDefs, traci::TraCIHandler, GUISettingsHandler, and SAXWeightsHandler.
Definition at line 185 of file GenericSAXHandler.cpp.
Referenced by GenericSAXHandler::startElement().
| void GenericSAXHandler::registerParent | ( | const SumoXMLTag | tag, | |
| GenericSAXHandler * | handler | |||
| ) | [inherited] |
Assigning a parent handler which is enabled when the specified tag is closed.
Definition at line 160 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, and XMLSubSys::setHandler().
Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger().
00160 { 00161 myParentHandler = handler; 00162 myParentIndicator = tag; 00163 XMLSubSys::setHandler(*this); 00164 }
| void GenericSAXHandler::setFileName | ( | const std::string & | name | ) | throw () [inherited] |
Sets the current file name.
| [in] | name | The name of the currently processed file |
Definition at line 72 of file GenericSAXHandler.cpp.
References GenericSAXHandler::myFileName.
Referenced by PCNetProjectionLoader::loadIfSet(), ROLoader::loadNet(), NIImporter_OpenStreetMap::loadNetwork(), NILoader::loadXMLType(), and traci::TraCIServer::TraCIServer().
00072 { 00073 myFileName = name; 00074 }
| void GenericSAXHandler::startElement | ( | const XMLCh *const | uri, | |
| const XMLCh *const | localname, | |||
| const XMLCh *const | qname, | |||
| const Attributes & | attrs | |||
| ) | [inherited] |
The inherited method called when a new tag opens.
The method parses the supplied XMLCh*-qname using the internal name/enum-map to obtain the enum representation of the attribute name.
Then, "myStartElement" is called supplying the enumeration value, the string-representation of the name and the attributes.
Definition at line 97 of file GenericSAXHandler.cpp.
References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), FileHelpers::getConfigurationRelative(), GenericSAXHandler::getFileName(), SUMOSAXAttributesImpl_Xerces::getString(), FileHelpers::isAbsolute(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myPredefinedTags, GenericSAXHandler::myPredefinedTagsMML, GenericSAXHandler::myStartElement(), XMLSubSys::runParser(), SUMO_ATTR_HREF, and SUMO_TAG_INCLUDE.
00100 { 00101 std::string name = TplConvert<XMLCh>::_2str(qname); 00102 SumoXMLTag element = convertTag(name); 00103 myCharactersVector.clear(); 00104 SUMOSAXAttributesImpl_Xerces na(attrs, myPredefinedTags, myPredefinedTagsMML); 00105 if (element == SUMO_TAG_INCLUDE) { 00106 std::string file = na.getString(SUMO_ATTR_HREF); 00107 if (!FileHelpers::isAbsolute(file)) { 00108 file = FileHelpers::getConfigurationRelative(getFileName(), file); 00109 } 00110 XMLSubSys::runParser(*this, file); 00111 } else { 00112 myStartElement(element, na); 00113 } 00114 }
| void SUMOSAXHandler::warning | ( | const SAXParseException & | exception | ) | throw () [inherited] |
Handler for XML-warnings.
The message is built using buildErrorMessage and reported to the warning-instance of the MsgHandler.
| [in] | exception | The occured exception to process |
Definition at line 68 of file SUMOSAXHandler.cpp.
References SUMOSAXHandler::buildErrorMessage(), MsgHandler::getWarningInstance(), and MsgHandler::inform().
00068 { 00069 MsgHandler::getWarningInstance()->inform(buildErrorMessage(exception)); 00070 }
1.5.6