23#include "moc_qgsvectorlayergpslogger.cpp"
68 if ( field.isEmpty() )
69 mDestinationFields.remove( component );
71 mDestinationFields[ component ] = field;
76 return mDestinationFields.value( component );
96 if ( track.isEmpty() )
106 geometry.
transform( mWgs84toTrackLayerTransform );
110 QgsDebugError( QStringLiteral(
"Error transforming GPS track" ) );
124 for (
auto it = mDestinationFields.constBegin(); it != mDestinationFields.constEnd(); ++it )
126 if ( it.value().isEmpty() )
153 const int fieldIdx = mTracksLayer->fields().lookupField( it.value() );
157 if ( value.toDateTime().isValid() )
159 attributes.insert( fieldIdx, timestamp( mTracksLayer, fieldIdx, value.toDateTime() ) );
169 const int fieldIdx = mTracksLayer->fields().lookupField( it.value() );
175 attributes.insert( fieldIdx, value );
187 if ( mUseEditBuffer )
197 if ( mPointsLayer && info.
isValid() )
203 if ( geometry.constGet()->is3D() && !
QgsWkbTypes::hasZ( mPointsLayer->wkbType() ) )
205 geometry.get()->dropZValue();
207 if ( geometry.constGet()->isMeasure() && !
QgsWkbTypes::hasM( mPointsLayer->wkbType() ) )
209 geometry.get()->dropMValue();
214 geometry.transform( mWgs84toPointLayerTransform );
216 catch ( QgsCsException & )
218 QgsDebugError( QStringLiteral(
"Error transforming GPS point" ) );
223 for (
auto it = mDestinationFields.constBegin(); it != mDestinationFields.constEnd(); ++it )
225 if ( it.value().isEmpty() )
247 const int fieldIdx = mPointsLayer->fields().lookupField( it.value() );
253 attributes.insert( fieldIdx, value );
262 const int fieldIdx = mPointsLayer->fields().lookupField( it.value() );
266 if ( value.toDateTime().isValid() )
268 attributes.insert( fieldIdx, timestamp( mPointsLayer, fieldIdx, value.toDateTime() ) );
282 QgsExpressionContext context = mPointsLayer->createExpressionContext();
286 if ( mUseEditBuffer )
293QVariant QgsVectorLayerGpsLogger::timestamp(
QgsVectorLayer *vlayer,
int idx,
const QDateTime &time )
296 if ( idx != -1 && time.isValid() )
301 case QMetaType::Type::QString:
302 value = time.toString( Qt::DateFormat::ISODate );
304 case QMetaType::Type::QDateTime:
GpsInformationComponent
GPS information component.
@ TrackStartTime
Timestamp at start of current track (available from QgsGpsLogger class only).
@ GroundSpeed
Ground speed.
@ TrackTimeSinceLastPoint
Time since last recorded location (available from QgsGpsLogger class only).
@ Pdop
Dilution of precision.
@ TrackEndTime
Timestamp at end (current point) of current track (available from QgsGpsLogger class only).
@ Altitude
Altitude/elevation above or below the mean sea level.
@ TrackDistanceFromStart
Direct distance from first vertex in current GPS track to last vertex (available from QgsGpsLogger cl...
@ TotalTrackLength
Total distance of current GPS track (available from QgsGpsLogger class only).
@ Hdop
Horizontal dilution of precision.
@ EllipsoidAltitude
Altitude/elevation above or below the WGS-84 Earth ellipsoid.
@ Bearing
Bearing measured in degrees clockwise from true north to the direction of travel.
@ Vdop
Vertical dilution of precision.
@ GeoidalSeparation
Geoidal separation, the difference between the WGS-84 Earth ellipsoid and mean-sea-level (geoid),...
@ VerticalAccuracy
Vertical accuracy in meters.
@ Location
2D location (latitude/longitude), as a QgsPointXY value
@ TrackDistanceSinceLastPoint
Distance since last recorded location (available from QgsGpsLogger class only).
@ HorizontalAccuracy
Horizontal accuracy in meters.
@ SatellitesUsed
Count of satellites used in obtaining the fix.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Abstract base class for connections to a GPS device.
virtual void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context to be used when transforming GPS coordinates.
void stateChanged(const QgsGpsInformation &info)
Emitted whenever the associated GPS device state is changed.
double lastElevation() const
Returns the last recorded elevation the device.
QgsGpsLogger(QgsGpsConnection *connection, QObject *parent=nullptr)
Constructor for QgsGpsLogger with the specified parent object.
QgsCoordinateReferenceSystem mWgs84CRS
WGS84 coordinate reference system.
QVector< QgsPoint > currentTrack() const
Returns the recorded points in the current track.
void resetTrack()
Resets the current track, discarding all recorded points.
double lastMValue() const
Returns the last recorded value corresponding to the QgsGpsLogger::settingsGpsMValueComponent setting...
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context to be used when transforming GPS coordinates.
QgsGpsConnection * connection()
Returns the associated GPS connection.
QVariant componentValue(Qgis::GpsInformationComponent component) const
Returns the value of the corresponding GPS information component.
QgsPointXY lastPosition() const
Returns the last recorded position of the device.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
~QgsVectorLayerGpsLogger() override
QgsVectorLayer * pointsLayer()
Returns the layer in which recorded GPS points will be stored.
void setDestinationField(Qgis::GpsInformationComponent component, const QString &field)
Sets a destination field name for a specific GPS information component.
QgsVectorLayerGpsLogger(QgsGpsConnection *connection, QObject *parent=nullptr)
Constructor for QgsVectorLayerGpsLogger with the specified parent object.
void setPointsLayer(QgsVectorLayer *layer)
Sets the layer in which recorded GPS points should be stored.
void setTracksLayer(QgsVectorLayer *layer)
Sets the layer in which recorded GPS tracks should be stored.
void setTransformContext(const QgsCoordinateTransformContext &context) override
Sets the coordinate transform context to be used when transforming GPS coordinates.
QString destinationField(Qgis::GpsInformationComponent component) const
Returns the destination field name for a specific GPS information component.
QgsVectorLayer * tracksLayer()
Returns the layer in which recorded GPS tracks will be stored.
void endCurrentTrack()
Ends the current track, storing it in the tracksLayer() if appropriate.
static QgsFeature createFeature(const QgsVectorLayer *layer, const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap(), QgsExpressionContext *context=nullptr)
Creates a new feature ready for insertion into a layer.
Represents a vector layer which manages a vector based dataset.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
QMap< int, QVariant > QgsAttributeMap
#define QgsDebugError(str)