QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsosmimport.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsosmimport.h
3  --------------------------------------
4  Date : January 2013
5  Copyright : (C) 2013 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef OSMIMPORT_H
17 #define OSMIMPORT_H
18 
19 #include <QFile>
20 #include <QObject>
21 
22 #include "qgsosmbase.h"
23 
24 class QXmlStreamReader;
25 
35 class ANALYSIS_EXPORT QgsOSMXmlImport : public QObject
36 {
37  Q_OBJECT
38  public:
39  explicit QgsOSMXmlImport( const QString& xmlFileName = QString(), const QString& dbFileName = QString() );
40 
41  void setInputXmlFileName( const QString& xmlFileName ) { mXmlFileName = xmlFileName; }
42  QString inputXmlFileName() const { return mXmlFileName; }
43 
44  void setOutputDbFileName( const QString& dbFileName ) { mDbFileName = dbFileName; }
45  QString outputDbFileName() const { return mDbFileName; }
46 
51  bool import();
52 
53  bool hasError() const { return !mError.isEmpty(); }
54  QString errorString() const { return mError; }
55 
56  signals:
57  void progress( int percent );
58 
59  protected:
60 
61  bool createDatabase();
62  bool closeDatabase();
63  void deleteStatement( sqlite3_stmt*& stmt );
64 
65  bool createIndexes();
66 
67  void readRoot( QXmlStreamReader& xml );
68  void readNode( QXmlStreamReader& xml );
69  void readWay( QXmlStreamReader& xml );
70  void readTag( bool way, QgsOSMId id, QXmlStreamReader& xml );
71 
72  private:
73  QString mXmlFileName;
74  QString mDbFileName;
75 
76  QString mError;
77 
78  QFile mInputFile;
79 
80  sqlite3* mDatabase;
81  sqlite3_stmt* mStmtInsertNode;
82  sqlite3_stmt* mStmtInsertNodeTag;
83  sqlite3_stmt* mStmtInsertWay;
84  sqlite3_stmt* mStmtInsertWayNode;
85  sqlite3_stmt* mStmtInsertWayTag;
86 };
87 
88 
89 
90 #endif // OSMIMPORT_H