25using namespace Qt::StringLiterals;
33QString QgsApproximateMedialAxisAlgorithm::name()
const
35 return u
"approximatemedialaxis"_s;
38QString QgsApproximateMedialAxisAlgorithm::displayName()
const
40 return QObject::tr(
"Approximate medial axis" );
43QStringList QgsApproximateMedialAxisAlgorithm::tags()
const
45 return QObject::tr(
"medial,axis,create,lines,straight,skeleton" ).split(
',' );
48QString QgsApproximateMedialAxisAlgorithm::group()
const
50 return QObject::tr(
"Vector geometry" );
53QString QgsApproximateMedialAxisAlgorithm::groupId()
const
55 return u
"vectorgeometry"_s;
58QString QgsApproximateMedialAxisAlgorithm::shortHelpString()
const
60 return QObject::tr(
"The Approximate Medial Axis algorithm generates a simplified skeleton of a shape by approximating its medial axis. \n\n"
61 "The output is a collection of lines that follow the central structure of the shape. The result is a thin, stable set "
62 "of curves that capture the main topology while ignoring noise.\n\n"
63 "This algorithm ignores the Z dimensions. If the geometry is 3D, the approximate medial axis will be calculated from "
64 "its 2D projection." );
67QString QgsApproximateMedialAxisAlgorithm::shortDescription()
const
69 return QObject::tr(
"Returns an approximate medial axis for a polygon layer input based on its straight skeleton." );
72QgsApproximateMedialAxisAlgorithm *QgsApproximateMedialAxisAlgorithm::createInstance()
const
74 return new QgsApproximateMedialAxisAlgorithm();
77QgsFields QgsApproximateMedialAxisAlgorithm::outputFields(
const QgsFields &inputFields )
const
80 newFields.
append(
QgsField( u
"length"_s, QMetaType::Type::Double, QString(), 20, 6 ) );
84QList<int> QgsApproximateMedialAxisAlgorithm::inputLayerTypes()
const
89QString QgsApproximateMedialAxisAlgorithm::outputName()
const
91 return QObject::tr(
"Medial axis" );
101 Q_UNUSED( inputWkbType )
107 Q_UNUSED( parameters )
114 throw QgsProcessingException( QObject::tr(
"This processing algorithm requires a QGIS installation with SFCGAL support enabled. Please use a version of QGIS that includes SFCGAL." ) );
124 if ( modifiedFeature.hasGeometry() )
127 QgsSfcgalGeometry inputSfcgalGeometry;
130 inputSfcgalGeometry = QgsSfcgalGeometry( modifiedFeature.geometry() );
134 feedback->
reportError( QObject::tr(
"Cannot calculate approximate medial axis for feature %1: %2" ).arg( feature.
id() ).arg( exception.
what() ) );
135 modifiedFeature.clearGeometry();
138 if ( !inputSfcgalGeometry.isEmpty() )
142 std::unique_ptr<QgsSfcgalGeometry> outputSfcgalGeometry = inputSfcgalGeometry.approximateMedialAxis();
143 outputGeometry =
QgsGeometry( outputSfcgalGeometry->asQgisGeometry() );
144 modifiedFeature.setGeometry( outputGeometry );
148 feedback->
reportError( QObject::tr(
"Cannot calculate approximate medial axis for feature %1: %2" ).arg( feature.
id() ).arg( medialAxisException.
what() ) );
152 if ( !outputGeometry.
isNull() )
156 modifiedFeature.setAttributes( attrs );
162 modifiedFeature.setAttributes( attrs );
169 throw QgsProcessingException( QObject::tr(
"This processing algorithm requires a QGIS installation with SFCGAL support enabled. Please use a version of QGIS that includes SFCGAL." ) );
ProcessingSourceType
Processing data source types.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ MultiLineString
MultiLineString.
virtual double length() const
Returns the planar, 2-dimensional length 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.
A geometry is the spatial representation of a feature.
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 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).
Custom exception class for SfCGAL related operations.
QList< QgsFeature > QgsFeatureList