23QString QgsPolygonizeAlgorithm::name()
const
25 return QStringLiteral(
"polygonize" );
28QString QgsPolygonizeAlgorithm::displayName()
const
30 return QObject::tr(
"Polygonize" );
33QString QgsPolygonizeAlgorithm::shortHelpString()
const
35 return QObject::tr(
"Creates a polygon layer from the input lines layer." );
38QStringList QgsPolygonizeAlgorithm::tags()
const
40 return QObject::tr(
"create,lines,polygons,convert" ).split(
',' );
43QString QgsPolygonizeAlgorithm::group()
const
45 return QObject::tr(
"Vector geometry" );
48QString QgsPolygonizeAlgorithm::groupId()
const
50 return QStringLiteral(
"vectorgeometry" );
53void QgsPolygonizeAlgorithm::initAlgorithm(
const QVariantMap & )
56 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"KEEP_FIELDS" ), QObject::tr(
"Keep table structure of line layer" ),
false ) );
61QgsPolygonizeAlgorithm *QgsPolygonizeAlgorithm::createInstance()
const
63 return new QgsPolygonizeAlgorithm();
68 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
73 if ( parameterAsBoolean( parameters, QStringLiteral(
"KEEP_FIELDS" ), context ) )
74 fields = source->fields();
77 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, dest, fields,
Qgis::WkbType::Polygon, source->sourceCrs() ) );
83 feedback->
pushInfo( QObject::tr(
"Collecting lines…" ) );
85 double step = source->featureCount() > 0 ? 40.0 / source->featureCount() : 1;
88 QVector<QgsGeometry> linesList;
89 linesList.reserve( source->featureCount() );
102 feedback->
pushInfo( QObject::tr(
"Noding lines…" ) );
105 return QVariantMap();
108 feedback->
pushInfo( QObject::tr(
"Polygonizing…" ) );
111 feedback->
reportError( QObject::tr(
"No polygons were created." ) );
119 for (
int part = 0; part < collection->
numGeometries(); ++part )
136 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );
137 outputs.insert( QStringLiteral(
"NUM_POLYGONS" ), polygonCount );
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
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.
This class wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
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.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Container of fields for a vector layer.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
A geometry is the spatial representation of a feature.
static QgsGeometry polygonize(const QVector< QgsGeometry > &geometries)
Creates a GeometryCollection geometry containing possible polygons formed from the constituent linewo...
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries, const QgsGeometryParameters ¶meters=QgsGeometryParameters())
Compute the unary union on a list of geometries.
Contains information about the context in which a processing algorithm is executed.
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.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
A numeric output for processing algorithms.
A boolean parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.