-
Notifications
You must be signed in to change notification settings - Fork 75
GNSS enhancements bundle #4234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
GNSS enhancements bundle #4234
Changes from 30 commits
d3e961e
4436062
9ab6816
2d801ea
b09dc43
6be4dfe
7f41eb1
d02bfd3
23bb99b
e8d7e46
daa06be
7428d5c
a7e1f63
c9c6d14
d95d6ed
d1c7a7f
c10f6bd
1957130
37cf85d
d3db441
59c5557
cd8f19c
b0ef9a8
29cd087
fe08648
e042e32
41f63be
48c1ab9
b186942
931e89b
93adc5f
4801f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -477,7 +477,7 @@ QString InputUtils::geometryLengthAsString( const QgsGeometry &geometry ) | |
| { | ||
| QgsDistanceArea distanceArea; | ||
| distanceArea.setEllipsoid( QStringLiteral( "WGS84" ) ); | ||
| distanceArea.setSourceCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ), QgsCoordinateTransformContext() ); | ||
| distanceArea.setSourceCrs( PositionKit::positionCrs2D(), QgsProject::instance()->transformContext() ); | ||
|
|
||
| qreal length = distanceArea.measureLength( geometry ); | ||
|
|
||
|
|
@@ -880,32 +880,66 @@ QgsPoint InputUtils::transformPoint( const QgsCoordinateReferenceSystem &srcCrs, | |
| // QGIS would convert them to a valid (0, 0) points | ||
| if ( srcPoint.isEmpty() ) | ||
| { | ||
| return QgsPoint(); | ||
| return {}; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| QgsCoordinateTransform ct( srcCrs, destCrs, context ); | ||
| const QgsCoordinateTransform ct( srcCrs, destCrs, context ); | ||
| if ( ct.isValid() ) | ||
| { | ||
| if ( !ct.isShortCircuited() ) | ||
| { | ||
| const QgsPointXY transformed = ct.transform( srcPoint.x(), srcPoint.y() ); | ||
| const QgsPoint pt( transformed.x(), transformed.y(), srcPoint.z(), srcPoint.m() ); | ||
| const QgsVector3D transformed = ct.transform( QgsVector3D( srcPoint.x(), srcPoint.y(), srcPoint.z() ) ); | ||
| const QgsPoint pt( transformed.x(), transformed.y(), transformed.z(), srcPoint.m() ); | ||
| return pt; | ||
| } | ||
| else | ||
|
|
||
| return srcPoint; | ||
| } | ||
| } | ||
| catch ( QgsCsException &cse ) | ||
| { | ||
| Q_UNUSED( cse ) | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| QgsPoint InputUtils::transformPoint( const QgsCoordinateReferenceSystem &srcCrs, | ||
| const QgsCoordinateReferenceSystem &destCrs, | ||
| const QgsCoordinateTransformContext &context, | ||
| const QgsPoint &srcPoint, bool &fallbackOperationOccurred ) | ||
| { | ||
| // we do not want to transform empty points, | ||
| // QGIS would convert them to a valid (0, 0) points | ||
| if ( srcPoint.isEmpty() ) | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| const QgsCoordinateTransform ct( srcCrs, destCrs, context ); | ||
| if ( ct.isValid() ) | ||
| { | ||
| if ( !ct.isShortCircuited() ) | ||
| { | ||
| return srcPoint; | ||
| const QgsVector3D transformed = ct.transform( QgsVector3D( srcPoint.x(), srcPoint.y(), srcPoint.z() ) ); | ||
| fallbackOperationOccurred = ct.fallbackOperationOccurred(); | ||
| const QgsPoint pt( transformed.x(), transformed.y(), transformed.z(), srcPoint.m() ); | ||
| return pt; | ||
| } | ||
|
|
||
| return srcPoint; | ||
| } | ||
| } | ||
| catch ( QgsCsException &cse ) | ||
| { | ||
| Q_UNUSED( cse ) | ||
| } | ||
|
|
||
| return QgsPoint(); | ||
| return {}; | ||
| } | ||
|
|
||
| QPointF InputUtils::transformPointToScreenCoordinates( const QgsCoordinateReferenceSystem &srcCrs, InputMapSettings *mapSettings, const QgsPoint &srcPoint ) | ||
|
|
@@ -954,12 +988,11 @@ QgsPoint InputUtils::mapPointToGps( QPointF mapPosition, InputMapSettings *mapSe | |
| return QgsPoint(); | ||
|
|
||
| QgsPoint positionMapCrs = mapSettings->screenToCoordinate( mapPosition ); | ||
| QgsCoordinateReferenceSystem crsGPS = coordinateReferenceSystemFromEpsgId( 4326 ); | ||
|
|
||
| const QgsPointXY transformedXY = transformPoint( | ||
| mapSettings->destinationCrs(), | ||
| crsGPS, | ||
| QgsCoordinateTransformContext(), | ||
| PositionKit::positionCrs2D(), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 2D in this case and 3D in all other? |
||
| mapSettings->transformContext(), | ||
| positionMapCrs | ||
| ); | ||
|
|
||
|
|
@@ -1716,7 +1749,7 @@ qreal InputUtils::distanceBetweenGpsAndFeature( QgsPoint gpsPosition, const Feat | |
|
|
||
| // Transform gps position to map CRS | ||
| QgsPointXY transformedPosition = transformPoint( | ||
| coordinateReferenceSystemFromEpsgId( 4326 ), | ||
| PositionKit::positionCrs3D(), | ||
| mapSettings->destinationCrs(), | ||
| mapSettings->transformContext(), | ||
| gpsPosition | ||
|
|
@@ -1764,7 +1797,7 @@ qreal InputUtils::angleBetweenGpsAndFeature( QgsPoint gpsPoint, const FeatureLay | |
|
|
||
| // Transform gps position to map CRS | ||
| QgsPointXY transformedPosition = transformPoint( | ||
| coordinateReferenceSystemFromEpsgId( 4326 ), | ||
| PositionKit::positionCrs3D(), | ||
| mapSettings->destinationCrs(), | ||
| mapSettings->transformContext(), | ||
| gpsPoint | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,11 +33,57 @@ PositionKit::PositionKit( QObject *parent ) | |
| { | ||
| } | ||
|
|
||
| QgsCoordinateReferenceSystem PositionKit::positionCRS() | ||
| QgsCoordinateReferenceSystem PositionKit::positionCrs3D( const bool forceDefault ) | ||
| { | ||
| if ( !forceDefault ) | ||
| { | ||
| bool crsExists = false; | ||
| const QString crsWktDef = QgsProject::instance()->readEntry( QStringLiteral( "Mergin" ), QStringLiteral( "TargetVerticalCRS" ), QString(), &crsExists ); | ||
| if ( crsExists ) | ||
| { | ||
| const QgsCoordinateReferenceSystem verticalCrs = QgsCoordinateReferenceSystem::fromWkt( crsWktDef ); | ||
| QString compoundCrsError{}; | ||
| const QgsCoordinateReferenceSystem compoundCrs = QgsCoordinateReferenceSystem::createCompoundCrs( positionCrs2D(), verticalCrs, compoundCrsError ); | ||
| if ( compoundCrs.isValid() && compoundCrsError.isEmpty() ) | ||
| { | ||
| return compoundCrs; | ||
| } | ||
| CoreUtils::log( QStringLiteral( "PositionKit" ), QStringLiteral( "Failed to create custom compound crs: %1" ).arg( compoundCrsError ) ); | ||
| } | ||
| } | ||
|
|
||
| return QgsCoordinateReferenceSystem::fromEpsgId( 9707 ); | ||
| } | ||
|
|
||
| QString PositionKit::positionCrs3DGeoidModelName() const | ||
| { | ||
| if ( !mPosition.isMock ) | ||
| { | ||
| const QgsCoordinateReferenceSystem crs = positionCrs3D( true ).verticalCrs(); | ||
| return crs.description(); | ||
| } | ||
|
|
||
| bool valueRead = false; | ||
| const bool isVerticalCRSPassedThrough = QVariant( QgsProject::instance()->readEntry( QStringLiteral( "Mergin" ), QStringLiteral( "VerticalCRSPassThrough" ), QVariant( true ).toString(), &valueRead ) ).toBool(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am seeing too many |
||
| if ( valueRead && !isVerticalCRSPassedThrough ) | ||
| { | ||
| const QgsCoordinateReferenceSystem crs = positionCrs3D().verticalCrs(); | ||
| return crs.description(); | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| QgsCoordinateReferenceSystem PositionKit::positionCrs2D() | ||
| { | ||
| return QgsCoordinateReferenceSystem::fromEpsgId( 4326 ); | ||
| } | ||
|
|
||
| QgsCoordinateReferenceSystem PositionKit::positionCrs3DEllipsoidHeight() | ||
| { | ||
| return QgsCoordinateReferenceSystem::fromEpsgId( 4979 ); | ||
| } | ||
|
|
||
| void PositionKit::startUpdates() | ||
| { | ||
| if ( mPositionProvider ) | ||
|
|
@@ -148,7 +194,11 @@ AbstractPositionProvider *PositionKit::constructActiveProvider( AppSettings *app | |
| { | ||
| if ( InputUtils::isMobilePlatform() ) | ||
| { | ||
| #ifdef ANDROID | ||
| return constructProvider( QStringLiteral( "internal" ), QStringLiteral( "android_fused" ) ); | ||
Withalion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #else | ||
| return constructProvider( QStringLiteral( "internal" ), QStringLiteral( "devicegps" ) ); | ||
| #endif | ||
| } | ||
| else // desktop | ||
| { | ||
|
|
@@ -205,9 +255,9 @@ void PositionKit::parsePositionUpdate( const GeoPosition &newPosition ) | |
| hasAnythingChanged = true; | ||
| } | ||
|
|
||
| if ( !qgsDoubleNear( newPosition.elevation, mPosition.elevation ) ) | ||
| if ( !qgsDoubleNear( newPosition.elevation - antennaHeight(), mPosition.elevation ) ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| mPosition.elevation = newPosition.elevation; | ||
| mPosition.elevation = newPosition.elevation - antennaHeight(); | ||
| emit altitudeChanged( mPosition.elevation ); | ||
| hasAnythingChanged = true; | ||
| } | ||
|
|
@@ -323,6 +373,13 @@ void PositionKit::parsePositionUpdate( const GeoPosition &newPosition ) | |
| hasAnythingChanged = true; | ||
| } | ||
|
|
||
| if ( newPosition.isMock != mPosition.isMock ) | ||
| { | ||
| mPosition.isMock = newPosition.isMock; | ||
| emit isMockPositionChanged( mPosition.isMock ); | ||
| hasAnythingChanged = true; | ||
| } | ||
|
|
||
| if ( hasAnythingChanged ) | ||
| { | ||
| emit positionChanged( mPosition ); | ||
|
|
@@ -449,6 +506,11 @@ const GeoPosition &PositionKit::position() const | |
| return mPosition; | ||
| } | ||
|
|
||
| bool PositionKit::isMockPosition() const | ||
| { | ||
| return mPosition.isMock; | ||
| } | ||
|
|
||
| AppSettings *PositionKit::appSettings() const | ||
| { | ||
| return mAppSettings; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to have both
transformPointmethods, can we make one call the other one instead of keeping nearly identical bodies duplicated?Something like