From 25fa2ec8f7ae6cb9d4c7c987020a431ac44634f4 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 8 Mar 2024 10:39:16 +1000 Subject: [PATCH] [processing] Use correct ellipsoid for network analysis tools Use the processing context's ellipsoid instead of a hardcoded WGS84 ellipsoid for distance calculations during network analysis, so that the lengths used will exactly match other measurement tools used on the same features in the same project. --- .../tests/testdata/qgis_algorithm_tests2.yaml | 12 ++++++++++++ .../processing/qgsalgorithmnetworkanalysisbase.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml b/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml index f43816b277bc..d98d5b180628 100644 --- a/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml +++ b/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml @@ -1808,6 +1808,7 @@ tests: - algorithm: native:shortestpathpointtopoint name: Shortest path (point to point, shortest route) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 5.0 @@ -1838,6 +1839,7 @@ tests: - algorithm: native:shortestpathpointtopoint name: Shortest path (point to point, fastest route) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 5.0 @@ -1869,6 +1871,7 @@ tests: - algorithm: native:shortestpathlayertopoint name: Shortest path layer to point + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 5.0 @@ -1899,6 +1902,7 @@ tests: - algorithm: native:shortestpathpointtolayer name: Shortest path point to layer + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 5.0 @@ -1929,6 +1933,7 @@ tests: - algorithm: native:serviceareafrompoint name: Service area from point (shortest, nodes) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -1960,6 +1965,7 @@ tests: - algorithm: native:serviceareafrompoint name: Service area from point (shortest, nodes, bounds) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -1986,6 +1992,7 @@ tests: - algorithm: native:serviceareafrompoint name: Service area from point (shortest, lines) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -2017,6 +2024,7 @@ tests: - algorithm: native:serviceareafrompoint name: Service area from point (fastest, old parameter) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -2051,6 +2059,7 @@ tests: - algorithm: native:serviceareafrompoint name: Service area from point (fastest, new parameter) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -2085,6 +2094,7 @@ tests: - algorithm: native:serviceareafromlayer name: Service area from layer (shortest, nodes) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -2120,6 +2130,7 @@ tests: - algorithm: native:serviceareafromlayer name: Service area from layer (shortest, nodes, boundary) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 @@ -2147,6 +2158,7 @@ tests: - algorithm: native:serviceareafromlayer name: Service area from layer (shortest, lines) + ellipsoid: WGS84 params: DEFAULT_DIRECTION: 2 DEFAULT_SPEED: 50.0 diff --git a/src/analysis/processing/qgsalgorithmnetworkanalysisbase.cpp b/src/analysis/processing/qgsalgorithmnetworkanalysisbase.cpp index 1aac17581aa0..d273671fc8c0 100644 --- a/src/analysis/processing/qgsalgorithmnetworkanalysisbase.cpp +++ b/src/analysis/processing/qgsalgorithmnetworkanalysisbase.cpp @@ -133,7 +133,7 @@ void QgsNetworkAnalysisAlgorithmBase::loadCommonParams( const QVariantMap ¶m mDirector->addStrategy( new QgsNetworkDistanceStrategy() ); } - mBuilder = std::make_unique< QgsGraphBuilder >( mNetwork->sourceCrs(), true, tolerance ); + mBuilder = std::make_unique< QgsGraphBuilder >( mNetwork->sourceCrs(), true, tolerance, context.ellipsoid() ); } void QgsNetworkAnalysisAlgorithmBase::loadPoints( QgsFeatureSource *source, QVector< QgsPointXY > &points, QHash< int, QgsAttributes > &attributes, QgsProcessingContext &context, QgsProcessingFeedback *feedback )