alaCarte Maps
Renderer for OpenStreetMap tiles
Importer::OsmXmlParser Class Reference

Parser for osm-xml-data. More...

Inheritance diagram for Importer::OsmXmlParser:

Public Types

typedef uint64_t OsmIdType
 Type, where osm ids stored in. More...
 

Public Member Functions

 OsmXmlParser (bool ignoreUnknownEntities, const FloatRect &bounds={-nl::max(),-nl::max(), nl::max(), nl::max()})
 Creates a new parser and sets default settings. More...
 
void parse (const path &xml_file)
 Will parse a given xml file. More...
 
shared_ptr< std::vector< Node > > getParsedNodes () const
 Returns a vector with parsed nodes. More...
 
shared_ptr< std::vector< Way > > getParsedWays () const
 Returns a vector with parsed ways. More...
 
shared_ptr< std::vector< Relation > > getParsedRelations () const
 Returns a vector with parsed relations. More...
 
std::size_t getNumberOfClippedNodes () const
 Returns the number of clipped nodes. More...
 

Static Public Attributes

static const int parser_flags
 flags for parsing the xml file More...
 

Private Member Functions

void parseEntities (eaglexml::xml_node<> *osmRoot)
 parses the osm-root element and creates given objects More...
 
void parseBounds (eaglexml::xml_node<> *node)
 parses the bound entity More...
 
void parseNode (eaglexml::xml_node<> *node)
 parses a node entity More...
 
void parseWay (eaglexml::xml_node<> *way)
 parses the way entity More...
 
void parseRelation (eaglexml::xml_node<> *relation)
 parses the relation entity More...
 
template<typename Target >
void parseProperties (eaglexml::xml_node<> *firstProp, DataMap< CachedString, CachedString > *tagMap, std::vector< NodeId > *nodeRefIds, DataMap< NodeId, CachedString > *nodeRoleMap, std::vector< WayId > *wayRefIds, DataMap< WayId, CachedString > *wayRoleMap)
 parses properties of an osm-object More...
 
template<typename T >
void extractAttributeFromNode (const string &attrname, eaglexml::xml_node<> *node, T *dest)
 Extracts the value of a specified xml-attribute from a given node. More...
 
template<typename IdType >
IdType resolveOsmId (OsmIdType osmId, const boost::unordered_map< OsmIdType, IdType > &table)
 Resolves a osm id into an internal id. More...
 
virtual void on_fetch (unsigned int chars_left, unsigned int need, node_type *active_node)
 
virtual void on_buffer_resize ()
 
virtual void on_segment_read ()
 
virtual void on_read_begin (unsigned int segments)
 

Private Attributes

bool ignoreUnknownEntities
 Specifies weather the parser should ignore unknown entities. More...
 
const FloatRect clippingBounds
 Specifies the rectangular area in which the nodes are kept. More...
 
boost::unordered_map< OsmIdType, NodeIdnodeIdMapping
 Mapping from osm ids to internal ids for nodes. More...
 
boost::unordered_map< OsmIdType, WayIdwayIdMapping
 Mapping from osm ids to internal ids for ways. More...
 
std::unordered_set< OsmIdTypeclippedNodes
 Id of clipped nodes. More...
 
shared_ptr< std::vector< Node > > nodes
 List to be filled with nodes. More...
 
shared_ptr< std::vector< Way > > ways
 List to be filled with ways. More...
 
shared_ptr< std::vector< Relation > > relations
 List to be filled with relations. More...
 
std::uintmax_t fileSize
 Size of the xml file in bytes. More...
 
std::uintmax_t alreadyRead
 Bytes already read from the xml file. More...
 
unsigned int segmentSize
 Number of bytes read by one read operation. More...
 
bool outputIgnoreRelation
 Booleans for some output, which should only appear once. More...
 
bool outputIgnoreBounds
 

Detailed Description

Parser for osm-xml-data.

This parser will parse xml files and extract nodes ways and relations

Definition at line 52 of file importer.cpp.

Member Typedef Documentation

Type, where osm ids stored in.

