17#include "moc_qgsgpslogger.cpp" 
   46  setConnection( connection );
 
   48  mLastNmeaPosition.lat = nmea_degree2radian( 0.0 );
 
   49  mLastNmeaPosition.lon = nmea_degree2radian( 0.0 );
 
   51  mAcquisitionTimer = std::unique_ptr<QTimer>( 
new QTimer( 
this ) );
 
   52  mAcquisitionTimer->setSingleShot( 
true );
 
   56  connect( mAcquisitionTimer.get(), &QTimer::timeout,
 
   57           this, &QgsGpsLogger::switchAcquisition );
 
 
   93  mTransformContext = context;
 
 
  100  return mTransformContext;
 
 
  105  return mDistanceCalculator;
 
 
  110  return mCaptureListWgs84;
 
 
  116  const QVector< QgsPoint > captureListWgs84 = 
currentTrack();
 
  119    error = tr( 
"Creating a line feature requires a track with at least two vertices." );
 
  124    error = tr( 
"Creating a polygon feature requires a track with at least three vertices." );
 
  130  switch ( geometryType )
 
  156      auto ringWgs84 = std::make_unique<QgsLineString>( captureListWgs84 );
 
  158        ringWgs84->dropZValue();
 
  160        ringWgs84->dropMValue();
 
  171        auto polygon = std::make_unique<QgsPolygon>();
 
  172        polygon->setExteriorRing( ringWgs84.release() );
 
 
  191  return mLastGpsPositionWgs84;
 
 
  196  return mLastElevation;
 
 
  208  const bool trackWasEmpty = mCaptureListWgs84.isEmpty();
 
  209  mCaptureListWgs84.clear();
 
  211  mTrackStartTime = QDateTime();
 
  213  if ( !trackWasEmpty )
 
 
  221  int acquisitionInterval = 0;
 
  245        mTimeStampSpec = Qt::TimeSpec::LocalTime;
 
  249        mTimeStampSpec = Qt::TimeSpec::UTC;
 
  253        mTimeStampSpec = Qt::TimeSpec::TimeZone;
 
  259  mAcquisitionInterval = acquisitionInterval * 1000;
 
  260  if ( mAcquisitionTimer->isActive() )
 
  261    mAcquisitionTimer->stop();
 
  262  mAcquisitionEnabled = 
true;
 
 
  269  QVector<QgsPointXY> points;
 
  278    QgsDebugError( QStringLiteral( 
"An error occurred while calculating length" ) );
 
 
  285  if ( mCaptureListWgs84.empty() )
 
  295    QgsDebugError( QStringLiteral( 
"An error occurred while calculating length" ) );
 
 
  320      return mConnection->currentGPSInformation().componentValue( component );
 
  342        QgsDebugError( QStringLiteral( 
"An error occurred while calculating length" ) );
 
  347      return mPreviousTrackPointTime.isValid() ? 
static_cast< double >( mPreviousTrackPointTime.msecsTo( 
lastTimestamp() ) ) / 1000 : QVariant();
 
 
  352void QgsGpsLogger::switchAcquisition()
 
  354  if ( mAcquisitionInterval > 0 )
 
  356    if ( mAcquisitionEnabled )
 
  357      mAcquisitionTimer->start( mAcquisitionInterval );
 
  360      mAcquisitionTimer->start( mAcquisitionInterval / 10 );
 
  362    mAcquisitionEnabled = !mAcquisitionEnabled;
 
  371  const bool validFlag = info.
isValid();
 
  373  nmeaPOS newNmeaPosition;
 
  378    newNmeaPosition.lat = nmea_degree2radian( info.
latitude );
 
  379    newNmeaPosition.lon = nmea_degree2radian( info.
longitude );
 
  387    switch ( mMValueComponent )
 
  403        mLastMValue = value.isValid() ? info.
componentValue( mMValueComponent ).toDouble() : std::numeric_limits< double >::quiet_NaN();
 
  408        mLastMValue = 
