Skip to content
Permalink
Browse files
[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
  • Loading branch information
wonder-sk committed Feb 28, 2013
1 parent 94f8f73 commit 4512133f61bb598393c00fadd4e4d12c758357b7
Show file tree
Hide file tree
Showing 24 changed files with 2,821 additions and 1 deletion.
@@ -37,6 +37,10 @@ SET(QGIS_ANALYSIS_SRCS
vector/qgsgeometryanalyzer.cpp
vector/qgszonalstatistics.cpp
vector/qgsoverlayanalyzer.cpp
openstreetmap/qgsosmbase.cpp
openstreetmap/qgsosmdatabase.cpp
openstreetmap/qgsosmdownload.cpp
openstreetmap/qgsosmimport.cpp
)

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

SET(QGIS_ANALYSIS_MOC_HDRS
openstreetmap/qgsosmdownload.h
openstreetmap/qgsosmimport.h
)

QT4_WRAP_CPP(QGIS_ANALYSIS_MOC_SRCS ${QGIS_ANALYSIS_MOC_HDRS})
@@ -85,6 +91,10 @@ SET(QGIS_ANALYSIS_HDRS
interpolation/qgsgridfilewriter.h
interpolation/qgsidwinterpolator.h
interpolation/qgstininterpolator.h
openstreetmap/qgsosmbase.h
openstreetmap/qgsosmdatabase.h
openstreetmap/qgsosmdownload.h
openstreetmap/qgsosmimport.h
)

INCLUDE_DIRECTORIES(
@@ -0,0 +1,3 @@
#include "qgsosmbase.h"

// nothing here now
@@ -0,0 +1,130 @@
#ifndef OSMBASE_H
#define OSMBASE_H

#include <QString>

#include "qgspoint.h"

#include <sqlite3.h>

typedef qint64 QgsOSMId;

class QgsOSMDatabase;

struct QgsOSMElementID
{
enum Type { Invalid, Node, Way, Relation };

Type type;
QgsOSMId id;
};


/**
Elements (also data primitives) are the basic components in OpenStreetMap from which everything else
is defined. These consist of Nodes (which define a point in space), Ways (which define a linear features
and areas), and Relations - with an optional role - which are sometimes used to define the relation
between other elements. All of the above can have one of more associated tags.
*/
class ANALYSIS_EXPORT QgsOSMElement
{
public:
QgsOSMElement() { mElemID.type = QgsOSMElementID::Invalid; mElemID.id = 0; }
QgsOSMElement( QgsOSMElementID::Type t, QgsOSMId id ) { mElemID.type = t; mElemID.id = id; }

bool isValid() const { return mElemID.type != QgsOSMElementID::Invalid; }

QgsOSMDatabase* database() const;

// fetched automatically from DB
QgsOSMElementID elemID() const { return mElemID; }
int id() const { return mElemID.id; }
//QString username() const;
//QDateTime timestamp() const;
//int version() const;

private:
QgsOSMElementID mElemID;
};



/**
A node is one of the core elements in the OpenStreetMap data model. It consists of a single geospatial
point using a latitude and longitude. A third optional dimension, altitude, can be recorded; key:ele
and a node can also be defined at a particular layer=* or level=*. Nodes can be used to define standalone
point features or be used to define the path of a way.
*/
class ANALYSIS_EXPORT QgsOSMNode : public QgsOSMElement
{
public:
QgsOSMNode() : mPoint() {}
QgsOSMNode( QgsOSMId id, const QgsPoint& point ) : QgsOSMElement( QgsOSMElementID::Node, id ), mPoint( point ) {}

QgsPoint point() const { return mPoint; }

// fetched on-demand
QList<QgsOSMElementID> ways() const; // where the node participates?
QList<QgsOSMElementID> relations() const;

private:
QgsPoint mPoint;
};


/**
A way is an ordered list of nodes which normally also has at least one tag or is included within
a Relation. A way can have between 2 and 2,000 nodes, although it's possible that faulty ways with zero
or a single node exist. A way can be open or closed. A closed way is one whose last node on the way
is also the first on that way. A closed way may be interpreted either as a closed polyline, or an area,
or both.
*/
class ANALYSIS_EXPORT QgsOSMWay : public QgsOSMElement
{
public:
QgsOSMWay() {}
QgsOSMWay( QgsOSMId id, const QList<QgsOSMId> nodes ) : QgsOSMElement( QgsOSMElementID::Way, id ), mNodes( nodes ) {}

QList<QgsOSMId> nodes() const { return mNodes; }

// fetched on-demand
//QList<OSMElementID> relations() const;

private:
QList<QgsOSMId> mNodes;
};


#if 0
/**
A relation is one of the core data elements that consists of one or more tags and also an ordered list
of one or more nodes and/or ways as members which is used to define logical or geographic relationships
between other elements. A member of a relation can optionally have a role which describe the part that
a particular feature plays within a relation.
*/
class ANALYSIS_EXPORT QgsOSMRelation : public QgsOSMElement
{
public:
QString relationType() const;

QList< QPair<QgsOSMElementID, QString> > members() const;
};
#endif


class ANALYSIS_EXPORT QgsOSMTags
{
public:
QgsOSMTags() {}

int count() const { return mMap.count(); }
QList<QString> keys() const { return mMap.keys(); }
bool contains( const QString& k ) const { return mMap.contains( k ); }
void insert( const QString& k, const QString& v ) { mMap.insert( k, v ); }
QString value( const QString& k ) const { return mMap.value( k ); }

private:
QMap<QString, QString> mMap;
};

#endif // OSMBASE_H

0 comments on commit 4512133

Please sign in to comment.