SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NIImporter_SUMO Class Reference

Importer for networks stored in SUMO format. More...

#include <NIImporter_SUMO.h>

Inheritance diagram for NIImporter_SUMO:
SUMOSAXHandler GenericSAXHandler

Data Structures

struct  Connection
 A connection description. More...
 
struct  EdgeAttrs
 Describes the values found in an edge's definition and this edge's lanes. More...
 
struct  LaneAttrs
 Describes the values found in a lane's definition. More...
 
struct  Prohibition
 Describes the values found in a prohibition. More...
 

Public Member Functions

void characters (const XMLCh *const chars, const XERCES3_SIZE_t length)
 The inherited method called when characters occured. More...
 
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 The inherited method called when a tag is being closed. More...
 
const std::string & getFileName () const
 returns the current file name More...
 
void registerParent (const int tag, GenericSAXHandler *handler)
 Assigning a parent handler which is enabled when the specified tag is closed. More...
 
void setFileName (const std::string &name)
 Sets the current file name. More...
 
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const XERCES_CPP_NAMESPACE::Attributes &attrs)
 The inherited method called when a new tag opens. More...
 
SAX ErrorHandler callbacks
void warning (const XERCES_CPP_NAMESPACE::SAXParseException &exception)
 Handler for XML-warnings. More...
 
void error (const XERCES_CPP_NAMESPACE::SAXParseException &exception)
 Handler for XML-errors. More...
 
void fatalError (const XERCES_CPP_NAMESPACE::SAXParseException &exception)
 Handler for XML-errors. More...
 

Static Public Member Functions