static_cast< double >( info.
utcDateTime.toMSecsSinceEpoch() );
 
  424    newLocationWgs84 = mLastGpsPositionWgs84;
 
  425    newNmeaPosition = mLastNmeaPosition;
 
  426    newAlt = mLastElevation;
 
  428  if ( !mAcquisitionEnabled || ( nmea_distance( &newNmeaPosition, &mLastNmeaPosition ) < mDistanceThreshold ) )
 
  431    newLocationWgs84 = mLastGpsPositionWgs84;
 
  434  if ( validFlag && mAcquisitionEnabled )
 
  441  if ( mLastGpsPositionWgs84 != newLocationWgs84 )
 
  443    mLastGpsPositionWgs84 = newLocationWgs84;
 
  444    mLastNmeaPosition = newNmeaPosition;
 
  445    mLastElevation = newAlt;
 
  447    if ( mAutomaticallyAddTrackVertices )
 
  456  mPreviousTrackPoint = mLastGpsPositionWgs84;
 
  461  QgsPoint pointWgs84 = 
QgsPoint( mLastGpsPositionWgs84.
x(), mLastGpsPositionWgs84.
y(), mLastElevation );
 
  463  if ( mStoreAttributeInMValues )
 
  468  const bool trackWasEmpty = mCaptureListWgs84.empty();
 
  469  mCaptureListWgs84.push_back( pointWgs84 );
 
 
  482  return mAutomaticallyAddTrackVertices;
 
 
  487  mAutomaticallyAddTrackVertices = enabled;
 
 
  492  if ( !mLastTime.isValid() )
 
  495  QDateTime time = mLastTime;
 
  498  time.setTimeSpec( Qt::UTC );
 
  500  if ( mApplyLeapSettings && mLeapSeconds != 0 )
 
  502    time = time.addSecs( mLeapSeconds );
 
  505  if ( mTimeStampSpec != Qt::TimeSpec::OffsetFromUTC )
 
  506    time = time.toTimeSpec( mTimeStampSpec );
 
  508  if ( mTimeStampSpec == Qt::TimeSpec::TimeZone )
 
  511    const QTimeZone destTz( mTimeZone.toUtf8() );
 
  512    if ( destTz.isValid() )
 
  514      time = time.toTimeZone( destTz );
 
  517  else if ( mTimeStampSpec == Qt::TimeSpec::LocalTime )
 
  519    time = time.toLocalTime();
 
  521  else if ( mTimeStampSpec == Qt::TimeSpec::OffsetFromUTC )
 
  523    time = time.toOffsetFromUtc( mOffsetFromUtc );
 
  525  else if ( mTimeStampSpec == Qt::TimeSpec::UTC )
 
 
  535  return mTrackStartTime;
 
 
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.
 
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
 
WkbType
The WKB type describes the number of dimensions a geometry has.
 
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
 
Represents a coordinate reference system (CRS).
 
Contains information about the context in which a coordinate transform is executed.
 
Custom exception class for Coordinate Reference System related exceptions.
 
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
 
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
 
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
 
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
 
A geometry is the spatial representation of a feature.
 
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
 
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
 
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
 
static void convertPointList(const QVector< QgsPointXY > &input, QgsPointSequence &output)
Upgrades a point list from QgsPointXY to QgsPoint.
 
Abstract base class for connections to a GPS device.
 
static const QgsSettingsEntryEnumFlag< Qt::TimeSpec > * settingsGpsTimeStampSpecification
Settings entry time specification for GPS time stamps.
 
static const QgsSettingsEntryString * settingsGpsTimeStampTimeZone
Settings entry GPS time stamp time zone.
 
static const QgsSettingsEntryBool * settingGpsApplyLeapSecondsCorrection
Settings entry GPS apply leap seconds correction.
 
static const QgsSettingsEntryInteger * settingGpsLeapSeconds
Settings entry GPS leap seconds correction amount (in seconds)
 
static const QgsSettingsEntryInteger * settingsGpsTimeStampOffsetFromUtc
Settings entry GPS time offset from UTC in seconds.
 
static const QgsSettingsEntryInteger * settingGpsAcquisitionInterval
Settings entry GPS track point acquisition interval.
 
