QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
67  QgsOSMNodeIterator listNodes() const;
68 
70  QgsOSMWayIterator listWays() const;
71 
72  QgsOSMNode node( QgsOSMId id ) const;
73  QgsOSMWay way( QgsOSMId id ) const;
74  //OSMRelation relation( OSMId id ) const;
75 
76  QgsOSMTags tags( bool way, QgsOSMId id ) const;
77 
79  QList<QgsOSMTagCountPair> usedTags( bool ways ) const;
80 
81  QgsPolyline wayPoints( QgsOSMId id ) const;
82 
83  // export to spatialite
84 
85  enum ExportType { Point, Polyline, Polygon };
86  bool exportSpatiaLite( ExportType type, const QString& tableName,
87  const QStringList& tagKeys = QStringList(),
88  const QStringList& noNullTagKeys = QStringList() );
89 
90  protected:
91  bool prepareStatements();
92  int runCountStatement( const char* sql ) const;
93 
97  void deleteStatement( sqlite3_stmt*& stmt );
98 
99  void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
100  void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
101  bool createSpatialTable( const QString& tableName, const QString& geometryType, const QStringList& tagKeys );
102  bool createSpatialIndex( const QString& tableName );
103 
104  QString quotedIdentifier( QString id );
105  QString quotedValue( QString value );
106 
107  private:
109  QString mDbFileName;
110 
111  QString mError;
112 
114  sqlite3* mDatabase;
115 
116  sqlite3_stmt* mStmtNode;
117  sqlite3_stmt* mStmtNodeTags;
118  sqlite3_stmt* mStmtWay;
119  sqlite3_stmt* mStmtWayNode;
120  sqlite3_stmt* mStmtWayNodePoints;
121  sqlite3_stmt* mStmtWayTags;
122 
123  QgsOSMDatabase( const QgsOSMDatabase& rh );
124  QgsOSMDatabase& operator=( const QgsOSMDatabase& rh );
125 };
126 
127 
132 class ANALYSIS_EXPORT QgsOSMNodeIterator
133 {
134  public:
136 
137  QgsOSMNode next();
138  void close();
139 
140  protected:
143  QgsOSMNodeIterator( sqlite3* handle );
144 
145  sqlite3_stmt* mStmt;
146 
147  friend class QgsOSMDatabase;
148 };
149 
150 
151 
156 class ANALYSIS_EXPORT QgsOSMWayIterator
157 {
158  public:
160 
161  QgsOSMWay next();
162  void close();
163 
164  protected:
167  QgsOSMWayIterator( sqlite3* handle );
168 
169  sqlite3_stmt* mStmt;
170 
171  private:
172 
173  friend class QgsOSMDatabase;
174 };
175 
176 
177 
178 #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:93
Encapsulate iteration over table of ways.
QPair< QString, int > QgsOSMTagCountPair
sqlite3_stmt * mStmt
qint64 QgsOSMId
Definition: qgsosmbase.h:24
sqlite3_stmt * mStmt
This class is a container of tags for a node, way or a relation.
Definition: qgsosmbase.h:131
QString filename() const
A node is one of the core elements in the OpenStreetMap data model.
Definition: qgsosmbase.h:70
Class that encapsulates access to OpenStreetMap data stored in a database previously imported from XM...
void setFileName(const QString &dbFileName)
struct sqlite3 sqlite3
QString errorString() const
Encapsulate iteration over table of nodes/.