Definition at line 64 of file importer.cpp.

Constructor & Destructor Documentation

Importer::OsmXmlParser::OsmXmlParser ( bool  ignoreUnknownEntities,
const FloatRect bounds = { -nl::max(), -nl::max(), nl::max(), nl::max() } 
)
inline

Creates a new parser and sets default settings.

Definition at line 71 of file importer.cpp.

Member Function Documentation

template<typename T >
void Importer::OsmXmlParser::extractAttributeFromNode ( const string attrname,
eaglexml::xml_node<> *  node,
T *  dest 
)
inlineprivate

Extracts the value of a specified xml-attribute from a given node.

Returns it in a wanted type. Throws if the attribute is missing or has a bad format.

Parameters
attrnamethe name of the attribute
nodethe node containing the attribute
destdestination to copy the extracted value

Definition at line 426 of file importer.cpp.

std::size_t Importer::OsmXmlParser::getNumberOfClippedNodes ( ) const
inline

Returns the number of clipped nodes.

Returns
number of clipped nodes

Definition at line 181 of file importer.cpp.

shared_ptr< std::vector<Node> > Importer::OsmXmlParser::getParsedNodes ( ) const
inline

Returns a vector with parsed nodes.

Returns
parsed nodes

Definition at line 148 of file importer.cpp.

shared_ptr< std::vector<Relation> > Importer::OsmXmlParser::getParsedRelations ( ) const
inline

Returns a vector with parsed relations.

Returns
parsed relations

Definition at line 170 of file importer.cpp.

shared_ptr< std::vector<Way> > Importer::OsmXmlParser::getParsedWays ( ) const
inline

Returns a vector with parsed ways.

Returns
parsed ways

Definition at line 159 of file importer.cpp.

virtual void Importer::OsmXmlParser::on_buffer_resize ( )
inlineprivatevirtual

Definition at line 469 of file importer.cpp.

virtual void Importer::OsmXmlParser::on_fetch ( unsigned int  chars_left,
unsigned int  need,
node_type *  active_node 
)
inlineprivatevirtual

Definition at line 468 of file importer.cpp.

virtual void Importer::OsmXmlParser::on_read_begin ( unsigned int  segments)
inlineprivatevirtual

Definition at line 472 of file importer.cpp.

virtual void Importer::OsmXmlParser::on_segment_read ( )
inlineprivatevirtual

Definition at line 470 of file importer.cpp.

void Importer::OsmXmlParser::parse ( const path &  xml_file)
inline

Will parse a given xml file.

This method will try to open the given file. osm data is expected to be found. nodes, ways and relations will be extracted and saved. They can be accessed through getParsedNodes, getParsedWays, getParsedRelations. Additionally a mapping from osm id to an internal id will be created for nodes and ways.

Parameters
xml_fileA path to a file containing the osm data.
Exceptions
FileNotFoundException

Definition at line 93 of file importer.cpp.

void Importer::OsmXmlParser::parseBounds ( eaglexml::xml_node<> *  node)
inlineprivate

parses the bound entity

Parameters
nodexml-node for the entity

Definition at line 229 of file importer.cpp.

void Importer::OsmXmlParser::parseEntities ( eaglexml::xml_node<> *  osmRoot)
inlineprivate

parses the osm-root element and creates given objects

Parameters
osm_rootosm-xml root node

Definition at line 192 of file importer.cpp.

void Importer::OsmXmlParser::parseNode ( eaglexml::xml_node<> *  node)
inlineprivate

parses a node entity

Parameters
nodexml-node for the entity

Definition at line 243 of file importer.cpp.

template<typename Target >
void Importer::OsmXmlParser::parseProperties ( eaglexml::xml_node<> *  firstProp,
DataMap< CachedString, CachedString > *  tagMap,
std::vector< NodeId > *  nodeRefIds,
DataMap< NodeId, CachedString > *  nodeRoleMap,
std::vector< WayId > *  wayRefIds,
DataMap< WayId, CachedString > *  wayRoleMap 
)
inlineprivate

parses properties of an osm-object