static const QgsSettingsEntryDouble * settingGpsDistanceThreshold
Settings entry GPS track point distance threshold.
 
void stateChanged(const QgsGpsInformation &info)
Emitted whenever the GPS state is changed.
 
Base class for objects which log incoming GPS data.
 
static const QgsSettingsEntryBool * settingsGpsStoreAttributeInMValues
Settings entry for whether storing GPS attributes as geometry M values should be enabled.
 
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.
 
static const QgsSettingsEntryEnumFlag< Qgis::GpsInformationComponent > * settingsGpsMValueComponent
Settings entry dictating which GPS attribute should be stored in geometry M values.
 
double lastElevation() const
Returns the last recorded elevation the device.
 
static const QgsSettingsEntryInteger * settingsTimeStampFormat
 
QgsCoordinateReferenceSystem mWgs84CRS
WGS84 coordinate reference system.
 
static const QgsSettingsEntryInteger * settingsLeapSecondsCorrection
 
int mBlockGpsStateChanged
Used to pause logging of incoming GPS messages.
 
static const QgsSettingsEntryBool * settingsApplyLeapSeconds
 
QgsGeometry currentGeometry(Qgis::WkbType type, QString &error) const
Returns the current logged GPS positions as a geometry of the specified type.
 
const QgsDistanceArea & distanceArea() const
Returns the distance area calculator which should be used for calculating distances associated with t...
 
QVector< QgsPoint > currentTrack() const
Returns the recorded points in the current track.
 
bool automaticallyAddTrackVertices() const
Returns true if track vertices will be automatically added whenever the GPS position is changed.
 
void trackIsEmptyChanged(bool isEmpty)
Emitted whenever the current track changes from being empty to non-empty or vice versa.
 
QDateTime trackStartTime() const
Returns the timestamp at which the current track was started.
 
static const QgsSettingsEntryDouble * settingsDistanceThreshold
 
void updateGpsSettings()
Should be called whenever the QGIS GPS settings are changed.
 
void trackReset()
Emitted whenever the current track is reset.
 
void resetTrack()
Resets the current track, discarding all recorded points.
 
QDateTime lastTimestamp() const
Returns the last recorded timestamp from the device.
 
void setAutomaticallyAddTrackVertices(bool enabled)
Sets whether track vertices will be automatically added whenever the GPS position is changed.
 
void addTrackVertex()
Adds a track vertex at the current GPS location.
 
double lastMValue() const
Returns the last recorded value corresponding to the QgsGpsLogger::settingsGpsMValueComponent setting...
 
double trackDistanceFromStart() const
Returns the direct length from the first vertex in the track to the last (in meters).
 
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context to be used when transforming GPS coordinates.
 
void setConnection(QgsGpsConnection *connection)
Sets the associated GPS connection.
 
void distanceAreaChanged()
Emitted whenever the distance area used to calculate track distances is changed.
 
QgsGpsConnection * connection()
Returns the associated GPS connection.
 
static const QgsSettingsEntryString * settingsTimestampTimeZone
 
double totalTrackLength() const
Returns the total length of the current digitized track (in meters).
 
void setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid which will be used for calculating distances in the log.
 
static const QgsSettingsEntryInteger * settingsAcquisitionInterval
 
QVariant componentValue(Qgis::GpsInformationComponent component) const
Returns the value of the corresponding GPS information component.
 
void trackVertexAdded(const QgsPoint &vertex)
Emitted whenever a new vertex is added to the track.
 
QgsPointXY lastPosition() const
Returns the last recorded position of the device.
 
bool isEmpty() const
Returns true if the geometry is empty.
 
Point geometry type, with support for z-dimension and m-values.
 
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
 
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
 
A boolean settings entry.
 
A template class for enum and flag settings entry.
 
An integer settings entry.
 
Holds the tree structure for the settings in QGIS core.
 
static QgsSettingsTreeNode * sTreeGps
 
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
 
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.
 
static Q_INVOKABLE bool isMultiType(Qgis::WkbType type)
Returns true if the WKB type is a multi type.
 
#define BUILTIN_UNREACHABLE
 
#define QgsDebugError(str)