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 mRasterProvider.reset( layer->dataProvider()->clone() );
97 if ( !mRasterProvider )
105 if ( !mCreatedTransform )
107 mCreatedTransform =
true;
127 double nodata = mNoData;
128 if ( mDynamicNoData )
131 double scale = mScale;
135 double offset = mOffset;
136 if ( mDynamicOffset )
139 prepareGeometry( geometry, nodata );
151 t = mTransform.transform( p );
153 val = mRasterProvider->sample( t, mBand, &ok );
164 feedback->
reportError( QObject::tr(
"Transform error while reprojecting feature {}" ).arg( f.
id() ) );
167 return drapeVertex( p, val );
181QString QgsDrapeToZAlgorithm::name()
const
183 return QStringLiteral(
"setzfromraster" );
186QString QgsDrapeToZAlgorithm::displayName()
const
188 return QObject::tr(
"Drape (set Z value from raster)" );
191QStringList QgsDrapeToZAlgorithm::tags()
const
193 return QObject::tr(
"3d,vertex,vertices,elevation,height,sample,dem,update,feature" ).split(
',' );
196QString QgsDrapeToZAlgorithm::shortHelpString()
const
198 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." )
199 + QStringLiteral(
"\n\n" )
200 + QObject::tr(
"The raster values can optionally be scaled by a preset amount and an offset can be algebraically added." );
203QString QgsDrapeToZAlgorithm::shortDescription()
const
205 return QObject::tr(
"Sets the z value for vertices to values sampled from a raster layer." );
208QgsDrapeToZAlgorithm *QgsDrapeToZAlgorithm::createInstance()
const
210 return new QgsDrapeToZAlgorithm();
213bool QgsDrapeToZAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
215 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
219 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
230void QgsDrapeToZAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
235QgsPoint QgsDrapeToZAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const
244QString QgsDrapeToMAlgorithm::name()
const
246 return QStringLiteral(
"setmfromraster" );
249QString QgsDrapeToMAlgorithm::displayName()
const
251 return QObject::tr(
"Set M value from raster" );
254QStringList QgsDrapeToMAlgorithm::tags()
const
256 return QObject::tr(
"drape,vertex,vertices,sample,dem,update,feature,measure" ).split(
',' );
259QString QgsDrapeToMAlgorithm::shortHelpString()
const
261 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." )
262 + QStringLiteral(
"\n\n" )
263 + QObject::tr(
"The raster values can optionally be scaled by a preset amount and an offset can be algebraically added." );
266QString QgsDrapeToMAlgorithm::shortDescription()
const
268 return QObject::tr(
"Sets the M value for vertices to values sampled from a raster layer." );
271QgsDrapeToMAlgorithm *QgsDrapeToMAlgorithm::createInstance()
const
273 return new QgsDrapeToMAlgorithm();
276bool QgsDrapeToMAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const
278 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
282 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
293void QgsDrapeToMAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
298QgsPoint 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