30 QString QgsNetworkAnalysisAlgorithmBase::group()
const
32 return QObject::tr(
"Network analysis" );
35 QString QgsNetworkAnalysisAlgorithmBase::groupId()
const
37 return QStringLiteral(
"networkanalysis" );
40 void QgsNetworkAnalysisAlgorithmBase::addCommonParams()
43 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"STRATEGY" ), QObject::tr(
"Path type to calculate" ), QStringList() << QObject::tr(
"Shortest" ) << QObject::tr(
"Fastest" ),
false, 0 ) );
45 std::unique_ptr< QgsProcessingParameterField > directionField = qgis::make_unique< QgsProcessingParameterField >( QStringLiteral(
"DIRECTION_FIELD" ),
48 addParameter( directionField.release() );
50 std::unique_ptr< QgsProcessingParameterString > forwardValue = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"VALUE_FORWARD" ),
51 QObject::tr(
"Value for forward direction" ), QVariant(),
false,
true );
53 addParameter( forwardValue.release() );
55 std::unique_ptr< QgsProcessingParameterString > backwardValue = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"VALUE_BACKWARD" ),
56 QObject::tr(
"Value for backward direction" ), QVariant(),
false,
true );
58 addParameter( backwardValue.release() );
60 std::unique_ptr< QgsProcessingParameterString > bothValue = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"VALUE_BOTH" ),
61 QObject::tr(
"Value for both directions" ), QVariant(),
false,
true );
63 addParameter( bothValue.release() );
65 std::unique_ptr< QgsProcessingParameterEnum > directionValue = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"DEFAULT_DIRECTION" ),
66 QObject::tr(
"Default direction" ), QStringList() << QObject::tr(
"Forward direction" ) << QObject::tr(
"Backward direction" ) << QObject::tr(
"Both directions" ),
false, 2 );
68 addParameter( directionValue.release() );
70 std::unique_ptr< QgsProcessingParameterField > speedField = qgis::make_unique< QgsProcessingParameterField >( QStringLiteral(
"SPEED_FIELD" ),
73 addParameter( speedField.release() );
75 std::unique_ptr< QgsProcessingParameterNumber > speed = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DEFAULT_SPEED" ), QObject::tr(
"Default speed (km/h)" ),
QgsProcessingParameterNumber::Double, 50,
false, 0 );
77 addParameter( speed.release() );
79 std::unique_ptr< QgsProcessingParameterNumber > tolerance = qgis::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"TOLERANCE" ), QObject::tr(
"Topology tolerance" ), 0, QStringLiteral(
"INPUT" ),
false, 0 );
81 addParameter( tolerance.release() );
88 mNetwork.reset( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
92 int strategy = parameterAsInt( parameters, QStringLiteral(
"STRATEGY" ), context );
93 QString directionFieldName = parameterAsString( parameters, QStringLiteral(
"DIRECTION_FIELD" ), context );
94 QString forwardValue = parameterAsString( parameters, QStringLiteral(
"VALUE_FORWARD" ), context );
95 QString backwardValue = parameterAsString( parameters, QStringLiteral(
"VALUE_BACKWARD" ), context );
96 QString bothValue = parameterAsString( parameters, QStringLiteral(
"VALUE_BOTH" ), context );
98 QString speedFieldName = parameterAsString( parameters, QStringLiteral(
"SPEED_FIELD" ), context );
99 double defaultSpeed = parameterAsDouble( parameters, QStringLiteral(
"DEFAULT_SPEED" ), context );
100 double tolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
102 int directionField = -1;
103 if ( !directionFieldName.isEmpty() )
105 directionField = mNetwork->fields().lookupField( directionFieldName );
109 if ( !speedFieldName.isEmpty() )
111 speedField = mNetwork->fields().lookupField( speedFieldName );
114 mDirector =
new QgsVectorLayerDirector( mNetwork.get(), directionField, forwardValue, backwardValue, bothValue, defaultDirection );
121 mDirector->addStrategy(
new QgsNetworkSpeedStrategy( speedField, defaultSpeed, mMultiplier * 1000.0 / 3600.0 ) );
129 mBuilder = qgis::make_unique< QgsGraphBuilder >( mNetwork->sourceCrs(),
true, tolerance );
134 feedback->
pushInfo( QObject::tr(
"Loading points…" ) );
159 attributes.insert( pointId, feat.
attributes() );