diff --git a/python/plugins/processing/tests/testdata/expected/service_area_fastest_nodes.gml b/python/plugins/processing/tests/testdata/expected/service_area_fastest_nodes.gml new file mode 100644 index 000000000000..3dab43e64daf --- /dev/null +++ b/python/plugins/processing/tests/testdata/expected/service_area_fastest_nodes.gml @@ -0,0 +1,21 @@ + + + + + 1002023.9295166796221487.760335854 + 1002827.7150467476222185.769065672 + + + + + + 1002023.92951668,6221544.259414111002226.25738032,6221518.347305461002799.96137266,6221861.966787671002734.26457445,6222073.391168291002827.71504675,6222143.532674451002507.37138296,6222181.740545261002512.08571525,6222181.363342281002507.68974452,6222185.769065671002480.47678085,6221961.349070841002319.14873192,6222045.131965591002258.48459656,6221984.897818531002090.1306568,6221871.327052321002065.78480569,6221856.922690741002067.99167685,6221878.787224881002085.28506334,6221855.502298461002195.42200931,6221714.597087131002242.51614345,6221653.851117171002369.47645633,6221487.760335851002378.42064641,6221631.180307831002227.95811523,6221516.164072371002225.67739976,6221519.083541321002228.28242073,6221518.770091491002464.51299513,6221625.109457511002599.36987065,6221613.27875561002492.67674944,6221959.86295761002544.46173119,6222146.820495451002513.39282933,6222180.050762821002546.98295224,6222178.435016121002746.38005306,6221522.210532061002766.07582328,6221803.544452541002137.81278244,6221630.620180511002215.13556068,6221689.254468871002288.4678461,6221744.859644951002334.20638747,6221779.490982841002425.63766482,6221848.744465431002462.62346654,6221875.387804421002518.06990805,6221915.348757411002626.85249869,6221993.75622021002657.33259138,6222018.206205361002781.74783802,6222107.451932551002509.88988421,6222183.568354631002380.76911747,6222089.858594961002284.1421556,6222019.722741821002076.31366647,6221866.903615331002131.61040283,6221796.629652131002302.22841804,6221576.642583061002310.58466849,6221563.422003221002226.82368085,6221517.628435221002532.83636772,6221785.381365211002421.46534272,6221674.175717251002526.28363451,6221554.702499941002485.75145034,6221954.550744191002621.6858386,6222058.822411011002529.45107897,6222163.925369651002643.23398503,6221648.434425311002623.85396603,6221672.144810971002423.478385,6221847.10894582 + within + 1002424.32112, 6221845.99633 + + + diff --git a/python/plugins/processing/tests/testdata/expected/service_area_fastest_nodes.xsd b/python/plugins/processing/tests/testdata/expected/service_area_fastest_nodes.xsd new file mode 100644 index 000000000000..fb1e569c6573 --- /dev/null +++ b/python/plugins/processing/tests/testdata/expected/service_area_fastest_nodes.xsd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/python/plugins/processing/tests/testdata/expected/service_area_fastests_lines.gml b/python/plugins/processing/tests/testdata/expected/service_area_fastests_lines.gml new file mode 100644 index 000000000000..1c04e1b630a7 --- /dev/null +++ b/python/plugins/processing/tests/testdata/expected/service_area_fastests_lines.gml @@ -0,0 +1,21 @@ + + + + + 1002023.9295166796221487.760335854 + 1002827.7150467476222185.769065672 + + + + + + 1002137.81278244,6221630.62018051 1002023.92951668,6221544.259414111002137.81278244,6221630.62018051 1002215.13556068,6221689.254468871002137.81278244,6221630.62018051 1002226.25738032,6221518.347305461002215.13556068,6221689.25446887 1002137.81278244,6221630.620180511002215.13556068,6221689.25446887 1002288.4678461,6221744.859644951002215.13556068,6221689.25446887 1002131.61040283,6221796.629652131002215.13556068,6221689.25446887 1002302.22841804,6221576.642583061002288.4678461,6221744.85964495 1002215.13556068,6221689.254468871002288.4678461,6221744.85964495 1002334.20638747,6221779.490982841002334.20638747,6221779.49098284 1002288.4678461,6221744.859644951002334.20638747,6221779.49098284 1002423.478385,6221847.108945821002334.20638747,6221779.49098284 1002421.46534272,6221674.175717251002425.63766482,6221848.74446543 1002423.478385,6221847.108945821002425.63766482,6221848.74446543 1002462.62346654,6221875.387804421002462.62346654,6221875.38780442 1002425.63766482,6221848.744465431002462.62346654,6221875.38780442 1002518.06990805,6221915.348757411002462.62346654,6221875.38780442 1002532.83636772,6221785.381365211002518.06990805,6221915.34875741 1002462.62346654,6221875.387804421002518.06990805,6221915.34875741 1002626.85249869,6221993.75622021002518.06990805,6221915.34875741 1002485.75145034,6221954.550744191002626.85249869,6221993.7562202 1002518.06990805,6221915.348757411002626.85249869,6221993.7562202 1002657.33259138,6222018.206205361002657.33259138,6222018.20620536 1002626.85249869,6221993.75622021002657.33259138,6222018.20620536 1002781.74783802,6222107.451932551002657.33259138,6222018.20620536 1002621.6858386,6222058.822411011002657.33259138,6222018.20620536 1002799.96137266,6221861.966787671002781.74783802,6222107.45193255 1002734.26457445,6222073.391168291002781.74783802,6222107.45193255 1002827.71504675,6222143.532674451002509.88988421,6222183.56835463 1002507.37138296,6222181.740545261002509.88988421,6222183.56835463 1002512.08571525,6222181.363342281002509.88988421,6222183.56835463 1002507.68974452,6222185.769065671002380.76911747,6222089.85859496 1002509.88988421,6222183.568354631002380.76911747,6222089.85859496 1002284.1421556,6222019.722741821002380.76911747,6222089.85859496 1002480.47678085,6221961.349070841002284.1421556,6222019.72274182 1002319.14873192,6222045.131965591002284.1421556,6222019.72274182 1002258.48459656,6221984.897818531002076.31366647,6221866.90361533 1002090.1306568,6221871.327052321002076.31366647,6221866.90361533 1002065.78480569,6221856.922690741002076.31366647,6221866.90361533 1002067.99167685,6221878.787224881002076.31366647,6221866.90361533 1002085.28506334,6221855.502298461002131.61040283,6221796.62965213 1002076.31366647,6221866.903615331002131.61040283,6221796.62965213 1002195.42200931,6221714.597087131002302.22841804,6221576.64258306 1002242.51614345,6221653.851117171002302.22841804,6221576.64258306 1002310.58466849,6221563.422003221002302.22841804,6221576.64258306 1002226.82368085,6221517.628435221002310.58466849,6221563.42200322 1002302.22841804,6221576.642583061002310.58466849,6221563.42200322 1002369.47645633,6221487.760335851002310.58466849,6221563.42200322 1002378.42064641,6221631.180307831002226.82368085,6221517.62843522 1002227.95811523,6221516.164072371002226.82368085,6221517.62843522 1002225.67739976,6221519.083541321002226.82368085,6221517.62843522 1002228.28242073,6221518.770091491002532.83636772,6221785.38136521 1002421.46534272,6221674.175717251002532.83636772,6221785.38136521 1002462.62346654,6221875.387804421002532.83636772,6221785.38136521 1002623.85396603,6221672.144810971002421.46534272,6221674.17571725 1002532.83636772,6221785.381365211002421.46534272,6221674.17571725 1002310.58466849,6221563.422003221002421.46534272,6221674.17571725 1002526.28363451,6221554.702499941002421.46534272,6221674.17571725 1002334.20638747,6221779.490982841002526.28363451,6221554.70249994 1002464.51299513,6221625.109457511002526.28363451,6221554.70249994 1002599.36987065,6221613.27875561002485.75145034,6221954.55074419 1002380.76911747,6222089.858594961002485.75145034,6221954.55074419 1002518.06990805,6221915.348757411002485.75145034,6221954.55074419 1002621.6858386,6222058.822411011002621.6858386,6222058.82241101 1002657.33259138,6222018.206205361002621.6858386,6222058.82241101 1002529.45107897,6222163.925369651002621.6858386,6222058.82241101 1002492.67674944,6221959.86295761002529.45107897,6222163.92536965 1002544.46173119,6222146.820495451002529.45107897,6222163.92536965 1002513.39282933,6222180.050762821002529.45107897,6222163.92536965 1002546.98295224,6222178.435016121002643.23398503,6221648.43442531 1002746.38005306,6221522.210532061002643.23398503,6221648.43442531 1002623.85396603,6221672.144810971002643.23398503,6221648.43442531 1002526.28363451,6221554.702499941002623.85396603,6221672.14481097 1002643.23398503,6221648.434425311002623.85396603,6221672.14481097 1002532.83636772,6221785.381365211002623.85396603,6221672.14481097 1002766.07582328,6221803.544452541002423.478385,6221847.10894582 1002334.20638747,6221779.490982841002423.478385,6221847.10894582 1002425.63766482,6221848.74446543 + lines + 1002424.32112, 6221845.99633 + + + diff --git a/python/plugins/processing/tests/testdata/expected/service_area_fastests_lines.xsd b/python/plugins/processing/tests/testdata/expected/service_area_fastests_lines.xsd new file mode 100644 index 000000000000..3c7ba826ef4d --- /dev/null +++ b/python/plugins/processing/tests/testdata/expected/service_area_fastests_lines.xsd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml b/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml index 5ba1b11de351..48d724f57e9d 100755 --- a/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml +++ b/python/plugins/processing/tests/testdata/qgis_algorithm_tests2.yaml @@ -1881,6 +1881,54 @@ tests: start: skip end: skip + - algorithm: native:serviceareafrompoint + name: Service area from point (fastest, old parameter) + params: + DEFAULT_DIRECTION: 2 + DEFAULT_SPEED: 50.0 + INCLUDE_BOUNDS: false + INPUT: + name: roads.gml|layername=roads + type: vector + START_POINT: 1002424.321122,6221845.996330 [EPSG:32733] + STRATEGY: 1 + TOLERANCE: 0.0 + TRAVEL_COST: 36 + VALUE_BACKWARD: '' + VALUE_BOTH: '' + VALUE_FORWARD: '' + results: + OUTPUT: + name: expected/service_area_fastest_nodes.gml + type: vector + OUTPUT_LINES: + name: expected/service_area_fastests_lines.gml + type: vector + + - algorithm: native:serviceareafrompoint + name: Service area from point (fastest, new parameter) + params: + DEFAULT_DIRECTION: 2 + DEFAULT_SPEED: 50.0 + INCLUDE_BOUNDS: false + INPUT: + name: roads.gml|layername=roads + type: vector + START_POINT: 1002424.321122,6221845.996330 [EPSG:32733] + STRATEGY: 1 + TOLERANCE: 0.0 + TRAVEL_COST2: 0.01 + VALUE_BACKWARD: '' + VALUE_BOTH: '' + VALUE_FORWARD: '' + results: + OUTPUT: + name: expected/service_area_fastest_nodes.gml + type: vector + OUTPUT_LINES: + name: expected/service_area_fastests_lines.gml + type: vector + - algorithm: native:serviceareafromlayer name: Service area from layer (shortest, nodes) params: diff --git a/src/analysis/processing/qgsalgorithmserviceareafromlayer.cpp b/src/analysis/processing/qgsalgorithmserviceareafromlayer.cpp index 7e73a5cb520c..691d0e46159e 100644 --- a/src/analysis/processing/qgsalgorithmserviceareafromlayer.cpp +++ b/src/analysis/processing/qgsalgorithmserviceareafromlayer.cpp @@ -39,7 +39,11 @@ QStringList QgsServiceAreaFromLayerAlgorithm::tags() const QString QgsServiceAreaFromLayerAlgorithm::shortHelpString() const { - return QObject::tr( "This algorithm creates a new vector with all the edges or parts of edges of a network line layer that can be reached within a distance or a time, starting from features of a point layer. The distance and the time (both referred to as \"travel cost\") must be specified respectively in the network layer units or in seconds." ); + return QObject::tr( "This algorithm creates a new vector with all the edges or parts of " + "edges of a network line layer that can be reached within a distance " + "or a time, starting from features of a point layer. The distance and " + "the time (both referred to as \"travel cost\") must be specified " + "respectively in the network layer units or in hours." ); } QgsServiceAreaFromLayerAlgorithm *QgsServiceAreaFromLayerAlgorithm::createInstance() const @@ -51,7 +55,12 @@ void QgsServiceAreaFromLayerAlgorithm::initAlgorithm( const QVariantMap & ) { addCommonParams(); addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "START_POINTS" ), QObject::tr( "Vector layer with start points" ), QList< int >() << QgsProcessing::TypeVectorPoint ) ); - addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TRAVEL_COST" ), QObject::tr( "Travel cost (distance for 'Shortest', time for 'Fastest')" ), + + std::unique_ptr< QgsProcessingParameterNumber > travelCost = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "TRAVEL_COST" ), QObject::tr( "Travel cost (distance for 'Shortest', time for 'Fastest')" ), QgsProcessingParameterNumber::Double, 0, true, 0 ); + travelCost->setFlags( travelCost->flags() | QgsProcessingParameterDefinition::FlagHidden ); + addParameter( travelCost.release() ); + + addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TRAVEL_COST2" ), QObject::tr( "Travel cost (distance for 'Shortest', time for 'Fastest')" ), QgsProcessingParameterNumber::Double, 0, false, 0 ) ); std::unique_ptr< QgsProcessingParameterBoolean > includeBounds = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( "INCLUDE_BOUNDS" ), QObject::tr( "Include upper/lower bound points" ), false, true ); @@ -77,7 +86,13 @@ QVariantMap QgsServiceAreaFromLayerAlgorithm::processAlgorithm( const QVariantMa if ( !startPoints ) throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "START_POINTS" ) ) ); - double travelCost = parameterAsDouble( parameters, QStringLiteral( "TRAVEL_COST" ), context ); + // use older deprecated travel cost style if specified, to maintain old api + const bool useOldTravelCost = parameters.value( QStringLiteral( "TRAVEL_COST" ) ).isValid(); + double travelCost = parameterAsDouble( parameters, useOldTravelCost ? QStringLiteral( "TRAVEL_COST" ) : QStringLiteral( "TRAVEL_COST2" ), context ); + + int strategy = parameterAsInt( parameters, QStringLiteral( "STRATEGY" ), context ); + if ( strategy && !useOldTravelCost ) + travelCost *= mMultiplier; bool includeBounds = true; // default to true to maintain 3.0 API if ( parameters.contains( QStringLiteral( "INCLUDE_BOUNDS" ) ) ) diff --git a/src/analysis/processing/qgsalgorithmserviceareafrompoint.cpp b/src/analysis/processing/qgsalgorithmserviceareafrompoint.cpp index 93fc74eb14ca..4d40a7595d50 100644 --- a/src/analysis/processing/qgsalgorithmserviceareafrompoint.cpp +++ b/src/analysis/processing/qgsalgorithmserviceareafrompoint.cpp @@ -39,7 +39,11 @@ QStringList QgsServiceAreaFromPointAlgorithm::tags() const QString QgsServiceAreaFromPointAlgorithm::shortHelpString() const { - return QObject::tr( "This algorithm creates a new vector with all the edges or parts of edges of a network line layer that can be reached within a distance or a time, starting from a point feature. The distance and the time (both referred to as \"travel cost\") must be specified respectively in the network layer units or in seconds." ); + return QObject::tr( "This algorithm creates a new vector with all the edges or parts of edges " + "of a network line layer that can be reached within a distance or a time, " + "starting from a point feature. The distance and the time (both referred to " + "as \"travel cost\") must be specified respectively in the network layer " + "units or in hours." ); } QgsServiceAreaFromPointAlgorithm *QgsServiceAreaFromPointAlgorithm::createInstance() const @@ -51,7 +55,12 @@ void QgsServiceAreaFromPointAlgorithm::initAlgorithm( const QVariantMap & ) { addCommonParams(); addParameter( new QgsProcessingParameterPoint( QStringLiteral( "START_POINT" ), QObject::tr( "Start point" ) ) ); - addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TRAVEL_COST" ), QObject::tr( "Travel cost (distance for 'Shortest', time for 'Fastest')" ), + + std::unique_ptr< QgsProcessingParameterNumber > travelCost = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "TRAVEL_COST" ), QObject::tr( "Travel cost (distance for 'Shortest', time for 'Fastest')" ), QgsProcessingParameterNumber::Double, 0, true, 0 ); + travelCost->setFlags( travelCost->flags() | QgsProcessingParameterDefinition::FlagHidden ); + addParameter( travelCost.release() ); + + addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TRAVEL_COST2" ), QObject::tr( "Travel cost (distance for 'Shortest', time for 'Fastest')" ), QgsProcessingParameterNumber::Double, 0, false, 0 ) ); std::unique_ptr< QgsProcessingParameterBoolean > includeBounds = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( "INCLUDE_BOUNDS" ), QObject::tr( "Include upper/lower bound points" ), false, true ); @@ -74,7 +83,14 @@ QVariantMap QgsServiceAreaFromPointAlgorithm::processAlgorithm( const QVariantMa loadCommonParams( parameters, context, feedback ); QgsPointXY startPoint = parameterAsPoint( parameters, QStringLiteral( "START_POINT" ), context, mNetwork->sourceCrs() ); - double travelCost = parameterAsDouble( parameters, QStringLiteral( "TRAVEL_COST" ), context ); + + // use older deprecated travel cost style if specified, to maintain old api + const bool useOldTravelCost = parameters.value( QStringLiteral( "TRAVEL_COST" ) ).isValid(); + double travelCost = parameterAsDouble( parameters, useOldTravelCost ? QStringLiteral( "TRAVEL_COST" ) : QStringLiteral( "TRAVEL_COST2" ), context ); + + int strategy = parameterAsInt( parameters, QStringLiteral( "STRATEGY" ), context ); + if ( strategy && !useOldTravelCost ) + travelCost *= mMultiplier; bool includeBounds = true; // default to true to maintain 3.0 API if ( parameters.contains( QStringLiteral( "INCLUDE_BOUNDS" ) ) )