Skip to content

Commit 4512133

Browse files
committed
[FEATURE] new OpenStreetMap data access API and GUI
The idea is to replace the current OSM provider+plugin by this new code. Differences from old code: - read-only access - without editing and upload support - no special provider (using SpatiaLite provider) - underlying OSM topology accessible from API - download using Overpass API: fast, customizable, nearly unlimited download - OSM XML files have to be first imported to a Sqlite3 database, then SpatiaLite layers can be exported
1 parent 94f8f73 commit 4512133

24 files changed

+2821
-1
lines changed

src/analysis/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ SET(QGIS_ANALYSIS_SRCS
3737
vector/qgsgeometryanalyzer.cpp
3838
vector/qgszonalstatistics.cpp
3939
vector/qgsoverlayanalyzer.cpp
40+
openstreetmap/qgsosmbase.cpp
41+
openstreetmap/qgsosmdatabase.cpp
42+
openstreetmap/qgsosmdownload.cpp
43+
openstreetmap/qgsosmimport.cpp
4044
)
4145

4246
INCLUDE_DIRECTORIES(BEFORE raster)
@@ -64,6 +68,8 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
6468
ENDIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
6569

6670
SET(QGIS_ANALYSIS_MOC_HDRS
71+
openstreetmap/qgsosmdownload.h
72+
openstreetmap/qgsosmimport.h
6773
)
6874

6975
QT4_WRAP_CPP(QGIS_ANALYSIS_MOC_SRCS ${QGIS_ANALYSIS_MOC_HDRS})
@@ -85,6 +91,10 @@ SET(QGIS_ANALYSIS_HDRS
8591
interpolation/qgsgridfilewriter.h
8692
interpolation/qgsidwinterpolator.h
8793
interpolation/qgstininterpolator.h
94+
openstreetmap/qgsosmbase.h
95+
openstreetmap/qgsosmdatabase.h
96+
openstreetmap/qgsosmdownload.h
97+
openstreetmap/qgsosmimport.h
8898
)
8999

90100
INCLUDE_DIRECTORIES(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "qgsosmbase.h"
2+
3+
// nothing here now
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#ifndef OSMBASE_H
2+
#define OSMBASE_H
3+
4+
#include <QString>
5+
6+
#include "qgspoint.h"
7+
8+
#include <sqlite3.h>
9+
10+
typedef qint64 QgsOSMId;
11+
12+
class QgsOSMDatabase;
13+
14+
struct QgsOSMElementID
15+
{
16+
enum Type { Invalid, Node, Way, Relation };
17+
18+
Type type;
19+
QgsOSMId id;
20+
};
21+
22+
23+
/**
24+
Elements (also data primitives) are the basic components in OpenStreetMap from which everything else
25+
is defined. These consist of Nodes (which define a point in space), Ways (which define a linear features
26+
and areas), and Relations - with an optional role - which are sometimes used to define the relation
27+
between other elements. All of the above can have one of more associated tags.
28+
*/
29+
class ANALYSIS_EXPORT QgsOSMElement
30+
{
31+
public:
32+
QgsOSMElement() { mElemID.type = QgsOSMElementID::Invalid; mElemID.id = 0; }
33+
QgsOSMElement( QgsOSMElementID::Type t, QgsOSMId id ) { mElemID.type = t; mElemID.id = id; }
34+
35+
bool isValid() const { return mElemID.type != QgsOSMElementID::Invalid; }
36+
37+
QgsOSMDatabase* database() const;
38+
39+
// fetched automatically from DB
40+
QgsOSMElementID elemID() const { return mElemID; }
41+
int id() const { return mElemID.id; }
42+
//QString username() const;
43+
//QDateTime timestamp() const;
44+
//int version() const;
45+
46+
private:
47+
QgsOSMElementID mElemID;
48+
};
49+
50+
51+
52+
/**
53+
A node is one of the core elements in the OpenStreetMap data model. It consists of a single geospatial
54+
point using a latitude and longitude. A third optional dimension, altitude, can be recorded; key:ele
55+
and a node can also be defined at a particular layer=* or level=*. Nodes can be used to define standalone
56+
point features or be used to define the path of a way.
57+
*/
58+
class ANALYSIS_EXPORT QgsOSMNode : public QgsOSMElement
59+
{
60+
public:
61+
QgsOSMNode() : mPoint() {}
62+
QgsOSMNode( QgsOSMId id, const QgsPoint& point ) : QgsOSMElement( QgsOSMElementID::Node, id ), mPoint( point ) {}
63+
64+
QgsPoint point() const { return mPoint; }
65+
66+
// fetched on-demand
67+
QList<QgsOSMElementID> ways() const; // where the node participates?
68+
QList<QgsOSMElementID> relations() const;
69+
70+
private:
71+
QgsPoint mPoint;
72+
};
73+
74+
75+
/**
76+
A way is an ordered list of nodes which normally also has at least one tag or is included within
77+
a Relation. A way can have between 2 and 2,000 nodes, although it's possible that faulty ways with zero
78+
or a single node exist. A way can be open or closed. A closed way is one whose last node on the way
79+
is also the first on that way. A closed way may be interpreted either as a closed polyline, or an area,
80+
or both.
81+
*/
82+
class ANALYSIS_EXPORT QgsOSMWay : public QgsOSMElement
83+
{
84+
public:
85+
QgsOSMWay() {}
86+
QgsOSMWay( QgsOSMId id, const QList<QgsOSMId> nodes ) : QgsOSMElement( QgsOSMElementID::Way, id ), mNodes( nodes ) {}
87+
88+
QList<QgsOSMId> nodes() const { return mNodes; }
89+
90+
// fetched on-demand
91+
//QList<OSMElementID> relations() const;
92+
93+
private:
94+
QList<QgsOSMId> mNodes;
95+
};
96+
97+
98+
#if 0
99+
/**
100+
A relation is one of the core data elements that consists of one or more tags and also an ordered list
101+
of one or more nodes and/or ways as members which is used to define logical or geographic relationships
102+
between other elements. A member of a relation can optionally have a role which describe the part that
103+
a particular feature plays within a relation.
104+
*/
105+
class ANALYSIS_EXPORT QgsOSMRelation : public QgsOSMElement
106+
{
107+
public:
108+
QString relationType() const;
109+
110+
QList< QPair<QgsOSMElementID, QString> > members() const;
111+
};
112+
#endif
113+
114+
115+
class ANALYSIS_EXPORT QgsOSMTags
116+
{
117+
public:
118+
QgsOSMTags() {}
119+
120+
int count() const { return mMap.count(); }
121+
QList<QString> keys() const { return mMap.keys(); }
122+
bool contains( const QString& k ) const { return mMap.contains( k ); }
123+
void insert( const QString& k, const QString& v ) { mMap.insert( k, v ); }
124+
QString value( const QString& k ) const { return mMap.value( k ); }
125+
126+
private:
127+
QMap<QString, QString> mMap;
128+
};
129+
130+
#endif // OSMBASE_H

0 commit comments

Comments
 (0)