1 /*************************************************************************** 2 qgsgpxfeatureiterator.h 3 --------------------- 4 begin : Dezember 2012 5 copyright : (C) 2012 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 #ifndef QGSGPXFEATUREITERATOR_H 16 #define QGSGPXFEATUREITERATOR_H 17 18 #include "qgsfeatureiterator.h" 19 20 #include "gpsdata.h" 21 #include "qgsgpxprovider.h" 22 23 class QgsGPXProvider; 24 25 26 class QgsGPXFeatureSource final: public QgsAbstractFeatureSource 27 { 28 public: 29 explicit QgsGPXFeatureSource( const QgsGPXProvider *p ); 30 ~QgsGPXFeatureSource() override; 31 32 QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override; 33 34 private: 35 QString mFileName; 36 QgsGPXProvider::DataType mFeatureType; 37 QgsGpsData *data = nullptr; 38 QVector<int> indexToAttr; 39 QgsFields mFields; 40 QgsCoordinateReferenceSystem mCrs; 41 42 friend class QgsGPXFeatureIterator; 43 }; 44 45 46 class QgsGPXFeatureIterator final: public QgsAbstractFeatureIteratorFromSource<QgsGPXFeatureSource> 47 { 48 public: 49 QgsGPXFeatureIterator( QgsGPXFeatureSource *source, bool ownSource, const QgsFeatureRequest &request ); 50 51 ~QgsGPXFeatureIterator() override; 52 53 bool rewind() override; 54 bool close() override; 55 56 protected: 57 58 bool fetchFeature( QgsFeature &feature ) override; 59 60 private: 61 62 bool readFid( QgsFeature &feature ); 63 64 bool readWaypoint( const QgsWaypoint &wpt, QgsFeature &feature ); 65 bool readRoute( const QgsRoute &rte, QgsFeature &feature ); 66 bool readTrack( const QgsTrack &trk, QgsFeature &feature ); 67 68 QgsGeometry *readWaypointGeometry( const QgsWaypoint &wpt ); 69 QgsGeometry *readRouteGeometry( const QgsRoute &rte ); 70 QgsGeometry *readTrackGeometry( const QgsTrack &trk ); 71 72 void readAttributes( QgsFeature &feature, const QgsWaypoint &wpt ); 73 void readAttributes( QgsFeature &feature, const QgsRoute &rte ); 74 void readAttributes( QgsFeature &feature, const QgsTrack &trk ); 75 76 //! Current waypoint iterator 77 QgsGpsData::WaypointIterator mWptIter; 78 //! Current route iterator 79 QgsGpsData::RouteIterator mRteIter; 80 //! Current track iterator 81 QgsGpsData::TrackIterator mTrkIter; 82 83 bool mFetchedFid = false; 84 85 QgsCoordinateTransform mTransform; 86 QgsRectangle mFilterRect; 87 }; 88 89 #endif // QGSGPXFEATUREITERATOR_H 90