24using namespace Qt::StringLiterals;
28QString QgsPolygonizeAlgorithm::name()
const
30 return u
"polygonize"_s;
33QString QgsPolygonizeAlgorithm::displayName()
const
35 return QObject::tr(
"Polygonize" );
38QString QgsPolygonizeAlgorithm::shortHelpString()
const
40 return QObject::tr(
"This algorithm creates a polygon layer from the input lines layer." );
43QString QgsPolygonizeAlgorithm::shortDescription()
const
45 return QObject::tr(
"Creates a polygon layer from the input lines layer." );
48QStringList QgsPolygonizeAlgorithm::tags()
const
50 return QObject::tr(
"create,lines,polygons,convert" ).split(
',' );
53QString QgsPolygonizeAlgorithm::group()
const
55 return QObject::tr(
"Vector geometry" );
58QString QgsPolygonizeAlgorithm::groupId()
const
60 return u
"vectorgeometry"_s;
63void QgsPolygonizeAlgorithm::initAlgorithm(
const QVariantMap & )
71QgsPolygonizeAlgorithm *QgsPolygonizeAlgorithm::createInstance()
const
73 return new QgsPolygonizeAlgorithm();
78 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, u
"INPUT"_s, context ) );
83 if ( parameterAsBoolean( parameters, u
"KEEP_FIELDS"_s, context ) )
84 fields = source->fields();
87 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, fields,
Qgis::WkbType::Polygon, source->sourceCrs() ) );
93 feedback->
pushInfo( QObject::tr(
"Collecting lines…" ) );
95 double step = source->featureCount() > 0 ? 40.0 / source->featureCount() : 1;
98 QVector<QgsGeometry> linesList;
99 linesList.reserve( source->featureCount() );
112 feedback->
pushInfo( QObject::tr(
"Noding lines…" ) );
115 return QVariantMap();
118 feedback->
pushInfo( QObject::tr(
"Polygonizing…" ) );
121 feedback->
reportError( QObject::tr(
"No polygons were created." ) );
128 const int numGeometries = collection ? collection->
numGeometries() : 1;
129 step = numGeometries > 0 ? 50.0 / numGeometries : 1;
149 outputs.insert( u
"OUTPUT"_s, dest );
150 outputs.insert( u
"NUM_POLYGONS"_s, polygonCount );
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
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.
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.
A geometry is the spatial representation of a feature.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
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...
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
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.
T qgsgeometry_cast(QgsAbstractGeometry *geom)