Skip to content

Commit

Permalink
[processing] Use correct ellipsoid for network analysis tools
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Mar 19, 2024
1 parent 505883e commit 25fa2ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1869,6 +1871,7 @@ tests:

- algorithm: native:shortestpathlayertopoint
name: Shortest path layer to point
ellipsoid: WGS84
params:
DEFAULT_DIRECTION: 2
DEFAULT_SPEED: 5.0
Expand Down Expand Up @@ -1899,6 +1902,7 @@ tests:

- algorithm: native:shortestpathpointtolayer
name: Shortest path point to layer
ellipsoid: WGS84
params:
DEFAULT_DIRECTION: 2
DEFAULT_SPEED: 5.0
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void QgsNetworkAnalysisAlgorithmBase::loadCommonParams( const QVariantMap &param
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 )
Expand Down

0 comments on commit 25fa2ec

Please sign in to comment.