29QString QgsApproximateMedialAxisAlgorithm::name()
const
31 return QStringLiteral(
"approximatemedialaxis" );
34QString QgsApproximateMedialAxisAlgorithm::displayName()
const
36 return QObject::tr(
"Approximate medial axis" );
39QStringList QgsApproximateMedialAxisAlgorithm::tags()
const
41 return QObject::tr(
"medial,axis,create,lines,straight,skeleton" ).split(
',' );
44QString QgsApproximateMedialAxisAlgorithm::group()
const
46 return QObject::tr(
"Vector geometry" );
49QString QgsApproximateMedialAxisAlgorithm::groupId()
const
51 return QStringLiteral(
"vectorgeometry" );
54QString QgsApproximateMedialAxisAlgorithm::shortHelpString()
const
56 return QObject::tr(
"The Approximate Medial Axis algorithm generates a simplified skeleton of a shape by approximating its medial axis. \n\n"
57 "The output is a collection of lines that follow the central structure of the shape. The result is a thin, stable set "
58 "of curves that capture the main topology while ignoring noise.\n\n"
59 "This algorithm ignores the Z dimensions. If the geometry is 3D, the approximate medial axis will be calculated from "
60 "its 2D projection." );
63QString QgsApproximateMedialAxisAlgorithm::shortDescription()
const
65 return QObject::tr(
"Returns an approximate medial axis for a polygon layer input based on its straight skeleton." );
68QgsApproximateMedialAxisAlgorithm *QgsApproximateMedialAxisAlgorithm::createInstance()
const
70 return new QgsApproximateMedialAxisAlgorithm();
73QgsFields QgsApproximateMedialAxisAlgorithm::outputFields(
const QgsFields &inputFields )
const
76 newFields.
append(
QgsField( QStringLiteral(
"length" ), QMetaType::Type::Double, QString(), 20, 6 ) );
80QList<int> QgsApproximateMedialAxisAlgorithm::inputLayerTypes()
const
85QString QgsApproximateMedialAxisAlgorithm::outputName()
const
87 return QObject::tr(
"Medial axis" );
97 Q_UNUSED( inputWkbType )
103 Q_UNUSED( parameters )
110 throw QgsProcessingException( QObject::tr(
"This processing algorithm requires a QGIS installation with SFCGAL support enabled. Please use a version of QGIS that includes SFCGAL." ) );
120 if ( modifiedFeature.hasGeometry() )
123 QgsSfcgalGeometry inputSfcgalGeometry;
126 inputSfcgalGeometry = QgsSfcgalGeometry( modifiedFeature.geometry() );
128 catch (
const QgsSfcgalException &exception )
130 feedback->
reportError( QObject::tr(
"Cannot calculate approximate medial axis for feature %1: %2" ).arg( feature.
id() ).arg( exception.what() ) );
131 modifiedFeature.clearGeometry();
134 if ( !inputSfcgalGeometry.isEmpty() )
138 std::unique_ptr<QgsSfcgalGeometry> outputSfcgalGeometry = inputSfcgalGeometry.approximateMedialAxis();
139 outputGeometry =
QgsGeometry( outputSfcgalGeometry->asQgisGeometry() );
140 modifiedFeature.setGeometry( outputGeometry );
142 catch (
const QgsSfcgalException &medialAxisException )
144 feedback->
reportError( QObject::tr(
"Cannot calculate approximate medial axis for feature %1: %2" ).arg( feature.
id() ).arg( medialAxisException.what() ) );
148 if ( !outputGeometry.
isNull() )
152 modifiedFeature.setAttributes( attrs );
158 modifiedFeature.setAttributes( attrs );
165 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).
QList< QgsFeature > QgsFeatureList