24 QString QgsDrapeAlgorithmBase::group()
const 26 return QObject::tr(
"Vector geometry" );
29 QString QgsDrapeAlgorithmBase::groupId()
const 31 return QStringLiteral(
"vectorgeometry" );
34 QString QgsDrapeAlgorithmBase::outputName()
const 36 return QObject::tr(
"Updated" );
39 void QgsDrapeAlgorithmBase::initParameters(
const QVariantMap & )
42 QObject::tr(
"Raster layer" ) ) );
44 QObject::tr(
"Band number" ), 1, QStringLiteral(
"RASTER" ) ) );
47 std::unique_ptr< QgsProcessingParameterNumber > nodata = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"NODATA" ),
50 nodata->setIsDynamic(
true );
52 nodata->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
53 addParameter( nodata.release() );
55 auto scaleParam = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"SCALE" ), QObject::tr(
"Scale factor" ),
QgsProcessingParameterNumber::Double, 1.0,
false, 0.0 );
56 scaleParam->setIsDynamic(
true );
58 scaleParam->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
59 addParameter( scaleParam.release() );
64 mNoData = parameterAsDouble( parameters, QStringLiteral(
"NODATA" ), context );
67 mNoDataProperty = parameters.value( QStringLiteral(
"NODATA" ) ).value<
QgsProperty >();
69 mScale = parameterAsDouble( parameters, QStringLiteral(
"SCALE" ), context );
72 mScaleProperty = parameters.value( QStringLiteral(
"SCALE" ) ).value<
QgsProperty >();
74 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, QStringLiteral(
"RASTER" ), context );
79 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
80 if ( mBand < 1 || mBand > layer->bandCount() )
81 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand )
82 .arg( layer->bandCount() ) );
83 mRasterExtent = layer->extent();
85 std::unique_ptr< QgsRasterInterface > provider( layer->dataProvider()->clone() );
90 mRasterProvider.reset( dp );
98 if ( !mCreatedTransform )
100 mCreatedTransform =
true;
120 double nodata = mNoData;
121 if ( mDynamicNoData )
124 double scale = mScale;
128 prepareGeometry( geometry, nodata );
140 t = mTransform.transform( p );
142 val = mRasterProvider->sample( t, mBand, &ok );
150 feedback->
reportError( QObject::tr(
"Transform error while reprojecting feature {}" ).arg( f.
id() ) );
153 return drapeVertex( p, val );
167 QString QgsDrapeToZAlgorithm::name()
const 169 return QStringLiteral(
"setzfromraster" );
172 QString QgsDrapeToZAlgorithm::displayName()
const 174 return QObject::tr(
"Drape (set Z value from raster)" );
177 QStringList QgsDrapeToZAlgorithm::tags()
const 179 return QObject::tr(
"3d,vertex,vertices,elevation,height,sample,dem,update,feature" ).split(
',' );
182 QString QgsDrapeToZAlgorithm::shortHelpString()
const 184 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." )
185 + QStringLiteral(
"\n\n" )
186 + QObject::tr(
"The raster values can optionally be scaled by a preset amount." );
189 QString QgsDrapeToZAlgorithm::shortDescription()
const 191 return QObject::tr(
"Sets the z value for vertices to values sampled from a raster layer." );
194 QgsDrapeToZAlgorithm *QgsDrapeToZAlgorithm::createInstance()
const 196 return new QgsDrapeToZAlgorithm();
199 bool QgsDrapeToZAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const 205 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
216 void QgsDrapeToZAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const 221 QgsPoint QgsDrapeToZAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const 230 QString QgsDrapeToMAlgorithm::name()
const 232 return QStringLiteral(
"setmfromraster" );
235 QString QgsDrapeToMAlgorithm::displayName()
const 237 return QObject::tr(
"Set M value from raster" );
240 QStringList QgsDrapeToMAlgorithm::tags()
const 242 return QObject::tr(
"drape,vertex,vertices,sample,dem,update,feature,measure" ).split(
',' );
245 QString QgsDrapeToMAlgorithm::shortHelpString()
const 247 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." )
248 + QStringLiteral(
"\n\n" )
249 + QObject::tr(
"The raster values can optionally be scaled by a preset amount." );
252 QString QgsDrapeToMAlgorithm::shortDescription()
const 254 return QObject::tr(
"Sets the M value for vertices to values sampled from a raster layer." );
257 QgsDrapeToMAlgorithm *QgsDrapeToMAlgorithm::createInstance()
const 259 return new QgsDrapeToMAlgorithm();
262 bool QgsDrapeToMAlgorithm::supportInPlaceEdit(
const QgsMapLayer *l )
const 268 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
279 void QgsDrapeToMAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const 284 QgsPoint QgsDrapeToMAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
A rectangle specified with double values.
Base class for all map layer types.
Base class for providing feedback from a processing algorithm.
QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QList< QgsFeature > QgsFeatureList
A class to represent a 2D point.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
A geometry is the spatial representation of a feature.
A raster band parameter for Processing algorithms.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
A raster layer parameter for processing algorithms.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
Custom exception class for processing related exceptions.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex...
A store for object properties.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Point geometry type, with support for z-dimension and m-values.
Double value (including negative values)
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition for a property.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
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.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Custom exception class for Coordinate Reference System related exceptions.
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
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...
Base class for raster data providers.