Skip to content

Commit

Permalink
[gps] Don't correct for true north by default, and add manual bearing…
Browse files Browse the repository at this point in the history
… offset option

This change adds two new advanced settings keys for gps:

app\gps\bearingAdjustment: allows for specifying a manual adjustment
factor to apply to bearings obtained from the GPS, in the case that
the GPS reports offset bearings

app\gps\correctForTrueNorth: whether to apply a correction for
true north to bearings obtained from the GPS (now defaults to off)
  • Loading branch information
nyalldawson committed May 30, 2020
1 parent 81abbbb commit f5e55df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions resources/qgis_global_settings.ini
Expand Up @@ -86,6 +86,16 @@ projections\newProjectCrsBehavior=UseCrsOfFirstLayerAdded
# "UseDefaultCrs" - use the default layer CRS set via QGIS options
projections\unknownCrsBehavior=NoAction

# Specifies a manual bearing correction to apply to bearings reported by a GPS
# device, for use when a map canvas is set to match rotation to the GPS bearing
# or when showing the GPS bearing line
gps\bearingAdjustment=0

# Set to "true" to automatically correct GPS reported bearings for true north
# when a map canvas is set to match rotation to the GPS bearing
# or when showing the GPS bearing line
gps\correctForTrueNorth=false

[core]

# Desired flow control mode for serial port GPS connections
Expand Down
19 changes: 12 additions & 7 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -1002,18 +1002,23 @@ void QgsGpsInformationWidget::displayGPSInformation( const QgsGpsInformation &in
if ( !std::isnan( info.direction ) )
{
double trueNorth = 0;
try
{
trueNorth = QgsBearingUtils::bearingTrueNorth( mMapCanvas->mapSettings().destinationCrs(), QgsProject::instance()->transformContext(), mMapCanvas->mapSettings().visibleExtent().center() );
}
catch ( QgsException & )
QgsSettings settings;
if ( settings.value( QStringLiteral( "gps/correctForTrueNorth" ), false, QgsSettings::App ).toBool() )
{
try
{
trueNorth = QgsBearingUtils::bearingTrueNorth( mMapCanvas->mapSettings().destinationCrs(), QgsProject::instance()->transformContext(), mMapCanvas->mapSettings().visibleExtent().center() );
}
catch ( QgsException & )
{

}
}
const double adjustment = settings.value( QStringLiteral( "gps/bearingAdjustment" ), 0.0, QgsSettings::App ).toDouble();

if ( mRotateMapCheckBox->isChecked() && ( !mLastRotateTimer.isValid() || mLastRotateTimer.hasExpired( mSpinMapRotateInterval->value() * 1000 ) ) )
{
mMapCanvas->setRotation( trueNorth - info.direction );
mMapCanvas->setRotation( trueNorth - info.direction - adjustment );
mLastRotateTimer.restart();
}

Expand All @@ -1026,7 +1031,7 @@ void QgsGpsInformationWidget::displayGPSInformation( const QgsGpsInformation &in
}

mMapBearingItem->setGpsPosition( myNewCenter );
mMapBearingItem->setGpsBearing( info.direction - trueNorth );
mMapBearingItem->setGpsBearing( info.direction - trueNorth + adjustment );
}
else if ( mMapBearingItem )
{
Expand Down

0 comments on commit f5e55df

Please sign in to comment.