~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/providers/gpx/qgsgpxprovider.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *                                                                         *
18
18
 ***************************************************************************/
19
19
 
20
 
#include <map>
21
20
 
22
21
#include "qgsvectordataprovider.h"
23
22
#include "gpsdata.h"
27
26
class QgsField;
28
27
class QFile;
29
28
class QDomDocument;
30
 
class GPSData;
 
29
class QgsGPSData;
31
30
 
32
31
 
33
32
/**
34
33
\class QgsGPXProvider
35
34
\brief Data provider for GPX (GPS eXchange) files
36
35
* This provider adds the ability to load GPX files as vector layers.
37
 
 
36
*
38
37
*/
39
 
class QgsGPXProvider : public QgsVectorDataProvider {
40
 
public:
41
 
  QgsGPXProvider(QString const & uri = "");
42
 
  virtual ~QgsGPXProvider();
43
 
  
44
 
  /**
45
 
    *   Returns the permanent storage type for this layer as a friendly name.
46
 
    */
47
 
  QString storageType();
48
 
 
49
 
  /** Used to ask the layer for its projection as a WKT string. Implements 
50
 
      virtual method of same name in QgsDataProvider. */
51
 
  QString getProjectionWKT();
52
 
  /**
53
 
   * Get the first feature resulting from a select operation
54
 
   * @return QgsFeature
55
 
   */
56
 
  QgsFeature * getFirstFeature(bool fetchAttributes=false);
57
 
  /** 
58
 
  * Get the next feature resutling from a select operation
59
 
  * @return QgsFeature
60
 
  */
61
 
  QgsFeature * getNextFeature(bool fetchAttributes=false);
62
 
  bool getNextFeature(QgsFeature &feature, bool fetchAttributes=false);
63
 
  QgsFeature * getNextFeature(std::list<int> const & attlist, int featureQueueSize = 1);
64
 
  
65
 
  /** Get the feature type. This corresponds to 
66
 
      WKBPoint,
67
 
      WKBLineString,
68
 
      WKBPolygon,
69
 
      WKBMultiPoint,
70
 
      WKBMultiLineString or
71
 
      WKBMultiPolygon
72
 
  * as defined in qgis.h
73
 
  * This provider will always return WKBPoint
74
 
  */
75
 
  int geometryType() const;
76
 
  /** 
77
 
   * Get the number of features in the layer
78
 
   */
79
 
  long featureCount() const;
80
 
  /** 
81
 
   * Get the number of fields in the layer
82
 
   */
83
 
  int fieldCount() const;
84
 
  /**
85
 
   * Select features based on a bounding rectangle. Features can be retrieved 
86
 
   * with calls to getFirstFeature and getNextFeature.
87
 
   * @param mbr QgsRect containing the extent to use in selecting features
88
 
   */
89
 
  void select(QgsRect *mbr, bool useIntersect=false);
90
 
  /** 
91
 
   * Set the data source specification. This may be a path or database
92
 
   * connection string
93
 
   * @uri data source specification
94
 
   */
95
 
  void setDataSourceUri(QString uri);
96
 
  
97
 
  /** 
98
 
   * Get the data source specification. This may be a path or database
99
 
   * connection string
100
 
   * @return data source specification
101
 
   */
102
 
  QString getDataSourceUri();
103
 
  
104
 
  /**
105
 
   * Identify features within the search radius specified by rect
106
 
   * @param rect Bounding rectangle of search radius
107
 
   * @return std::vector containing QgsFeature objects that intersect rect
108
 
   */
109
 
  virtual std::vector<QgsFeature>& identify(QgsRect *rect);
110
 
  
111
 
  /** Return the extent for this data layer
112
 
   */
113
 
  virtual QgsRect * extent();
114
 
  
115
 
  /**
116
 
   * Get the field information for the layer
117
 
   */
118
 
  std::vector<QgsField> const & fields() const;
119
 
  
120
 
  /* Reset the layer (ie move the file pointer to the head
121
 
     of the file.
122
 
  */
123
 
  void reset();
124
 
    
125
 
  /**Returns the minimum value of an attribute
126
 
     @param position the number of the attribute*/
127
 
  QString minValue(int position);
128
 
  
129
 
  /**Returns the maximum value of an attribute
130
 
     @param position the number of the attribute*/
131
 
  QString maxValue(int position);
132
 
  
133
 
  /**Returns true if this is a valid delimited file
134
 
   */
135
 
  bool isValid();
136
 
 
137
 
  /**Adds a list of features
138
 
     @return true in case of success and false in case of failure*/
139
 
  bool addFeatures(std::list<QgsFeature*> flist);
140
 
  
141
 
  bool deleteFeatures(std::list<int> const & id);
142
 
  
143
 
  bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & 
144
 
                             attr_map);
145
 
  
146
 
  void changeAttributeValues(GPSObject& obj, 
147
 
                             const std::map<QString, QString>& attrs);
148
 
  
149
 
  /** Adds one feature (used by addFeatures()) */
