31QString QgsNetworkAnalysisAlgorithmBase::group()
const
33 return QObject::tr(
"Network analysis" );
36QString QgsNetworkAnalysisAlgorithmBase::groupId()
const
38 return QStringLiteral(
"networkanalysis" );
47void QgsNetworkAnalysisAlgorithmBase::addCommonParams()
50 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"STRATEGY" ), QObject::tr(
"Path type to calculate" ), QStringList() << QObject::tr(
"Shortest" ) << QObject::tr(
"Fastest" ),
false, 0 ) );
52 std::unique_ptr<QgsProcessingParameterField> directionField = std::make_unique<QgsProcessingParameterField>( QStringLiteral(
"DIRECTION_FIELD" ), QObject::tr(
"Direction field" ), QVariant(), QStringLiteral(
"INPUT" ),
Qgis::ProcessingFieldParameterDataType::Any,
false,
true );
54 addParameter( directionField.release() );
56 std::unique_ptr<QgsProcessingParameterString> forwardValue = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"VALUE_FORWARD" ), QObject::tr(
"Value for forward direction" ), QVariant(),
false,
true );
58 addParameter( forwardValue.release() );
60 std::unique_ptr<QgsProcessingParameterString> backwardValue = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"VALUE_BACKWARD" ), QObject::tr(
"Value for backward direction" ), QVariant(),
false,
true );
62 addParameter( backwardValue.release() );
64 std::unique_ptr<QgsProcessingParameterString> bothValue = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"VALUE_BOTH" ), QObject::tr(
"Value for both directions" ), QVariant(),
false,
true );
66 addParameter( bothValue.release() );
68 std::unique_ptr<QgsProcessingParameterEnum> directionValue = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"DEFAULT_DIRECTION" ), QObject::tr(
"Default direction" ), QStringList() << QObject::tr(
"Forward direction" ) << QObject::tr(
"Backward direction" ) << QObject::tr(
"Both directions" ),
false, 2 );
70 addParameter( directionValue.release() );
72 std::unique_ptr<QgsProcessingParameterField> speedField = std::make_unique<QgsProcessingParameterField>( QStringLiteral(
"SPEED_FIELD" ), QObject::tr(
"Speed field" ), QVariant(), QStringLiteral(
"INPUT" ),
Qgis::ProcessingFieldParameterDataType::Numeric,
false,
true );
74 addParameter( speedField.release() );
76 std::unique_ptr<QgsProcessingParameterNumber> speed = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"DEFAULT_SPEED" ), QObject::tr(
"Default speed (km/h)" ),
Qgis::ProcessingNumberParameterType::Double, 50,
false, 0 );
78 addParameter( speed.release() );
80 std::unique_ptr<QgsProcessingParameterNumber> tolerance = std::make_unique<QgsProcessingParameterDistance>( QStringLiteral(
"TOLERANCE" ), QObject::tr(
"Topology tolerance" ), 0, QStringLiteral(
"INPUT" ),
false, 0 );
82 addParameter( tolerance.release() );
89 mNetwork.reset( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
93 const int strategy = parameterAsInt( parameters, QStringLiteral(
"STRATEGY" ), context );
94 const QString directionFieldName = parameterAsString( parameters, QStringLiteral(
"DIRECTION_FIELD" ), context );
95 const QString forwardValue = parameterAsString( parameters, QStringLiteral(
"VALUE_FORWARD" ), context );
96 const QString backwardValue = parameterAsString( parameters, QStringLiteral(
"VALUE_BACKWARD" ), context );
97 const QString bothValue = parameterAsString( parameters, QStringLiteral(
"VALUE_BOTH" ), context );
99 const QString speedFieldName = parameterAsString( parameters, QStringLiteral(
"SPEED_FIELD" ), context );
100 const double defaultSpeed = parameterAsDouble( parameters, QStringLiteral(
"DEFAULT_SPEED" ), context );
101 const double tolerance = parameterAsDouble( parameters, QStringLiteral(
"TOLERANCE" ), context );
103 int directionField = -1;
104 if ( !directionFieldName.isEmpty() )
106 directionField = mNetwork->fields().lookupField( directionFieldName );
110 if ( !speedFieldName.isEmpty() )
112 speedField = mNetwork->fields().lookupField( speedFieldName );
115 mDirector =
new QgsVectorLayerDirector( mNetwork.get(), directionField, forwardValue, backwardValue, bothValue, defaultDirection );
122 mDirector->addStrategy(
new QgsNetworkSpeedStrategy( speedField, defaultSpeed, mMultiplier * 1000.0 / 3600.0 ) );
130 mBuilder = std::make_unique<QgsGraphBuilder>( mNetwork->sourceCrs(),
true, tolerance, context.
ellipsoid() );
135 feedback->
pushInfo( QObject::tr(
"Loading points…" ) );
160 attributes.insert( pointId, feat.
attributes() );
@ VectorLine
Vector line layers.
DistanceUnit
Units of distance.
@ Numeric
Accepts numeric fields.
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
The vertex_iterator class provides STL-style iterator for vertices.
Qgis::DistanceUnit mapUnits
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which provide features via a getFeatures method.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const =0
Returns an iterator for the features in the source.
virtual long long featureCount() const =0
Returns the number of features contained in the source, or -1 if the feature count is unknown.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
Strategy for calculating edge cost based on its length.
Strategy for calculating edge cost based on travel time.
A class to represent a 2D point.
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QString ellipsoid() const
Returns the ellipsoid to use for distance and area calculations.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsCoordinateReferenceSystem crs
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
Determine making the graph from vector line layer.
Direction
Edge direction Edge can be one-way with direct flow (one can move only from the start point to the en...