27using namespace Qt::StringLiterals;
35QString QgsNetworkAnalysisAlgorithmBase::group()
const
37 return QObject::tr(
"Network analysis" );
40QString QgsNetworkAnalysisAlgorithmBase::groupId()
const
42 return u
"networkanalysis"_s;
56void QgsNetworkAnalysisAlgorithmBase::addCommonParams()
59 addParameter(
new QgsProcessingParameterEnum( u
"STRATEGY"_s, QObject::tr(
"Path type to calculate" ), QStringList() << QObject::tr(
"Shortest" ) << QObject::tr(
"Fastest" ),
false, 0 ) );
63 directionField->setHelp( QObject::tr(
"The attribute field specifying the direction of traffic flow for each segment." ) );
65 addParameter( directionField.release() );
67 auto forwardValue = std::make_unique<QgsProcessingParameterString>( u
"VALUE_FORWARD"_s, QObject::tr(
"Value for forward direction" ), QVariant(),
false,
true );
68 forwardValue->setHelp( QObject::tr(
"The string value in the direction field that indicates one-way traffic in the digitized direction." ) );
70 addParameter( forwardValue.release() );
72 auto backwardValue = std::make_unique<QgsProcessingParameterString>( u
"VALUE_BACKWARD"_s, QObject::tr(
"Value for backward direction" ), QVariant(),
false,
true );
73 backwardValue->setHelp( QObject::tr(
"The string value in the direction field that indicates one-way traffic opposite to the digitized direction." ) );
75 addParameter( backwardValue.release() );
77 auto bothValue = std::make_unique<QgsProcessingParameterString>( u
"VALUE_BOTH"_s, QObject::tr(
"Value for both directions" ), QVariant(),
false,
true );
78 bothValue->setHelp( QObject::tr(
"The string value in the direction field that indicates two-way traffic." ) );
80 addParameter( bothValue.release() );
82 auto directionValue = std::make_unique<
83 QgsProcessingParameterEnum>( u
"DEFAULT_DIRECTION"_s, QObject::tr(
"Default direction" ), QStringList() << QObject::tr(
"Forward direction" ) << QObject::tr(
"Backward direction" ) << QObject::tr(
"Both directions" ),
false, 2 );
85 addParameter( directionValue.release() );
89 addParameter( speedField.release() );
93 addParameter( speed.release() );
95 std::unique_ptr<QgsProcessingParameterNumber> tolerance = std::make_unique<QgsProcessingParameterDistance>( u
"TOLERANCE"_s, QObject::tr(
"Topology tolerance" ), 0, u
"INPUT"_s,
false, 0 );
97 addParameter( tolerance.release() );
104 mNetwork.reset( parameterAsSource( parameters, u
"INPUT"_s, context ) );
108 const int strategy = parameterAsInt( parameters, u
"STRATEGY"_s, context );
109 const QString directionFieldName = parameterAsString( parameters, u
"DIRECTION_FIELD"_s, context );
110 const QString forwardValue = parameterAsString( parameters, u
"VALUE_FORWARD"_s, context );
111 const QString backwardValue = parameterAsString( parameters, u
"VALUE_BACKWARD"_s, context );
112 const QString bothValue = parameterAsString( parameters, u
"VALUE_BOTH"_s, context );
114 const QString speedFieldName = parameterAsString( parameters, u
"SPEED_FIELD"_s, context );
115 const double defaultSpeed = parameterAsDouble( parameters, u
"DEFAULT_SPEED"_s, context );
116 const double tolerance = parameterAsDouble( parameters, u
"TOLERANCE"_s, context );
118 int directionField = -1;
119 if ( !directionFieldName.isEmpty() )
121 directionField = mNetwork->fields().lookupField( directionFieldName );
125 if ( !speedFieldName.isEmpty() )
127 speedField = mNetwork->fields().lookupField( speedFieldName );
130 mDirector =
new QgsVectorLayerDirector( mNetwork.get(), directionField, forwardValue, backwardValue, bothValue, defaultDirection );
137 mDirector->addStrategy(
new QgsNetworkSpeedStrategy( speedField, defaultSpeed, mMultiplier * 1000.0 / 3600.0 ) );
145 mBuilder = std::make_unique<QgsGraphBuilder>( mNetwork->sourceCrs(),
true, tolerance, context.
ellipsoid() );
148void QgsNetworkAnalysisAlgorithmBase::loadPoints(
152 feedback->
pushInfo( QObject::tr(
"Loading points…" ) );
179 attributes->insert( pointId, feat.
attributes() );
181 featureHash->insert( pointId, feat );
@ VectorLine
Vector line layers.
DistanceUnit
Units of distance.
@ Numeric
Accepts numeric fields.
@ RespectsEllipsoid
Algorithm respects the context's ellipsoid settings, and uses ellipsoidal based measurements.
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ 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 an 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.
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.
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.
void setFlags(Qgis::ProcessingParameterFlags flags)
Sets the flags associated with the parameter.
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.
Determines creating a graph from a 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...