Skip to content

Commit e809358

Browse files
author
wonder
committed
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
1 parent a8980f8 commit e809358

File tree

6 files changed

+441
-241
lines changed

6 files changed

+441
-241
lines changed

src/providers/osm/osmhandler.h

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,77 @@
2020

2121
#include <sqlite3.h>
2222

23-
#include <iostream>
24-
using namespace std;
2523

2624
/**
27-
* XML SAX handler -> while processing XML file,
28-
* stores data to specified sqlite database
25+
* The SAX handler used for parsing input OSM XML file.
26+
* While processing XML file it stores data to specified sqlite database.
2927
*/
3028
class OsmHandler: public QXmlDefaultHandler
3129
{
3230
public:
33-
// member variables
31+
/**
32+
* Construction.
33+
* @param f input file with OSM data
34+
* @param database opened sqlite3 database with OSM db schema to store data in
35+
*/
36+
OsmHandler( QFile *f, sqlite3 *database );
3437

35-
QFile mFile;
36-
sqlite3 *mDatabase;
37-
int mCnt;
38+
/**
39+
* Destruction.
40+
*/
41+
~OsmHandler();
3842

39-
int mFileSize;
40-
QString mError;
41-
// xml processing information
42-
QString mObjectId; //last node, way or relation id while parsing file
43-
QString mObjectType; //one of strings "node", "way", "relation"
44-
QString mRelationType;
45-
float mLat;
46-
float mLon;
47-
double xMin, xMax, yMin, yMax;
43+
// input OSM XML processing
4844

49-
int mPointCnt;
50-
int mLineCnt;
51-
int mPolygonCnt;
45+
/**
46+
* Function is called after XML processing is started.
47+
* @return True if start of document signal is processed without problems; False otherwise
48+
*/
49+
bool startDocument();
5250

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

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

61-
// object construction
62-
OsmHandler( QFile *f, sqlite3 *database );
63-
~OsmHandler();
64-
// xml processing
77+
/**
78+
* Function is called after end of document is reached while XML processing.
79+
* @return True if end of document signal is processed without problems; False otherwise
80+
*/
81+
bool endDocument();
6582

66-
bool startDocument();
83+
/**
84+
* Returns information on error that occures while parsing.
85+
* @return info on error that occures while parsing
86+
*/
6787
QString errorString();
68-
bool startElement( const QString & pUri, const QString & pLocalName, const QString & pName, const QXmlAttributes & pAttrs );
69-
bool endElement( const QString & pURI, const QString & pLocalName, const QString & pName );
70-
bool endDocument();
88+
89+
public:
90+
int mPointCnt;
91+
int mLineCnt;
92+
int mPolygonCnt;
93+
double xMin, xMax, yMin, yMax;
7194

7295
private:
7396
sqlite3_stmt *mStmtInsertNode;
@@ -78,6 +101,17 @@ class OsmHandler: public QXmlDefaultHandler
78101
sqlite3_stmt *mStmtInsertRelationMember;
79102
sqlite3_stmt *mStmtUpdateNode;
80103
sqlite3_stmt *mStmtInsertVersion;
104+
105+
sqlite3 *mDatabase;
106+
int mPosId;
107+
QString firstWayMemberId;
108+
QString lastWayMemberId;
109+
int mFirstMemberAppeared;
110+
int mCnt;
111+
QString mError;
112+
QString mObjectId; //last node, way or relation id while parsing file
113+
QString mObjectType; //one of "node", "way", "relation"
114+
QString mRelationType;
81115
};
82116

83117

0 commit comments

Comments
 (0)