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
90 mDa.setSourceCrs( mCrs, mTransformContext );
94 QString QgsSumLineLengthAlgorithm::inputParameterName()
const
96 return QStringLiteral(
"POLYGONS" );
99 QString QgsSumLineLengthAlgorithm::inputParameterDescription()
const
101 return QObject::tr(
"Polygons" );
104 QString QgsSumLineLengthAlgorithm::outputName()
const
106 return QObject::tr(
"Line length" );
109 void QgsSumLineLengthAlgorithm::initParameters(
const QVariantMap & )
114 QObject::tr(
"Lines length field name" ), QStringLiteral(
"LENGTH" ) ) );
116 QObject::tr(
"Lines count field name" ), QStringLiteral(
"COUNT" ) ) );
121 mLengthFieldName = parameterAsString( parameters, QStringLiteral(
"LEN_FIELD" ), context );
122 mCountFieldName = parameterAsString( parameters, QStringLiteral(
"COUNT_FIELD" ), context );
124 mLinesSource.reset( parameterAsSource( parameters, QStringLiteral(
"LINES" ), context ) );
129 feedback->
reportError( QObject::tr(
"No spatial index exists for lines layer, performance will be severely degraded" ) );
140 QgsFields QgsSumLineLengthAlgorithm::outputFields(
const QgsFields &inputFields )
const
143 mLengthFieldIndex = inputFields.
lookupField( mLengthFieldName );
144 if ( mLengthFieldIndex < 0 )
145 outFields.
append(
QgsField( mLengthFieldName, QVariant::Double ) );
147 mCountFieldIndex = inputFields.
lookupField( mCountFieldName );
148 if ( mCountFieldIndex < 0 )
149 outFields.
append(
QgsField( mCountFieldName, QVariant::Double ) );
161 if ( mLengthFieldIndex < 0 )
164 attrs[mLengthFieldIndex] = 0;
166 if ( mCountFieldIndex < 0 )
169 attrs[mCountFieldIndex] = 0;
172 return QList< QgsFeature > () << outputFeature;
178 engine->prepareGeometry();
196 length += mDa.measureLength( outGeom );
202 if ( mLengthFieldIndex < 0 )
203 attrs.append( length );
205 attrs[mLengthFieldIndex] = length;
207 if ( mCountFieldIndex < 0 )
208 attrs.append( count );
210 attrs[mCountFieldIndex] = count;
213 return QList< QgsFeature >() << outputFeature;