24QString QgsDrapeAlgorithmBase::group()
const
26 return QObject::tr(
"Vector geometry" );
29QString QgsDrapeAlgorithmBase::groupId()
const
31 return QStringLiteral(
"vectorgeometry" );
34QString QgsDrapeAlgorithmBase::outputName()
const
36 return QObject::tr(
"Draped" );
39void QgsDrapeAlgorithmBase::initParameters(
const QVariantMap & )
42 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"BAND" ), QObject::tr(
"Band number" ), 1, QStringLiteral(
"RASTER" ) ) );
45 std::unique_ptr<QgsProcessingParameterNumber> nodata = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"NODATA" ), QObject::tr(
"Value for NoData or non-intersecting vertices" ),
Qgis::ProcessingNumberParameterType::Double, 0.0 );
46 nodata->setIsDynamic(
true );
48 nodata->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
49 addParameter( nodata.release() );
52 scaleParam->setIsDynamic(
true );
54 scaleParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
55 addParameter( scaleParam.release() );
58 offsetParam->setIsDynamic(
true );
60 offsetParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
61 addParameter( offsetParam.release() );
66 mNoData = parameterAsDouble( parameters, QStringLiteral(
"NODATA" ), context );
69 mNoDataProperty = parameters.value( QStringLiteral(
"NODATA" ) ).value<
QgsProperty>();
71 mScale = parameterAsDouble( parameters, QStringLiteral(
"SCALE" ), context );
74 mScaleProperty = parameters.value( QStringLiteral(
"SCALE" ) ).value<
QgsProperty>();
76 mOffset = parameterAsDouble( parameters, QStringLiteral(
"OFFSET" ), context );
79 mOffsetProperty = parameters.value( QStringLiteral(
"OFFSET" ) ).value<
QgsProperty>();
81 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"RASTER" ), context );
86 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
87 if ( mBand < 1 || mBand > layer->bandCount() )
88 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( layer->bandCount() ) );
89 mRasterExtent = layer->extent();
91 mRasterProvider.reset( layer->dataProvider()->clone() );
92 if ( !mRasterProvider )
100 if ( !mCreatedTransform )
102 mCreatedTransform =
true;
122 double nodata = mNoData;
123 if ( mDynamicNoData )
126 double scale = mScale;
130 double offset = mOffset;
131 if ( mDynamicOffset )
134 prepareGeometry( geometry, nodata );
145 t = mTransform.transform( p );
147 val = mRasterProvider->sample( t, mBand, &ok );
158 feedback->
reportError( QObject::tr(
"Transform error while reprojecting feature {}" ).arg( f.
id() ) );
161 return drapeVertex( p, val );
175QString QgsDrapeToZAlgorithm::name()
const
177 return QStringLiteral(
"setzfromraster" );
180QString QgsDrapeToZAlgorithm::displayName()
const
182 return QObject::tr(
"Drape (set Z value from raster)" );
185QStringList QgsDrapeToZAlgorithm::tags()
const
187 return QObject::tr(
"3d,vertex,vertices,elevation,height,sample,dem,update,feature" ).split(
',' );
190QString QgsDrapeToZAlgorithm::shortHelpString()
const
192 return QObject::tr(
"This algorithm sets the z value of every vertex in the feature geometry to a value sampled from a band within a raster layer." )
193 + QStringLiteral(
"\n\n" )
194 + QObject::tr(
"The raster values can optionally be scaled by a preset amount and an offset can be algebraically added." );
197QString QgsDrapeToZAlgorithm::shortDescription()
const
199 return QObject::tr(
"Sets the z value for vertices to values sampled from a raster layer." );
202QgsDrapeToZAlgorithm *QgsDrapeToZAlgorithm::createInstance()
const
204 return new QgsDrapeToZAlgorithm();
207bool QgsDrapeToZAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
209 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
213 if ( !QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
224void QgsDrapeToZAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
229QgsPoint QgsDrapeToZAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const
238QString QgsDrapeToMAlgorithm::name()
const
240 return QStringLiteral(
"setmfromraster" );
243QString QgsDrapeToMAlgorithm::displayName()
const
245 return QObject::tr(
"Set M value from raster" );
248QStringList QgsDrapeToMAlgorithm::tags()
const
250 return QObject::tr(
"drape,vertex,vertices,sample,dem,update,feature,measure" ).split(
',' );
253QString QgsDrapeToMAlgorithm::shortHelpString()
const
255 return QObject::tr(
"This algorithm sets the M value for every vertex in the feature geometry to a value sampled from a band within a raster layer." )
256 + QStringLiteral(
"\n\n" )
257 + QObject::tr(
"The raster values can optionally be scaled by a preset amount and an offset can be algebraically added." );
260QString QgsDrapeToMAlgorithm::shortDescription()
const
262 return QObject::tr(
"Sets the M value for vertices to values sampled from a raster layer." );
265QgsDrapeToMAlgorithm *QgsDrapeToMAlgorithm::createInstance()
const
267 return new QgsDrapeToMAlgorithm();
270bool QgsDrapeToMAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
272 const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( l );
276 if ( !QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
287void QgsDrapeToMAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
292QgsPoint QgsDrapeToMAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const
WkbType
The WKB type describes the number of dimensions a geometry has.
@ Reverse
Reverse/inverse transform (from destination to source)
@ Double
Double/float values.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
Custom exception class for Coordinate Reference System related exceptions.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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.
bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
Base class for all map layer types.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
Contains information about the context in which a processing algorithm is executed.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform 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.
A raster band parameter for Processing algorithms.
A raster layer parameter for processing algorithms.
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.
double valueAsDouble(const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a double.
Represents a raster layer.
A rectangle specified with double values.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::WkbType wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
QList< QgsFeature > QgsFeatureList