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() );
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Wrapper for iterator of features from vector data provider or vector layer.
bool isCanceled() const
Tells whether the operation has been canceled already.
Direction
Edge direction Edge can be one-way with direct flow (one can move only from the start point to the en...
Base class for providing feedback from a processing algorithm.
Parameter is an advanced parameter which should be hidden from users by default.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry...
Determine making the graph from vector line layer.
A class to represent a 2D point.
void setProgress(double progress)
Sets the current progress for the feedback object.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
A geometry is the spatial representation of a feature.
QgsUnitTypes::DistanceUnit mapUnits
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Strategy for calculating edge cost based on travel time.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
QgsCoordinateReferenceSystem crs
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
The vertex_iterator class provides STL-style iterator for vertices.
Strategy for calculating edge cost based on its length.
DistanceUnit
Units of distance.
An interface for objects which provide features via a getFeatures method.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool nextFeature(QgsFeature &f)
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Contains information about the context in which a processing algorithm is executed.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown...