26using namespace Qt::StringLiterals;
34QString QgsExtrudeAlgorithm::name()
const
39QString QgsExtrudeAlgorithm::displayName()
const
41 return QObject::tr(
"Extrude" );
44QStringList QgsExtrudeAlgorithm::tags()
const
46 return QObject::tr(
"extrude,extrusion,3d,volume" ).split(
',' );
49QString QgsExtrudeAlgorithm::group()
const
51 return QObject::tr(
"Vector geometry" );
54QString QgsExtrudeAlgorithm::groupId()
const
56 return u
"vectorgeometry"_s;
59QString QgsExtrudeAlgorithm::shortHelpString()
const
62 "This algorithm generates 3D geometries by extruding 2D polygon features along a specified direction.\n\n"
63 "Each feature is displaced according to the X, Y, and Z extrusion parameters: "
64 "X and Y control the horizontal displacement, while Z controls the vertical elevation. "
65 "Setting only the Z parameter produces vertical extrusions, whereas combining X, Y, and Z "
66 "allows the creation of non-vertical extrusions. Negative values are supported, enabling extrusions "
67 "in the opposite direction.\n\n"
68 "If the input features already carry Z values, those values are preserved and used as the base "
69 "elevation of the extruded geometry.\n\n"
70 "For MultiPolygon geometries, each part is extruded separately, producing one output feature per part.\n\n"
71 "Output geometries are of type PolyhedralSurfaceZ, representing the extruded surface of each input feature."
75QString QgsExtrudeAlgorithm::shortDescription()
const
77 return QObject::tr(
"Generates a 3D extrusion from 2D polygon features." );
80QgsExtrudeAlgorithm *QgsExtrudeAlgorithm::createInstance()
const
82 return new QgsExtrudeAlgorithm();
85QList<int> QgsExtrudeAlgorithm::inputLayerTypes()
const
90QString QgsExtrudeAlgorithm::outputName()
const
92 return QObject::tr(
"Extrusion" );
102 Q_UNUSED( inputWkbType )
106void QgsExtrudeAlgorithm::initParameters(
const QVariantMap & )
109 xExtrude->setIsDynamic(
true );
111 xExtrude->setDynamicLayerParameterName( u
"INPUT"_s );
112 addParameter( xExtrude.release() );
115 yExtrude->setIsDynamic(
true );
117 yExtrude->setDynamicLayerParameterName( u
"INPUT"_s );
118 addParameter( yExtrude.release() );
121 zExtrude->setIsDynamic(
true );
123 zExtrude->setDynamicLayerParameterName( u
"INPUT"_s );
124 addParameter( zExtrude.release() );
132 mExtrudeX = parameterAsDouble( parameters, u
"EXTRUDE_X"_s, context );
134 if ( mDynamicExtrudeX )
135 mExtrudeXProperty = parameters.value( u
"EXTRUDE_X"_s ).value<
QgsProperty>();
137 mExtrudeY = parameterAsDouble( parameters, u
"EXTRUDE_Y"_s, context );
139 if ( mDynamicExtrudeY )
140 mExtrudeYProperty = parameters.value( u
"EXTRUDE_Y"_s ).value<
QgsProperty>();
142 mExtrudeZ = parameterAsDouble( parameters, u
"EXTRUDE_Z"_s, context );
144 if ( mDynamicExtrudeZ )
145 mExtrudeZProperty = parameters.value( u
"EXTRUDE_Z"_s ).value<
QgsProperty>();
149 Q_UNUSED( parameters )
151 throw QgsProcessingException( QObject::tr(
"This processing algorithm requires a QGIS installation with SFCGAL support enabled. Please use a version of QGIS that includes SFCGAL." ) );
160 QgsSfcgalGeometry inputSfcgalGeometry( polygon );
161 if ( inputSfcgalGeometry.isEmpty() )
166 std::unique_ptr<QgsSfcgalGeometry> outputSfcgalGeometry = inputSfcgalGeometry.extrude( extrusion );
167 return QgsGeometry( outputSfcgalGeometry->asQgisGeometry() );
171 feedback->
reportError( QObject::tr(
"Cannot calculate extrusion for feature %1: %2" ).arg( featureId ).arg( exception.
what() ) );
185 double extrudeX = mExtrudeX;
186 if ( mDynamicExtrudeX )
188 extrudeX = mExtrudeXProperty.valueAsDouble( context.
expressionContext(), extrudeX );
191 double extrudeY = mExtrudeY;
192 if ( mDynamicExtrudeY )
194 extrudeY = mExtrudeYProperty.valueAsDouble( context.
expressionContext(), extrudeY );
197 double extrudeZ = mExtrudeZ;
198 if ( mDynamicExtrudeZ )
200 extrudeZ = mExtrudeZProperty.valueAsDouble( context.
expressionContext(), extrudeZ );
203 const QgsVector3D extrusion( extrudeX, extrudeY, extrudeZ );
213 std::optional<QgsGeometry> extruded = extrudePolygon( *partIt, extrusion, feature.
id(), feedback );
214 if ( extruded.has_value() )
219 outputFeatures << modifiedFeature;
225 std::optional<QgsGeometry> extruded = extrudePolygon( inputGeometry.
constGet(), extrusion, feature.
id(), feedback );
226 if ( extruded.has_value() )
230 outputFeatures << modifiedFeature;
234 return outputFeatures;
239 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.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ PolyhedralSurfaceZ
PolyhedralSurfaceZ.
@ Double
Double/float values.
Abstract base class for all geometries.
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.
A geometry is the spatial representation of a feature.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
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 bool isDynamic(const QVariantMap ¶meters, const QString &name)
Returns true if the parameter with matching name is a dynamic parameter, and must be evaluated once f...
Definition for a property.
@ Double
Double value (including negative values).
A store for object properties.
Custom exception class for SfCGAL related operations.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
QList< QgsFeature > QgsFeatureList
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features