QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsosmdatabase.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsosmdatabase.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 OSMDATABASE_H
17 #define OSMDATABASE_H
18 
19 #include <QString>
20 #include <QStringList>
21 
22 #include "qgsosmbase.h"
23 
24 #include "qgsgeometry.h"
25 
26 class QgsOSMNodeIterator;
28 
30 
46 class ANALYSIS_EXPORT QgsOSMDatabase
47 {
48  public:
49  explicit QgsOSMDatabase( const QString& dbFileName = QString() );
50  ~QgsOSMDatabase();
51 
52  void setFileName( const QString& dbFileName ) { mDbFileName = dbFileName; }
53  QString filename() const { return mDbFileName; }
54  bool isOpen() const;
55 
56  bool open();
57  bool close();
58 
59  QString errorString() const { return mError; }
60 
61  // data access
62 
63  int countNodes() const;
64  int countWays() const;
65 
66  QgsOSMNodeIterator listNodes() const;
67  QgsOSMWayIterator listWays() const;
68 
69  QgsOSMNode node( QgsOSMId id ) const;
70  QgsOSMWay way( QgsOSMId id ) const;
71  //OSMRelation relation( OSMId id ) const;
72 
73  QgsOSMTags tags( bool way, QgsOSMId id ) const;
74 
75  QList<QgsOSMTagCountPair> usedTags( bool ways ) const;
76 
77  QgsPolyline wayPoints( QgsOSMId id ) const;
78 
79  // export to spatialite
80 
81  enum ExportType { Point, Polyline, Polygon };
82  bool exportSpatiaLite( ExportType type, const QString& tableName,
83  const QStringList& tagKeys = QStringList(),
84  const QStringList& noNullTagKeys = QStringList() );
85 
86  protected:
87  bool prepareStatements();
88  int runCountStatement( const char* sql ) const;
89  void deleteStatement( sqlite3_stmt*& stmt );
90 
91  void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
92  void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
93  bool createSpatialTable( const QString& tableName, const QString& geometryType, const QStringList& tagKeys );
94  bool createSpatialIndex( const QString& tableName );
95 
96  QString quotedIdentifier( QString id );
97  QString quotedValue( QString value );
98 
99  private:
101  QString mDbFileName;
102 
103  QString mError;
104 
106  sqlite3* mDatabase;
107 
108  sqlite3_stmt* mStmtNode;
109  sqlite3_stmt* mStmtNodeTags;
110  sqlite3_stmt* mStmtWay;
111  sqlite3_stmt* mStmtWayNode;
112  sqlite3_stmt* mStmtWayNodePoints;
113  sqlite3_stmt* mStmtWayTags;
114 };
115 
116 
118 class ANALYSIS_EXPORT QgsOSMNodeIterator
119 {
120  public:
122 
123  QgsOSMNode next();
124  void close();
125 
126  protected:
127  QgsOSMNodeIterator( sqlite3* handle );
128 
129  sqlite3_stmt* mStmt;
130 
131  friend class QgsOSMDatabase;
132 };
133 
134 
135 
137 class ANALYSIS_EXPORT QgsOSMWayIterator
138 {
139  public:
141 
142  QgsOSMWay next();
143  void close();
144 
145  protected:
146  QgsOSMWayIterator( sqlite3* handle );
147 
148  sqlite3_stmt* mStmt;
149 
150  friend class QgsOSMDatabase;
151 };
152 
153 
154 
155 #endif // OSMDATABASE_H
A way is an ordered list of nodes which normally also has at least one tag or is included within a Re...
Definition: qgsosmbase.h:82
Encapsulate iteration over table of ways.
QPair< QString, int > QgsOSMTagCountPair
sqlite3_stmt * mStmt
qint64 QgsOSMId
Definition: qgsosmbase.h:10
sqlite3_stmt * mStmt
This class is a container of tags for a node, way or a relation.
Definition: qgsosmbase.h:117
A node is one of the core elements in the OpenStreetMap data model.
Definition: qgsosmbase.h:58
Class that encapsulates access to OpenStreetMap data stored in a database previously imported from XM...
void setFileName(const QString &dbFileName)
struct sqlite3 sqlite3
Encapsulate iteration over table of nodes.
QString errorString() const
QString filename() const