QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
network
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
16
#include "
qgsnetworkspeedstrategy.h
"
17
18
QgsNetworkSpeedStrategy::QgsNetworkSpeedStrategy
(
int
attributeId,
double
defaultValue,
double
toMetricFactor )
19
: mAttributeId( attributeId )
20
, mDefaultValue( defaultValue )
21
, mToMetricFactor( toMetricFactor )
22
{}
23
24
QVariant
QgsNetworkSpeedStrategy::cost
(
double
distance,
const
QgsFeature
&f )
const
25
{
26
double
speed = mDefaultValue;
27
const
QgsAttributes
attrs = f.
attributes
();
28
if
( mAttributeId >= 0 && mAttributeId < attrs.count() )
29
{
30
const
QVariant value = attrs.at( mAttributeId );
31
if
( !
QgsVariantUtils::isNull
( value ) )
32
{
33
speed = attrs.at( mAttributeId ).toDouble();
34
if
( speed < 0 )
35
speed = mDefaultValue;
36
}
37
}
38
39
return
distance / ( speed * mToMetricFactor );
40
}
41
42
QSet<int>
QgsNetworkSpeedStrategy::requiredAttributes
()
const
43
{
44
QSet<int> l;
45
if
( mAttributeId >= 0 )
46
l.insert( mAttributeId );
47
return
l;
48
}
QgsAttributes
A vector of attributes.
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:60
QgsFeature::attributes
QgsAttributes attributes
Definition
qgsfeature.h:64
QgsNetworkSpeedStrategy::cost
QVariant cost(double distance, const QgsFeature &f) const override
Returns edge cost.
Definition
qgsnetworkspeedstrategy.cpp:24
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:42
QgsVariantUtils::isNull
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Definition
qgsvariantutils.cpp:176
qgsnetworkspeedstrategy.h
Generated on
for QGIS API Documentation by
1.17.0