Skip to content
Permalink
Browse files

Update of OSM provider from Lukas Berka:

code documentation, refactoring, cleaning


git-svn-id: http://svn.osgeo.org/qgis/trunk@11376 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Aug 14, 2009
1 parent a8980f8 commit e8093581fe54913dda178105189ab66765aeff72
@@ -20,54 +20,77 @@

#include <sqlite3.h>

#include <iostream>
using namespace std;

/**
* XML SAX handler -> while processing XML file,
* stores data to specified sqlite database
* The SAX handler used for parsing input OSM XML file.
* While processing XML file it stores data to specified sqlite database.
*/
class OsmHandler: public QXmlDefaultHandler
{
public:
// member variables
/**
* Construction.
* @param f input file with OSM data
* @param database opened sqlite3 database with OSM db schema to store data in
*/
OsmHandler( QFile *f, sqlite3 *database );

QFile mFile;
sqlite3 *mDatabase;
int mCnt;
/**
* Destruction.
*/
~OsmHandler();

int mFileSize;
QString mError;
// xml processing information
QString mObjectId; //last node, way or relation id while parsing file
QString mObjectType; //one of strings "node", "way", "relation"
QString mRelationType;
float mLat;
float mLon;
double xMin, xMax, yMin, yMax;
// input OSM XML processing

int mPointCnt;
int mLineCnt;
int mPolygonCnt;
/**
* Function is called after XML processing is started.
* @return True if start of document signal is processed without problems; False otherwise
*/
bool startDocument();

int mCurrent_way_id;
int mPosId;
QString firstWayMemberId;
QString lastWayMemberId;
int mFirstMemberAppeared;
/**
* The reader of OSM file calls this function when it has parsed a start element tag.
* If this function returns false the reader stops parsing and reports an error.
* The reader uses the function errorString() to get the error message.
*
* @param pUri namespace URI of element, or an empty string if the element has no namespace URI or if no namespace processing is done
* @param pLocalName local name of element (without prefix), or an empty string if no namespace processing is done
* @param pName qualified name of element (with prefix)
* @param pAttrs attributes attached to the element; if there are no attributes, atts is an empty attributes object.
* @return True if start of element signal is processed without problems; False otherwise
*/
bool startElement( const QString & pUri, const QString & pLocalName, const QString & pName, const QXmlAttributes & pAttrs );

//functions
/**
* The reader calls this function when it has parsed an end element tag with the qualified name pName,
* the local name pLocalName and the namespace URI pURI.
* If this function returns false the reader stops parsing and reports an error.
* The reader uses the function errorString() to get the error message.
*
* @param pUri namespace URI of element, or an empty string if the element has no namespace URI or if no namespace processing is done
* @param pLocalName local name of element (without prefix), or an empty string if no namespace processing is done
* @param pName qualified name of element (with prefix)
* @return True if end of element signal is processed without problems; False otherwise
*/
bool endElement( const QString & pURI, const QString & pLocalName, const QString & pName );

// object construction
OsmHandler( QFile *f, sqlite3 *database );
~OsmHandler();
// xml processing
/**
* Function is called after end of document is reached while XML processing.
* @return True if end of document signal is processed without problems; False otherwise
*/
bool endDocument();

bool startDocument();
/**
* Returns information on error that occures while parsing.
* @return info on error that occures while parsing
*/
QString errorString();
bool startElement( const QString & pUri, const QString & pLocalName, const QString & pName, const QXmlAttributes & pAttrs );
bool endElement( const QString & pURI, const QString & pLocalName, const QString & pName );
bool endDocument();

public:
int mPointCnt;
int mLineCnt;
int mPolygonCnt;
double xMin, xMax, yMin, yMax;

private:
sqlite3_stmt *mStmtInsertNode;
@@ -78,6 +101,17 @@ class OsmHandler: public QXmlDefaultHandler
sqlite3_stmt *mStmtInsertRelationMember;
sqlite3_stmt *mStmtUpdateNode;
sqlite3_stmt *mStmtInsertVersion;

sqlite3 *mDatabase;
int mPosId;
QString firstWayMemberId;
QString lastWayMemberId;
int mFirstMemberAppeared;
int mCnt;
QString mError;
QString mObjectId; //last node, way or relation id while parsing file
QString mObjectType; //one of "node", "way", "relation"
QString mRelationType;
};


0 comments on commit e809358

Please sign in to comment.
You can’t perform that action at this time.