static void addPhase (const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
 adds a phase to the traffic lights logic currently build More...
 
static NBLoadedSUMOTLDefinitTrafficLightLogic (const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
 begins the reading of a traffic lights logic More...
 
static GeoConvHelperloadLocation (const SUMOSAXAttributes &attrs)
 Parses network location description and registers it with GeoConveHelper::setLoaded. More...
 
static void loadNetwork (OptionsCont &oc, NBNetBuilder &nb)
 Loads content of the optionally given SUMO file. More...
 

Protected Member Functions

std::string buildErrorMessage (const XERCES_CPP_NAMESPACE::SAXParseException &exception)
 Builds an error message. More...
 
virtual void myCharacters (int element, const std::string &chars)
 Callback method for characters to implement by derived classes. More...
 
 NIImporter_SUMO (NBNetBuilder &nb)
 Constructor. More...
 
 ~NIImporter_SUMO ()
 Destructor. More...
 
inherited from GenericSAXHandler
void myStartElement (int element, const SUMOSAXAttributes &attrs)
 Called on the opening of a tag;. More...
 
void myEndElement (int element)
 Called when a closing tag occurs. More...
 

Private Member Functions

void _loadNetwork (OptionsCont &oc)
 load the network More...
 
LaneAttrsgetLaneAttrsFromID (EdgeAttrs *edge, std::string lane_id)
 Parses lane index from lane ID an retrieve lane from EdgeAttrs. More...
 
void parseProhibitionConnection (const std::string &attr, std::string &from, std::string &to, bool &ok)
 parses connection string of a prohibition (very old school) More...
 
Object instance parsing methods
void addEdge (const SUMOSAXAttributes &attrs)
 Parses an edge and stores the values in "myCurrentEdge". More...
 
void addLane (const SUMOSAXAttributes &attrs)
 Parses a lane and stores the values in "myCurrentLane". More...
 
void addJunction (const SUMOSAXAttributes &attrs)
 Parses a junction and saves it in the node control. More...
 
void addConnection (const SUMOSAXAttributes &attrs)
 Parses a connection and saves it into the lane's definition stored in "myCurrentLane". More...
 
void addProhibition (const SUMOSAXAttributes &attrs)
 Parses a prohibition and saves it. More...
 

Static Private Member Functions

static void interpretLaneID (const std::string &lane_id, std::string &edge_id, unsigned int &index)
 parses edge-id and index from lane-id More...
 
static Position readPosition (const SUMOSAXAttributes &attrs, const std::string &id, bool &ok)
 read position from the given attributes, attribute errors to id More...
 
static PositionVector reconstructEdgeShape (const EdgeAttrs *edge, const Position &from, const Position &to)
 reconstructs the edge shape from the node positions and the given lane shapes since we do not know the original LaneSpreadFunction this is only an approximation More...
 

Private Attributes

EdgeAttrsmyCurrentEdge
 The currently parsed edge's definition (to add loaded lanes to) More...
 
LaneAttrsmyCurrentLane
 The currently parsed lanes's definition (to add the shape to) More...
 
NBLoadedSUMOTLDefmyCurrentTL
 The currently parsed traffic light. More...
 
std::map< std::string,
EdgeAttrs * > 
myEdges
 Loaded edge definitions. More...
 
bool myHaveSeenInternalEdge
 whether the loaded network contains internal lanes More...
 
GeoConvHelpermyLocation
 The coordinate transformation which was used to build the loaded network. More...
 
NBNetBuildermyNetBuilder
 The network builder to fill. More...
 
NBNodeContmyNodeCont
 The node container to fill. More...
 
std::vector< ProhibitionmyProhibitions
 Loaded prohibitions. More...
 
bool mySuspectKeepShape
 whether we suspect a net that was built with xml.keep-shape More...
 
NBTrafficLightLogicContmyTLLCont
 The node container to fill. More...
 

Detailed Description

Importer for networks stored in SUMO format.

Definition at line 58 of file NIImporter_SUMO.h.

Constructor & Destructor Documentation

NIImporter_SUMO::NIImporter_SUMO ( NBNetBuilder nb)
protected

Constructor.

Parameters
[in]ncThe network builder to fill

Definition at line 76 of file NIImporter_SUMO.cpp.

NIImporter_SUMO::~NIImporter_SUMO ( )
protected

Destructor.

Definition at line 90 of file NIImporter_SUMO.cpp.

References NIImporter_SUMO::EdgeAttrs::lanes, myEdges, and myLocation.

Member Function Documentation

void NIImporter_SUMO::_loadNetwork ( OptionsCont oc)
private

load the network

Definition at line 103 of file NIImporter_SUMO.cpp.

References NBLoadedSUMOTLDef::addConnection(), NBEdge::addLane2LaneConnection(), NBNode::addSortedLinkFoes(), NIImporter_SUMO::LaneAttrs::allow, NIImporter_SUMO::EdgeAttrs::builtEdge, NIImporter_SUMO::LaneAttrs::connections, NBEdge::declareConnectionsAsLoaded(), NIImporter_SUMO::LaneAttrs::disallow, EDGEFUNC_INTERNAL, FileHelpers::exists(), NIImporter_SUMO::EdgeAttrs::fromNode, NIImporter_SUMO::EdgeAttrs::func, NBNetBuilder::getEdgeCont(), Named::getID(), NBEdge::getLaneID(), NBEdge::getLanes(), NBEdge::getLaneWidth(), NBEdge::getOffset(), NBNode::getPosition(), NBTrafficLightLogicCont::getPrograms(), OptionsCont::getStringVector(), NBEdge::getToNode(), NBEdge::hasConnectionTo(), NBEdge::hasLaneSpecificOffset(), NBEdge::hasLaneSpecificWidth(), NIImporter_SUMO::EdgeAttrs::id, NBEdgeCont::insert(), OptionsCont::isDefault(), OptionsCont::isUsableFileList(), NBEdge::L2L_VALIDATED, NIImporter_SUMO::EdgeAttrs::lanes, NIImporter_SUMO::EdgeAttrs::length, NIImporter_SUMO::EdgeAttrs::lsf, NIImporter_SUMO::LaneAttrs::maxSpeed, NIImporter_SUMO::EdgeAttrs::maxSpeed, NIImporter_SUMO::Connection::mayDefinitelyPass, myEdges, myHaveSeenInternalEdge, myNetBuilder, myNodeCont, myProhibitions, mySuspectKeepShape, myTLLCont, NIImporter_SUMO::LaneAttrs::offset, parseVehicleClasses(), NIImporter_SUMO::EdgeAttrs::priority, PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, reconstructEdgeShape(), NBEdgeCont::retrieve(), NBNodeCont::retrieve(), XMLSubSys::runParser(), OptionsCont::set(), GenericSAXHandler::setFileName(), NBEdge::setLaneWidth(), NBEdge::setLoadedLength(), NBEdge::setOffset(), NBEdge::setPermissions(), NBEdge::setSpeed(), NIImporter_SUMO::EdgeAttrs::shape, NIImporter_SUMO::EdgeAttrs::streetName, NIImporter_SUMO::Connection::tlID, NIImporter_SUMO::Connection::tlLinkNo, NIImporter_SUMO::Connection::toEdgeID, NIImporter_SUMO::Connection::toLaneIdx, NIImporter_SUMO::EdgeAttrs::toNode, NIImporter_SUMO::EdgeAttrs::type, NBEdge::UNSPECIFIED_OFFSET, NBEdge::UNSPECIFIED_WIDTH, NIImporter_SUMO::LaneAttrs::width, WRITE_ERROR, and WRITE_WARNING.

Referenced by loadNetwork().

void NIImporter_SUMO::addPhase ( const SUMOSAXAttributes attrs,
NBLoadedSUMOTLDef currentTL 
)
static
void NIImporter_SUMO::addProhibition ( const SUMOSAXAttributes attrs)
private
std::string GenericSAXHandler::buildErrorMessage ( const XERCES_CPP_NAMESPACE::SAXParseException &  exception)
protectedinherited

Builds an error message.

The error message includes the file name and the line/column information as supported by the given SAXParseException

Parameters
[in]exceptionThe name of the currently processed file
Returns
A string describing the given exception

Definition at line 193 of file GenericSAXHandler.cpp.

References GenericSAXHandler::getFileName().

Referenced by GenericSAXHandler::error(), GenericSAXHandler::fatalError(), and GenericSAXHandler::warning().

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.

Todo:

recheck/describe what happens with characters when a new element is opened

describe characters processing in the class' head

Definition at line 176 of file GenericSAXHandler.cpp.

References TplConvert::_2str(), and GenericSAXHandler::myCharactersVector.

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.

Todo:

recheck/describe encoding of the string-representation

do not generate and report the string-representation

Definition at line 126 of file GenericSAXHandler.cpp.

References TplConvert::_2str(), GenericSAXHandler::convertTag(), GenericSAXHandler::myCharacters(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myEndElement(), GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.

void GenericSAXHandler::error ( const XERCES_CPP_NAMESPACE::SAXParseException &  exception)
inherited

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Parameters
[in]exceptionThe occured exception to process
Exceptions
ProcessErrorOn any call

Definition at line 212 of file GenericSAXHandler.cpp.

References GenericSAXHandler::buildErrorMessage().

void GenericSAXHandler::fatalError ( const XERCES_CPP_NAMESPACE::SAXParseException &  exception)
inherited

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Exceptions
ProcessErrorOn any call
Parameters
[in]exceptionThe occured exception to process

Definition at line 218 of file GenericSAXHandler.cpp.

References GenericSAXHandler::buildErrorMessage().

NIImporter_SUMO::LaneAttrs * NIImporter_SUMO::getLaneAttrsFromID ( EdgeAttrs edge,
std::string  lane_id 
)
private

Parses lane index from lane ID an retrieve lane from EdgeAttrs.

Parameters
[in]edgeThe EdgeAttrs* which should contain the lane
[in]lane_idThe ID of the lane

Definition at line 501 of file NIImporter_SUMO.cpp.

References NIImporter_SUMO::EdgeAttrs::id, interpretLaneID(), NIImporter_SUMO::EdgeAttrs::lanes, and WRITE_ERROR.

NBLoadedSUMOTLDef * NIImporter_SUMO::initTrafficLightLogic ( const SUMOSAXAttributes attrs,
NBLoadedSUMOTLDef currentTL 
)
static
void NIImporter_SUMO::interpretLaneID ( const std::string &  lane_id,
std::string &  edge_id,
unsigned int index 
)
staticprivate

parses edge-id and index from lane-id

Parameters
[in]lane_idThe lane-id
[out]edge_idID of this lane's edge
[out]indexIndex of this lane

Definition at line 516 of file NIImporter_SUMO.cpp.

References TplConvert::_2int(), and WRITE_ERROR.

Referenced by getLaneAttrsFromID().

GeoConvHelper * NIImporter_SUMO::loadLocation ( const SUMOSAXAttributes attrs)
static

Parses network location description and registers it with GeoConveHelper::setLoaded.

Definition at line 625 of file NIImporter_SUMO.cpp.

References SUMOSAXAttributes::get(), GeoConvHelper::setLoaded(), SUMO_ATTR_CONV_BOUNDARY, SUMO_ATTR_NET_OFFSET, SUMO_ATTR_ORIG_BOUNDARY, and SUMO_ATTR_ORIG_PROJ.

Referenced by NIXMLNodesHandler::myStartElement(), and myStartElement().

void NIImporter_SUMO::loadNetwork ( OptionsCont oc,
NBNetBuilder nb 
)
static

Loads content of the optionally given SUMO file.

If the option "sumo-net-file" is set, the file stored therein is read and the network definition stored therein is stored within the given network builder.

If the option "sumo-net-file" is not set, this method simply returns.

The loading is done by parsing the network definition as an XML file using the SAXinterface and handling the incoming data via this class' methods.

Parameters
[in,out]ocThe options to use (option no-internal-links may be modified)
[in]nbThe network builder to fill

Definition at line 67 of file NIImporter_SUMO.cpp.

References _loadNetwork().

Referenced by NILoader::load().

void GenericSAXHandler::myCharacters ( int  element,
const std::string &  chars 
)
protectedvirtualinherited

Callback method for characters to implement by derived classes.

Called by "endElement" (see there).

Parameters
[in]elementThe opened element, given as a int
[in]charsThe complete embedded character string ProcessError These method may throw a ProcessError if something fails

Reimplemented in NIImporter_ITSUMO::Handler.

Definition at line 228 of file GenericSAXHandler.cpp.

Referenced by GenericSAXHandler::endElement().

void NIImporter_SUMO::myEndElement ( int  element)
protectedvirtual
void NIImporter_SUMO::myStartElement ( int  element,
const SUMOSAXAttributes attrs 
)
protectedvirtual

Called on the opening of a tag;.

In dependence to the obtained type, an appropriate parsing method is called ("addEdge" if an edge encounters, f.e.).

Parameters
[in]elementID of the currently opened element
[in]attrsAttributes within the currently opened element
Exceptions
ProcessErrorIf something fails
See Also
GenericSAXHandler::myStartElement

Reimplemented from GenericSAXHandler.

Definition at line 248 of file NIImporter_SUMO.cpp.

References addConnection(), addEdge(), addJunction(), addLane(), addPhase(), addProhibition(), NBNetBuilder::haveSeenRoundabouts(), initTrafficLightLogic(), loadLocation(), myCurrentTL, myLocation, myNetBuilder, SUMO_TAG_CONNECTION, SUMO_TAG_EDGE, SUMO_TAG_JUNCTION, SUMO_TAG_LANE, SUMO_TAG_LOCATION, SUMO_TAG_PHASE, SUMO_TAG_PROHIBITION, SUMO_TAG_ROUNDABOUT, and SUMO_TAG_TLLOGIC.

void NIImporter_SUMO::parseProhibitionConnection ( const std::string &  attr,
std::string &  from,
std::string &  to,
bool ok 
)
private

parses connection string of a prohibition (very old school)

Parameters
[in]attrThe connection attribute
[out]fromID of the source edge
[out]toID of the destination edge
[out]okWhether parsing completed successfully

Definition at line 655 of file NIImporter_SUMO.cpp.

References myEdges, and WRITE_ERROR.

Referenced by addProhibition().

Position NIImporter_SUMO::readPosition ( const SUMOSAXAttributes attrs,
const std::string &  id,
bool ok 
)
staticprivate

read position from the given attributes, attribute errors to id

Definition at line 643 of file NIImporter_SUMO.cpp.

References SUMOSAXAttributes::get(), SUMOSAXAttributes::hasAttribute(), SUMO_ATTR_X, SUMO_ATTR_Y, SUMO_ATTR_Z, and SUMOReal.

Referenced by addJunction().

PositionVector NIImporter_SUMO::reconstructEdgeShape ( const EdgeAttrs edge,
const Position from,
const Position to 
)
staticprivate

reconstructs the edge shape from the node positions and the given lane shapes since we do not know the original LaneSpreadFunction this is only an approximation

Parameters
[in]lanesThe list of lane attributes

= -2.; //

Todo:
: actually, when looking at the road networks, the center line is not in the center

Definition at line 583 of file NIImporter_SUMO.cpp.

References Line::extrapolateBy(), NIImporter_SUMO::EdgeAttrs::id, Line::intersects(), Line::intersectsAt(), NBEdge::laneOffset(), NIImporter_SUMO::EdgeAttrs::lanes, LANESPREAD_RIGHT, NIImporter_SUMO::EdgeAttrs::lsf, PositionVector::push_back(), SUMO_const_laneOffset, SUMO_const_laneWidth, SUMOReal, WRITE_WARNING, Position::x(), and Position::y().

Referenced by _loadNetwork().

void GenericSAXHandler::registerParent ( const int  tag,
GenericSAXHandler handler 
)
inherited
void GenericSAXHandler::setFileName ( const std::string &  name)
inherited

Sets the current file name.

Parameters
[in]nameThe name of the currently processed file
Todo:
Hmmm - this is as unsafe as having a direct access to the variable; recheck

Definition at line 80 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myFileName.

Referenced by _loadNetwork(), GUISettingsHandler::GUISettingsHandler(), PCNetProjectionLoader::load(), NIImporter_OpenStreetMap::load(), loadNet(), ROLoader::loadNet(), NIImporter_ITSUMO::loadNetwork(), NIImporter_MATSim::loadNetwork(), NIImporter_OpenDrive::loadNetwork(), and XMLSubSys::runParser().

void GenericSAXHandler::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const XERCES_CPP_NAMESPACE::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.

Todo:

recheck/describe encoding of the string-representation

do not generate and report the string-representation

Definition at line 105 of file GenericSAXHandler.cpp.

References TplConvert::_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.

void GenericSAXHandler::warning ( const XERCES_CPP_NAMESPACE::SAXParseException &  exception)
inherited

Handler for XML-warnings.

The message is built using buildErrorMessage and reported to the warning-instance of the MsgHandler.

Parameters
[in]exceptionThe occured exception to process

Definition at line 206 of file GenericSAXHandler.cpp.

References GenericSAXHandler::buildErrorMessage(), and WRITE_WARNING.

Field Documentation

EdgeAttrs* NIImporter_SUMO::myCurrentEdge
private

The currently parsed edge's definition (to add loaded lanes to)

Definition at line 265 of file NIImporter_SUMO.h.

Referenced by addEdge(), addLane(), and myEndElement().

LaneAttrs* NIImporter_SUMO::myCurrentLane
private

The currently parsed lanes's definition (to add the shape to)

Definition at line 268 of file NIImporter_SUMO.h.

Referenced by addLane(), and myEndElement().

NBLoadedSUMOTLDef* NIImporter_SUMO::myCurrentTL
private

The currently parsed traffic light.

Definition at line 271 of file NIImporter_SUMO.h.

Referenced by myEndElement(), and myStartElement().

std::map<std::string, EdgeAttrs*> NIImporter_SUMO::myEdges
private

Loaded edge definitions.

Definition at line 250 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), addConnection(), myEndElement(), parseProhibitionConnection(), and ~NIImporter_SUMO().

bool NIImporter_SUMO::myHaveSeenInternalEdge
private

whether the loaded network contains internal lanes

Definition at line 280 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addLane().

GeoConvHelper* NIImporter_SUMO::myLocation
private

The coordinate transformation which was used to build the loaded network.

Definition at line 274 of file NIImporter_SUMO.h.

Referenced by addEdge(), addJunction(), addLane(), myStartElement(), and ~NIImporter_SUMO().

NBNetBuilder& NIImporter_SUMO::myNetBuilder
private

The network builder to fill.

Definition at line 256 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and myStartElement().

NBNodeCont& NIImporter_SUMO::myNodeCont
private

The node container to fill.

Definition at line 259 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addJunction().

std::vector<Prohibition> NIImporter_SUMO::myProhibitions
private

Loaded prohibitions.

Definition at line 253 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addProhibition().

bool NIImporter_SUMO::mySuspectKeepShape
private

whether we suspect a net that was built with xml.keep-shape

Definition at line 277 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addJunction().

NBTrafficLightLogicCont& NIImporter_SUMO::myTLLCont
private

The node container to fill.

Definition at line 262 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and myEndElement().


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