QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsnetworkspeedstrategy.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsspeedstrategy.h
3  --------------------------------------
4  Date : 2011-04-01
5  Copyright : (C) 2010 by Yakushev Sergey
6  Email : YakushevS <at> list.ru
7 ****************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
17 
18 QgsNetworkSpeedStrategy::QgsNetworkSpeedStrategy( int attributeId, double defaultValue, double toMetricFactor )
19 {
20  mAttributeId = attributeId;
21  mDefaultValue = defaultValue;
22  mToMetricFactor = toMetricFactor;
23 }
24 
25 QVariant QgsNetworkSpeedStrategy::cost( double distance, const QgsFeature &f ) const
26 {
27  const QgsAttributes attrs = f.attributes();
28 
29  if ( mAttributeId < 0 || mAttributeId >= attrs.count() )
30  return QVariant( distance / ( mDefaultValue * mToMetricFactor ) );
31 
32  const double val = distance / ( attrs.at( mAttributeId ).toDouble() * mToMetricFactor );
33  if ( val <= 0.0 )
34  return QVariant( distance / ( mDefaultValue / mToMetricFactor ) );
35 
36  return QVariant( val );
37 }
38 
40 {
41  QSet< int > l;
42  l.insert( mAttributeId );
43  return l;
44 }
qgsnetworkspeedstrategy.h
QgsNetworkSpeedStrategy::cost
QVariant cost(double distance, const QgsFeature &f) const override
Returns edge cost.
Definition: qgsnetworkspeedstrategy.cpp:25
QgsFeature::attributes
QgsAttributes attributes
Definition: qgsfeature.h:69
QgsNetworkSpeedStrategy::QgsNetworkSpeedStrategy
QgsNetworkSpeedStrategy(int attributeId, double defaultValue, double toMetricFactor)
Default constructor.
Definition: qgsnetworkspeedstrategy.cpp:18
QgsNetworkSpeedStrategy::requiredAttributes
QSet< int > requiredAttributes() const override
Returns a list of the source layer attributes needed for cost calculation.
Definition: qgsnetworkspeedstrategy.cpp:39
QgsAttributes
A vector of attributes. Mostly equal to QVector<QVariant>.
Definition: qgsattributes.h:57
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55