22using namespace Qt::StringLiterals;
26QString QgsConcaveHullOfPolygonsAlgorithm::name()
const
28 return u
"tightconcavehullofpolygons"_s;
31QString QgsConcaveHullOfPolygonsAlgorithm::displayName()
const
33 return QObject::tr(
"Fill gaps between polygons" );
36QStringList QgsConcaveHullOfPolygonsAlgorithm::tags()
const
38 return QObject::tr(
"concave,hull,bounds,bounding,convex,multipolygons,boundary,fill,holes,between,space,tight,strict" ).split(
',' );
41QString QgsConcaveHullOfPolygonsAlgorithm::group()
const
43 return QObject::tr(
"Vector geometry" );
46QString QgsConcaveHullOfPolygonsAlgorithm::groupId()
const
48 return u
"vectorgeometry"_s;
51QString QgsConcaveHullOfPolygonsAlgorithm::outputName()
const
53 return QObject::tr(
"Tight concave hulls" );
56QString QgsConcaveHullOfPolygonsAlgorithm::shortHelpString()
const
58 return QObject::tr(
"This algorithm calculates a concave hull for each multi-polygon feature in an input layer." )
61 "Unlike the standard Concave Hull algorithm, a tight concave hull is a (possibly) non-convex polygon containing all the input polygons. The computed hull fills the gaps between the "
62 "polygons without intersecting their interiors. It strictly follows the outer boundaries of the input polygons, allowing you to fill gaps between them without distorting their original "
67 "It is particularly useful for cases such as generalizing groups of building outlines, creating 'district' polygons around blocks, or removing gaps and joining disjoint sets of polygons."
70 + QObject::tr(
"The algorithm works by creating a constrained Delaunay Triangulation of the space between the polygons and removing the longest outer edges until a target criterion is reached." )
72 + QObject::tr(
"The input geometry must be a valid Polygon or MultiPolygon (i.e., the individual polygons must not overlap)." );
75QString QgsConcaveHullOfPolygonsAlgorithm::shortDescription()
const
77 return QObject::tr(
"Constructs a tight concave hull for a set of polygons, filling gaps between them while strictly preserving their original outer boundaries." );
80QgsConcaveHullOfPolygonsAlgorithm *QgsConcaveHullOfPolygonsAlgorithm::createInstance()
const
82 return new QgsConcaveHullOfPolygonsAlgorithm();
85void QgsConcaveHullOfPolygonsAlgorithm::initParameters(
const QVariantMap & )
91 "Specifies the maximum edge length as a fraction of the difference between the longest and shortest edge lengths between the polygons. This normalizes the maximum edge length to be scale-free. "
92 "A value of 1 produces the convex hull; a value of 0 produces the original polygons."
95 addParameter( ratioParam.release() );
97 auto holesParam = std::make_unique<QgsProcessingParameterBoolean>( u
"HOLES"_s, QObject::tr(
"Allow holes" ),
true );
98 holesParam->setHelp( QObject::tr(
"Controls whether the computed concave hull is allowed to contain holes." ) );
99 addParameter( holesParam.release() );
102QList<int> QgsConcaveHullOfPolygonsAlgorithm::inputLayerTypes()
const
107QgsFields QgsConcaveHullOfPolygonsAlgorithm::outputFields(
const QgsFields &inputFields )
const
110 newFields.
append(
QgsField( u
"area"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
111 newFields.
append(
QgsField( u
"perimeter"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
117#if GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR < 11
118 throw QgsProcessingException( QObject::tr(
"This algorithm requires a QGIS build based on GEOS 3.11 or later" ) );
120 mPercentage = parameterAsDouble( parameters, u
"RATIO"_s, context );
121 mAllowHoles = parameterAsBool( parameters, u
"HOLES"_s, context );
132 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
146 feedback->
pushWarning( QObject::tr(
"Concave hull for feature %1 resulted in a linestring, ignoring" ).arg( f.
id() ) );
150 feedback->
pushWarning( QObject::tr(
"Concave hull for feature %1 resulted in a point, ignoring" ).arg( f.
id() ) );
153 attrs << QVariant() << QVariant();
@ VectorPolygon
Vector polygon layers.
@ Double
Double/float values.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
A geometry is the spatial representation of a feature.
QgsGeometry concaveHullOfPolygons(double lengthRatio, bool allowHoles=false, bool isTight=false, QgsFeedback *feedback=nullptr) const
Constructs a concave hull of a set of polygons, respecting the polygons as constraints.
QString lastError() const
Returns an error string referring to the last error encountered either when this geometry was created...
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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 pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
static QgsFields combineFields(const QgsFields &fieldsA, const QgsFields &fieldsB, const QString &fieldsBPrefix=QString())
Combines two field lists, avoiding duplicate field names (in a case-insensitive manner).
QList< QgsFeature > QgsFeatureList