30 QString QgsNetworkAnalysisAlgorithmBase::group()
const
32 return QObject::tr(
"Network analysis" );
35 QString QgsNetworkAnalysisAlgorithmBase::groupId()
const
37 return QStringLiteral(
"networkanalysis" );
40 QgsProcessingAlgorithm::Flags QgsNetworkAnalysisAlgorithmBase::flags()
const
46 void QgsNetworkAnalysisAlgorithmBase::addCommonParams()
49 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"STRATEGY" ), QObject::tr(
"Path type to calculate" ), QStringList() << QObject::tr(
"Shortest" ) << QObject::tr(
"Fastest" ),
false, 0 ) );
51 std::unique_ptr< QgsProcessingParameterField > directionField = qgis::make_unique< QgsProcessingParameterField >( QStringLiteral(
"DIRECTION_FIELD" ),
54 addParameter( directionField.release() );
56 std::unique_ptr< QgsProcessingParameterString > forwardValue = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"VALUE_FORWARD" ),
57 QObject::tr(
"Value for forward direction" ), QVariant(),
false,
true );
59 addParameter( forwardValue.release() );
61 std::unique_ptr< QgsProcessingParameterString > backwardValue = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"VALUE_BACKWARD" ),
62 QObject::tr(
"Value for backward direction" ), QVariant(),
false,
true );
64 addParameter( backwardValue.release() );
66 std::unique_ptr< QgsProcessingParameterString > bothValue = qgis::make_unique< QgsProcessingParameterString >( QStringLiteral(
"VALUE_BOTH" ),
67 QObject::tr(
"Value for both directions" ), QVariant(),
false,
true );
69 addParameter( bothValue.release() );
71 std::unique_ptr< QgsProcessingParameterEnum > directionValue = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"DEFAULT_DIRECTION" ),
72 QObject::tr(
"Default direction" ), QStringList() << QObject::tr(
"Forward direction" ) << QObject::tr(
"Backward direction" ) << QObject::tr(
"Both directions" ),
false, 2 );
74 addParameter( directionValue.release() );
76 std::unique_ptr< QgsProcessingParameterField > speedField = qgis::make_unique< QgsProcessingParameterField >( QStringLiteral(
"SPEED_FIELD" ),
79 addParameter( speedField.release() );
81 std::unique_ptr< QgsProcessingParameterNumber > speed = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"DEFAULT_SPEED" ), QObject::tr(
"Default speed (km/h)" ),
QgsProcessingParameterNumber::Double, 50,
false, 0 );
83 addParameter( speed.release() );
85 std::unique_ptr< QgsProcessingParameterNumber > tolerance = qgis::make_unique < QgsProcessingParameterDistance >( QStringLiteral(
"TOLERANCE" ), QObject::tr(
"Topology tolerance" ), 0, QStringLiteral(
"INPUT" ),
false, 0 );
87 addParameter( tolerance.release() );
94 mNetwork.reset( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
98 int strategy = parameterAsInt( parameters, QStringLiteral(
"STRATEGY" ), context );
99 QString directionFieldName = parameterAsString( parameters, QStringLiteral(
"DIRECTION_FIELD" ), context );
100 QString forwardValue = parameterAsString( parameters, QStringLiteral(
"VALUE_FORWARD" ), context );
101 QString backwardValue = parameterAsString( parameters, QStringLiteral(
"VALUE_BACKWARD" ), context );
102 QString bothValue = parameterAsString( parameters, QStringLiteral(
"VALUE_BOTH" ), context );
104 QString speedFieldName = parameterAsString( parameters, QStringLiteral(
"SPEED_FIELD" ), context );
105 double defaultSpeed = parameterAsDouble( parameters, QStringLiteral(
"DEFAULT_SPEED" ), context );
106 double tolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
108 int directionField = -1;
109 if ( !directionFieldName.isEmpty() )
111 directionField = mNetwork->fields().lookupField( directionFieldName );
115 if ( !speedFieldName.isEmpty() )
117 speedField = mNetwork->fields().lookupField( speedFieldName );
120 mDirector =
new QgsVectorLayerDirector( mNetwork.get(), directionField, forwardValue, backwardValue, bothValue, defaultDirection );
127 mDirector->addStrategy(
new QgsNetworkSpeedStrategy( speedField, defaultSpeed, mMultiplier * 1000.0 / 3600.0 ) );
135 mBuilder = qgis::make_unique< QgsGraphBuilder >( mNetwork->sourceCrs(),
true, tolerance );
140 feedback->
pushInfo( QObject::tr(
"Loading points…" ) );
165 attributes.insert( pointId, feat.
attributes() );