150
 
  bool addFeature(QgsFeature* f);
151
 
  
152
 
  /**Returns the default value for attribute @c attr for feature @c f. */
153
 
  QString getDefaultValue(const QString& attr, QgsFeature* f);
154
 
  
155
 
  /**
156
 
   * Check to see if the point is withn the selection
157
 
   * rectangle
158
 
   * @param x X value of point
159
 
   * @param y Y value of point
160
 
   * @return True if point is within the rectangle
161
 
   */
162
 
  bool boundsCheck(double x, double y);
163
 
 
164
 
  int capabilities() const {
165
 
    return AddFeatures | DeleteFeatures | ChangeAttributeValues;
166
 
  }
167
 
  
168
 
  QgsDataSourceURI *getURI()
169
 
  {
170
 
      return 0;
171
 
  }
172
 
 
173
 
  /** return the number of layers for the current data source
174
 
 
175
 
  @note 
176
 
 
177
 
  Should this be subLayerCount() instead?
178
 
  */
179
 
  size_t layerCount() const;
180
 
 
181
 
 
182
 
    /** return a provider name
183
 
 
184
 
    Essentially just returns the provider key.  Should be used to build file
185
 
    dialogs so that providers can be shown with their supported types. Thus
186
 
    if more than one provider supports a given format, the user is able to
187
 
    select a specific provider to open that file.
188
 
 
189
 
    @note
190
 
 
191
 
    Instead of being pure virtual, might be better to generalize this
192
 
    behavior and presume that none of the sub-classes are going to do
193
 
    anything strange with regards to their name or description?
194
 
 
195
 
    */
196
 
    QString name() const;
197
 
 
198
 
 
199
 
    /** return description
200
 
 
201
 
    Return a terse string describing what the provider is.
202
 
 
203
 
    @note
204
 
 
205
 
    Instead of being pure virtual, might be better to generalize this
206
 
    behavior and presume that none of the sub-classes are going to do
207
 
    anything strange with regards to their name or description?
208
 
 
209
 
    */
210
 
    QString description() const;
211
 
 
212
 
  
213
 
private:
214
 
  
215
 
  /** Internal function used by the other getNextFeature() functions. */
216
 
  bool getNextFeature(QgsFeature* feature, std::list<int> const & attlist);
217
 
 
218
 
  bool mEditable;
219
 
  GPSData* data;
220
 
  void fillMinMaxCash();
221
 
  //! Fields
222
 
  std::vector<QgsField> attributeFields;
223
 
  std::list<int> mAllAttributes;
224
 
  //! Map to store field position by name
225
 
  std::map<QString, int> fieldPositions;
226
 
 
227
 
  QString mFileName;
228
 
 
229
 
  enum { WaypointType, RouteType, TrackType } mFeatureType;
230
 
  enum Attribute { NameAttr = 0, EleAttr, SymAttr, NumAttr, 
231
 
                   CmtAttr, DscAttr, SrcAttr, URLAttr, URLNameAttr };
232
 
  static const char* attr[];
233
 
  //! Current selection rectangle
234
 
  QgsRect *mSelectionRectangle;
235
 
  bool mValid;
236
 
  int mGeomType;
237
 
  long mNumberFeatures;
238
 
  
239
 
  //! Current waypoint iterator
240
 
  GPSData::WaypointIterator mWptIter;
241
 
  //! Current route iterator
242
 
  GPSData::RouteIterator mRteIter;
243
 
  //! Current track iterator
244
 
  GPSData::TrackIterator mTrkIter;
245
 
 
246
 
  /**Flag indicating, if the minmaxcache should be renewed (true) or not (false)*/
247
 
  bool mMinMaxCacheDirty;
248
 
  /**Matrix storing the minimum and maximum values*/
249
 
  double** mMinMaxCache;
250
 
  /**Fills the cash and sets minmaxcachedirty to false*/
251
 
  void mFillMinMaxCash();
252
 
  struct wkbPoint{
253
 
    char byteOrder;
254
 
    unsigned wkbType;
255
 
    double x;
256
 
    double y;
257
 
  };
258
 
  wkbPoint mWKBpt;
259
 
  
 
38
class QgsGPXProvider : public QgsVectorDataProvider
 
39
{
 
40
    Q_OBJECT
 
41
 
 
42
  public:
 
43
 
 
44
    QgsGPXProvider( QString uri = QString() );
 
45
    virtual ~QgsGPXProvider();
 
46
 
 
47
    /* Functions inherited from QgsVectorDataProvider */
 
48
 
 
49
    /**
 
50
     *   Returns the permanent storage type for this layer as a friendly name.
 
51
     */
 
52
    virtual QString storageType() const;
 
53
 
 
54
    /** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
 
55
     * @param fetchAttributes list of attributes which should be fetched
 
56
     * @param rect spatial filter
 
57
     * @param fetchGeometry true if the feature geometry should be fetched
 
58
     * @param useIntersect true if an accurate intersection test should be used,
 
59
     *                     false if a test based on bounding box is sufficient
 
60
     */
 
61
    virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(),
 
62
                         QgsRectangle rect = QgsRectangle(),
 
63
                         bool fetchGeometry = true,
 
64
                         bool useIntersect = false );
 
