24using namespace Qt::StringLiterals;
28QString QgsConcaveHullByFeatureAlgorithm::name()
const
30 return u
"concavehullbyfeature"_s;
33QString QgsConcaveHullByFeatureAlgorithm::displayName()
const
35 return QObject::tr(
"Concave hull (by feature)" );
38QStringList QgsConcaveHullByFeatureAlgorithm::tags()
const
40 return QObject::tr(
"concave,hull,bounds,bounding,convex" ).split(
',' );
43QString QgsConcaveHullByFeatureAlgorithm::group()
const
45 return QObject::tr(
"Vector geometry" );
48QString QgsConcaveHullByFeatureAlgorithm::groupId()
const
50 return u
"vectorgeometry"_s;
53QString QgsConcaveHullByFeatureAlgorithm::outputName()
const
55 return QObject::tr(
"Concave hulls" );
58QString QgsConcaveHullByFeatureAlgorithm::shortHelpString()
const
60 return QObject::tr(
"This algorithm calculates the concave hull for each feature in an input layer." )
62 + QObject::tr(
"For point and line layers, a concave hull is a polygon which contains all the vertices of the input geometries, but is a better approximation than the convex hull to the area occupied by the input." )
65 "When the input is a polygon layer, the algorithm operates differently: it computes a concave hull that respects the interior of the input polygons. The concave hull does not intersect "
66 "the polygon interiors. The computed hull also fills the empty space between the polygons within a multi-polygon feature."
69 + QObject::tr(
"See the 'Concave hull (by layer)' algorithm for a concave hull calculation which covers the whole layer or grouped subsets of features." );
72QString QgsConcaveHullByFeatureAlgorithm::shortDescription()
const
74 return QObject::tr(
"Calculates the concave hull for each feature in an input layer." );
77QgsConcaveHullByFeatureAlgorithm *QgsConcaveHullByFeatureAlgorithm::createInstance()
const
79 return new QgsConcaveHullByFeatureAlgorithm();
82void QgsConcaveHullByFeatureAlgorithm::initParameters(
const QVariantMap & )
88 "Controls the concaveness of the computed hull. A value of 1 produces the convex hull, while a value closer to 0 produces a highly concave hull. For point and line layers, this value "
89 "represents the target percentage of the convex hull area. For polygon layers, it specifies the maximum edge length as a fraction of the difference between the longest and shortest edge "
90 "lengths in the empty space between polygons."
93 addParameter( alphaParam.release() );
95 auto holesParam = std::make_unique<QgsProcessingParameterBoolean>( u
"HOLES"_s, QObject::tr(
"Allow holes" ),
true );
96 holesParam->setHelp( QObject::tr(
"Controls whether the computed concave hull is allowed to contain holes." ) );
97 addParameter( holesParam.release() );
100QList<int> QgsConcaveHullByFeatureAlgorithm::inputLayerTypes()
const
105QgsFields QgsConcaveHullByFeatureAlgorithm::outputFields(
const QgsFields &inputFields )
const
108 newFields.
append(
QgsField( u
"area"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
109 newFields.
append(
QgsField( u
"perimeter"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
115#if GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR < 11
116 throw QgsProcessingException( QObject::tr(
"This algorithm requires a QGIS build based on GEOS 3.11 or later" ) );
118 mPercentage = parameterAsDouble( parameters, u
"ALPHA"_s, context );
119 mAllowHoles = parameterAsBool( parameters, u
"HOLES"_s, context );
135 feedback->
reportError( QObject::tr(
"Cannot calculate concave hull for a single point feature (%1) (try 'Concave hull (by layer)' algorithm instead)." ).arg( f.
id() ) );
141 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
149 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
156 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
171 feedback->
pushWarning( QObject::tr(
"Concave hull for feature %1 resulted in a linestring, ignoring" ).arg( f.
id() ) );
175 feedback->
pushWarning( QObject::tr(
"Concave hull for feature %1 resulted in a point, ignoring" ).arg( f.
id() ) );
178 attrs << QVariant() << QVariant();
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ Double
Double/float values.
Abstract base class for all geometries.
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.
void clearGeometry()
Removes any geometry associated with the feature.
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.
int numGeometries() const
Returns the number of geometries within the collection.
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.
QgsGeometry concaveHull(double targetPercent, bool allowHoles=false, QgsFeedback *feedback=nullptr) const
Returns a possibly concave polygon that contains all the points in the geometry.
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).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QList< QgsFeature > QgsFeatureList