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 QObject::tr(
"Raster layer" ) ) );
44 QObject::tr(
"Band number" ), 1, QStringLiteral(
"RASTER" ) ) );
47 std::unique_ptr< QgsProcessingParameterNumber > nodata = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"NODATA" ),
50 nodata->setIsDynamic(
true );
52 nodata->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
53 addParameter( nodata.release() );
56 scaleParam->setIsDynamic(
true );
58 scaleParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
59 addParameter( scaleParam.release() );
62 offsetParam->setIsDynamic(
true );
64 offsetParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
65 addParameter( offsetParam.release() );
70 mNoData = parameterAsDouble( parameters, QStringLiteral(
"NODATA" ), context );
73 mNoDataProperty = parameters.value( QStringLiteral(
"NODATA" ) ).value<
QgsProperty >();
75 mScale = parameterAsDouble( parameters, QStringLiteral(
"SCALE" ), context );
78 mScaleProperty = parameters.value( QStringLiteral(
"SCALE" ) ).value<
QgsProperty >();
80 mOffset = parameterAsDouble( parameters, QStringLiteral(
"OFFSET" ), context );
83 mOffsetProperty = parameters.value( QStringLiteral(
"OFFSET" ) ).value<
QgsProperty >();
85 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"RASTER" ), context );
90 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
91 if ( mBand < 1 || mBand > layer->bandCount() )
92 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand )
93 .arg( layer->bandCount() ) );
94 mRasterExtent = layer->extent();
96 std::unique_ptr< QgsRasterInterface > provider( layer->dataProvider()->clone() );
101 mRasterProvider.reset( dp );
109 if ( !mCreatedTransform )
111 mCreatedTransform =
true;
131 double nodata = mNoData;
132 if ( mDynamicNoData )
135 double scale = mScale;
139 double offset = mOffset;
140 if ( mDynamicOffset )
143 prepareGeometry( geometry, nodata );
155 t = mTransform.transform( p );
157 val = mRasterProvider->sample( t, mBand, &ok );
168 feedback->
reportError( QObject::tr(
"Transform error while reprojecting feature {}" ).arg( f.
id() ) );
171 return drapeVertex( p, val );
185QString QgsDrapeToZAlgorithm::name()
const
187 return QStringLiteral(
"setzfromraster" );
190QString QgsDrapeToZAlgorithm::displayName()
const
192 return QObject::tr(
"Drape (set Z value from raster)" );
195QStringList QgsDrapeToZAlgorithm::tags()
const
197 return QObject::tr(
"3d,vertex,vertices,elevation,height,sample,dem,update,feature" ).split(
',' );
200QString QgsDrapeToZAlgorithm::shortHelpString()
const
202 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." )
203 + QStringLiteral(
"\n\n" )
204 + QObject::tr(
"The raster values can optionally be scaled by a preset amount and an offset can be algebraically added." );
207QString QgsDrapeToZAlgorithm::shortDescription()
const
209 return QObject::tr(
"Sets the z value for vertices to values sampled from a raster layer." );
212QgsDrapeToZAlgorithm *QgsDrapeToZAlgorithm::createInstance()
const
214 return new QgsDrapeToZAlgorithm();
217bool QgsDrapeToZAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
219 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
223 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
234void QgsDrapeToZAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
239QgsPoint QgsDrapeToZAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const
248QString QgsDrapeToMAlgorithm::name()
const
250 return QStringLiteral(
"setmfromraster" );
253QString QgsDrapeToMAlgorithm::displayName()
const
255 return QObject::tr(
"Set M value from raster" );
258QStringList QgsDrapeToMAlgorithm::tags()
const
260 return QObject::tr(
"drape,vertex,vertices,sample,dem,update,feature,measure" ).split(
',' );
263QString QgsDrapeToMAlgorithm::shortHelpString()
const
265 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." )
266 + QStringLiteral(
"\n\n" )
267 + QObject::tr(
"The raster values can optionally be scaled by a preset amount and an offset can be algebraically added." );
270QString QgsDrapeToMAlgorithm::shortDescription()
const
272 return QObject::tr(
"Sets the M value for vertices to values sampled from a raster layer." );
275QgsDrapeToMAlgorithm *QgsDrapeToMAlgorithm::createInstance()
const
277 return new QgsDrapeToMAlgorithm();
280bool QgsDrapeToMAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
282 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
286 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
297void QgsDrapeToMAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
302QgsPoint 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.
Base class for raster data providers.
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