25using namespace Qt::StringLiterals;
29QString QgsConcaveHullByFeatureAlgorithm::name()
const
31 return u
"concavehullbyfeature"_s;
34QString QgsConcaveHullByFeatureAlgorithm::displayName()
const
36 return QObject::tr(
"Concave hull (by feature)" );
39QStringList QgsConcaveHullByFeatureAlgorithm::tags()
const
41 return QObject::tr(
"concave,hull,bounds,bounding,convex" ).split(
',' );
44QString QgsConcaveHullByFeatureAlgorithm::group()
const
46 return QObject::tr(
"Vector geometry" );
49QString QgsConcaveHullByFeatureAlgorithm::groupId()
const
51 return u
"vectorgeometry"_s;
54QString QgsConcaveHullByFeatureAlgorithm::outputName()
const
56 return QObject::tr(
"Concave hulls" );
59QString QgsConcaveHullByFeatureAlgorithm::shortHelpString()
const
61 return QObject::tr(
"This algorithm calculates the concave hull for each feature in an input layer." )
63 + 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." )
66 "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 "
67 "the polygon interiors. The computed hull also fills the empty space between the polygons within a multi-polygon feature."
70 + QObject::tr(
"See the 'Concave hull (by layer)' algorithm for a concave hull calculation which covers the whole layer or grouped subsets of features." );
73QString QgsConcaveHullByFeatureAlgorithm::shortDescription()
const
75 return QObject::tr(
"Calculates the concave hull for each feature in an input layer." );
78QgsConcaveHullByFeatureAlgorithm *QgsConcaveHullByFeatureAlgorithm::createInstance()
const
80 return new QgsConcaveHullByFeatureAlgorithm();
83void QgsConcaveHullByFeatureAlgorithm::initParameters(
const QVariantMap & )
89 "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 "
90 "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 "
91 "lengths in the empty space between polygons."
94 addParameter( alphaParam.release() );
96 auto holesParam = std::make_unique<QgsProcessingParameterBoolean>( u
"HOLES"_s, QObject::tr(
"Allow holes" ),
true );
97 holesParam->setHelp( QObject::tr(
"Controls whether the computed concave hull is allowed to contain holes." ) );
98 addParameter( holesParam.release() );
101QList<int> QgsConcaveHullByFeatureAlgorithm::inputLayerTypes()
const
106QgsFields QgsConcaveHullByFeatureAlgorithm::outputFields(
const QgsFields &inputFields )
const
109 newFields.
append(
QgsField( u
"area"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
110 newFields.
append(
QgsField( u
"perimeter"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
116#if GEOS_VERSION_NUM < GEOS_COMPUTE_VERSION( 3, 11, 0 )
117 throw QgsProcessingException( QObject::tr(
"This algorithm requires a QGIS build based on GEOS 3.11 or later" ) );
119 mPercentage = parameterAsDouble( parameters, u
"ALPHA"_s, context );
120 mAllowHoles = parameterAsBool( parameters, u
"HOLES"_s, context );
126 QGS_MARK_ALGORITHM_SOURCE
129 if ( f.hasGeometry() )
138 feedback->
reportError( QObject::tr(
"Cannot calculate concave hull for a single point feature (%1) (try 'Concave hull (by layer)' algorithm instead)." ).arg( f.id() ) );
143 outputGeometry = f.geometry().
concaveHull( mPercentage, mAllowHoles );
144 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
146 f.setGeometry( outputGeometry );
151 outputGeometry = f.geometry().
concaveHull( mPercentage, mAllowHoles );
152 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
154 f.setGeometry( outputGeometry );
159 if ( outputGeometry.
isNull() && !outputGeometry.
lastError().isEmpty() )
161 f.setGeometry( outputGeometry );
168 f.setAttributes( attrs );
174 feedback->
pushWarning( QObject::tr(
"Concave hull for feature %1 resulted in a linestring, ignoring" ).arg( f.id() ) );
178 feedback->
pushWarning( QObject::tr(
"Concave hull for feature %1 resulted in a point, ignoring" ).arg( f.id() ) );
181 attrs << QVariant() << QVariant();
182 f.setAttributes( attrs );
@ 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...
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