|
| 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