65
 
 
66
    /**
 
67
     * Get the next feature resulting from a select operation.
 
68
     * @param feature feature which will receive data from the provider
 
69
     * @return true when there was a feature to fetch, false when end was hit
 
70
     */
 
71
    virtual bool nextFeature( QgsFeature& feature );
 
72
 
 
73
    /**
 
74
     * Get feature type.
 
75
     * @return int representing the feature type
 
76
     */
 
77
    virtual QGis::WkbType geometryType() const;
 
78
 
 
79
    /**
 
80
     * Number of features in the layer
 
81
     * @return long containing number of features
 
82
     */
 
83
    virtual long featureCount() const;
 
84
 
 
85
    /**
 
86
     * Get the number of fields in the layer
 
87
     */
 
88
    virtual uint fieldCount() const;
 
89
 
 
90
    /**
 
91
     * Get the field information for the layer
 
92
     */
 
93
    virtual const QgsFieldMap & fields() const;
 
94
 
 
95
    /** Restart reading features from previous select operation */
 
96
    virtual void rewind();
 
97
 
 
98
    /**
 
99
     * Adds a list of features
 
100
     * @return true in case of success and false in case of failure
 
101
     */
 
102
    virtual bool addFeatures( QgsFeatureList & flist );
 
103
 
 
104
    /**
 
105
     * Deletes a feature
 
106
     * @param id list containing feature ids to delete
 
107
     * @return true in case of success and false in case of failure
 
108
     */
 
109
    virtual bool deleteFeatures( const QgsFeatureIds & id );
 
110
 
 
111
    /**
 
112
     * Changes attribute values of existing features.
 
113
     * @param attr_map a map containing changed attributes
 
114
     * @return true in case of success and false in case of failure
 
115
     */
 
116
    virtual bool changeAttributeValues( const QgsChangedAttributesMap & attr_map );
 
117
 
 
118
    virtual int capabilities() const;
 
119
 
 
120
    /**
 
121
     * Returns the default value for field specified by @c fieldId
 
122
     */
 
123
    virtual QVariant defaultValue( int fieldId );
 
124
 
 
125
 
 
126
    /* Functions inherited from QgsDataProvider */
 
127
 
 
128
    /** Return the extent for this data layer
 
129
     */
 
130
    virtual QgsRectangle extent();
 
131
 
 
132
    /**Returns true if this is a valid delimited file
 
133
     */
 
134
    virtual bool isValid();
 
135
 
 
136
    /** return a provider name */
 
137
    virtual QString name() const;
 
138
 
 
139
    /** return description */
 
140
    virtual QString description() const;
 
141
 
 
142
    virtual QgsCoordinateReferenceSystem crs();
 
143
 
 
144
 
 
145
    /* new functions */
 
146
 
 
147
    void changeAttributeValues( QgsGPSObject& obj,
 
148
                                const QgsAttributeMap& attrs );
 
149
 
 
150
    /** Adds one feature (used by addFeatures()) */
 
151
    bool addFeature( QgsFeature& f );
 
152
 
 
153
    /**
 
154
     * Check to see if the point is withn the selection
 
155
     * rectangle
 
156
     * @param x X value of point
 
157
     * @param y Y value of point
 
158
     * @return True if point is within the rectangle
 
159
     */
 
160
    bool boundsCheck( double x, double y );
 
161
 
 
162
 
 
163
  private:
 
164
 
 
165
    QgsGPSData* data;
 
166
 
 
167
    //! Fields
 
168
    QgsFieldMap attributeFields;
 
169
 
 
170
    QString mFileName;
 
171
 
 
172
    enum { WaypointType, RouteType, TrackType } mFeatureType;
 
173
    enum Attribute { NameAttr = 0, EleAttr, SymAttr, NumAttr,
 
174
                     CmtAttr, DscAttr, SrcAttr, URLAttr, URLNameAttr
 
175
                 };
 
176
    static const char* attr[];
 
177
    //! Current selection rectangle
 
178
    QgsRectangle *mSelectionRectangle;
 
179
    bool mValid;
 
180
    long mNumberFeatures;
 
181
 
 
182
    //! Current waypoint iterator
 
183
    QgsGPSData::WaypointIterator mWptIter;
 
184
    //! Current route iterator
 
185
    QgsGPSData::RouteIterator mRteIter;
 
186
    //! Current track iterator
 
187
    QgsGPSData::TrackIterator mTrkIter;
 
188
 
 
189
    struct wkbPoint
 
190
    {
 
191
      char byteOrder;
 
192
      unsigned wkbType;
 
193
      double x;
 
194
      double y;
 
195
    };
 
196
    wkbPoint mWKBpt;
 
197
 
260
198
};