26 QString QgsSumLineLengthAlgorithm::name()
const 28 return QStringLiteral(
"sumlinelengths" );
31 QString QgsSumLineLengthAlgorithm::displayName()
const 33 return QObject::tr(
"Sum line lengths" );
36 QStringList QgsSumLineLengthAlgorithm::tags()
const 38 return QObject::tr(
"line,intersects,intersecting,sum,length,count" ).split(
',' );
41 QString QgsSumLineLengthAlgorithm::svgIconPath()
const 46 QIcon QgsSumLineLengthAlgorithm::icon()
const 51 QString QgsSumLineLengthAlgorithm::group()
const 53 return QObject::tr(
"Vector analysis" );
56 QString QgsSumLineLengthAlgorithm::groupId()
const 58 return QStringLiteral(
"vectoranalysis" );
61 QString QgsSumLineLengthAlgorithm::shortHelpString()
const 63 return QObject::tr(
"This algorithm takes a polygon layer and a line layer and " 64 "measures the total length of lines and the total number of " 65 "them that cross each polygon.\n\n" 66 "The resulting layer has the same features as the input polygon " 67 "layer, but with two additional attributes containing the length " 68 "and count of the lines across each polygon. The names of these " 69 "two fields can be configured in the algorithm parameters." );
72 QgsSumLineLengthAlgorithm *QgsSumLineLengthAlgorithm::createInstance()
const 74 return new QgsSumLineLengthAlgorithm();
77 QList<int> QgsSumLineLengthAlgorithm::inputLayerTypes()
const 93 QString QgsSumLineLengthAlgorithm::inputParameterName()
const 95 return QStringLiteral(
"POLYGONS" );
98 QString QgsSumLineLengthAlgorithm::inputParameterDescription()
const 100 return QObject::tr(
"Polygons" );
103 QString QgsSumLineLengthAlgorithm::outputName()
const 105 return QObject::tr(
"Line length" );
108 void QgsSumLineLengthAlgorithm::initParameters(
const QVariantMap & )
113 QObject::tr(
"Lines length field name" ), QStringLiteral(
"LENGTH" ) ) );
115 QObject::tr(
"Lines count field name" ), QStringLiteral(
"COUNT" ) ) );
120 mLengthFieldName = parameterAsString( parameters, QStringLiteral(
"LEN_FIELD" ), context );
121 mCountFieldName = parameterAsString( parameters, QStringLiteral(
"COUNT_FIELD" ), context );
123 mLinesSource.reset( parameterAsSource( parameters, QStringLiteral(
"LINES" ), context ) );
128 feedback->
reportError( QObject::tr(
"No spatial index exists for lines layer, performance will be severely degraded" ) );
139 QgsFields QgsSumLineLengthAlgorithm::outputFields(
const QgsFields &inputFields )
const 142 mLengthFieldIndex = inputFields.
lookupField( mLengthFieldName );
143 if ( mLengthFieldIndex < 0 )
144 outFields.
append(
QgsField( mLengthFieldName, QVariant::Double ) );
146 mCountFieldIndex = inputFields.
lookupField( mCountFieldName );
147 if ( mCountFieldIndex < 0 )
148 outFields.
append(
QgsField( mCountFieldName, QVariant::Double ) );
160 if ( mLengthFieldIndex < 0 )
163 attrs[mLengthFieldIndex] = 0;
165 if ( mCountFieldIndex < 0 )
168 attrs[mCountFieldIndex] = 0;
171 return QList< QgsFeature > () << outputFeature;
177 engine->prepareGeometry();
195 length += mDa.measureLength( outGeom );
201 if ( mLengthFieldIndex < 0 )
202 attrs.append( length );
204 attrs[mLengthFieldIndex] = length;
206 if ( mCountFieldIndex < 0 )
207 attrs.append( count );
209 attrs[mCountFieldIndex] = count;
212 return QList< QgsFeature >() << outputFeature;
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Wrapper for iterator of features from vector data provider or vector layer.
No spatial index exists for the source.
Base class for providing feedback from a processing algorithm.
QList< QgsFeature > QgsFeatureList
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
This class represents a coordinate reference system (CRS).
SourceType
Data source types enum.
const QgsCoordinateReferenceSystem & outputCrs
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
bool nextFeature(QgsFeature &f)
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.