Starts with the first and goes through all property xml-nodes. Depending on the Target, specified, the nodes will be examined and data will be extracted.

Template Parameters
TargetThe geoobject-type for which the properties should be examined. Must be one of the following: Node, Way, Relation
Parameters
firstPropfirst xml-property-node
tagMapmap, where tags are saved
nodeRefIdslist, where references to nodes are saved
nodeRoleMapmap, where roles of nodes are saved
wayRefIdslist, where references to ways are saved
wayRoleMapmap, where roles of ways are saved

Targets to be set

Definition at line 334 of file importer.cpp.

void Importer::OsmXmlParser::parseRelation ( eaglexml::xml_node<> *  relation)
inlineprivate

parses the relation entity

Parameters
nodexml-node for the entity

Definition at line 295 of file importer.cpp.

void Importer::OsmXmlParser::parseWay ( eaglexml::xml_node<> *  way)
inlineprivate

parses the way entity

Parameters
nodexml-node for the entity

Definition at line 270 of file importer.cpp.

template<typename IdType >
IdType Importer::OsmXmlParser::resolveOsmId ( OsmIdType  osmId,
const boost::unordered_map< OsmIdType, IdType > &  table 
)
inlineprivate

Resolves a osm id into an internal id.

Can only take care of objects already parsed.

Parameters
osmIdto be resolved
tablecontaining the id mapping
Returns
the resolved internal id
Exceptions
ifthe id can not be resolved.

Definition at line 457 of file importer.cpp.

Member Data Documentation

std::uintmax_t Importer::OsmXmlParser::alreadyRead
private

Bytes already read from the xml file.

Definition at line 516 of file importer.cpp.

std::unordered_set<OsmIdType> Importer::OsmXmlParser::clippedNodes
private

Id of clipped nodes.

Definition at line 501 of file importer.cpp.

const FloatRect Importer::OsmXmlParser::clippingBounds
private

Specifies the rectangular area in which the nodes are kept.

If a node lies outside of this area it is not added to the data!

Definition at line 492 of file importer.cpp.

std::uintmax_t Importer::OsmXmlParser::fileSize
private

Size of the xml file in bytes.

Definition at line 513 of file importer.cpp.

bool Importer::OsmXmlParser::ignoreUnknownEntities
private

Specifies weather the parser should ignore unknown entities.

If this is false and an unknown entity appears an exception will be thrown

Definition at line 488 of file importer.cpp.

boost::unordered_map<OsmIdType, NodeId> Importer::OsmXmlParser::nodeIdMapping
private

Mapping from osm ids to internal ids for nodes.

Definition at line 495 of file importer.cpp.

shared_ptr< std::vector<Node> > Importer::OsmXmlParser::nodes
private

List to be filled with nodes.

Definition at line 504 of file importer.cpp.

bool Importer::OsmXmlParser::outputIgnoreBounds
private

Definition at line 522 of file importer.cpp.

bool Importer::OsmXmlParser::outputIgnoreRelation
private

Booleans for some output, which should only appear once.

Definition at line 522 of file importer.cpp.

const int Importer::OsmXmlParser::parser_flags
static
Initial value:
= eaglexml::parse_no_data_nodes
| eaglexml::parse_normalize_whitespace
| eaglexml::parse_trim_whitespace
| eaglexml::parse_validate_closing_tags
| eaglexml::parse_default

flags for parsing the xml file

Definition at line 57 of file importer.cpp.

shared_ptr< std::vector<Relation> > Importer::OsmXmlParser::relations
private

List to be filled with relations.

Definition at line 510 of file importer.cpp.

unsigned int Importer::OsmXmlParser::segmentSize
private

Number of bytes read by one read operation.

Definition at line 519 of file importer.cpp.

boost::unordered_map<OsmIdType, WayId> Importer::OsmXmlParser::wayIdMapping
private

Mapping from osm ids to internal ids for ways.

Definition at line 498 of file importer.cpp.

shared_ptr< std::vector<Way> > Importer::OsmXmlParser::ways
private

List to be filled with ways.

Definition at line 507 of file importer.cpp.


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