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(
"Draped" );
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 = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"NODATA" ),
50 nodata->setIsDynamic(
true );
52 nodata->setDynamicLayerParameterName( QStringLiteral(
"INPUT" ) );
53 addParameter( nodata.release() );
55 auto scaleParam = std::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;
107 mRasterExtent = mTransform.transform( mRasterExtent, Qgis::TransformDirection::Reverse );
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
201 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
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
264 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
268 if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
279 void QgsDrapeToMAlgorithm::prepareGeometry(
QgsGeometry &geometry,
double defaultVal )
const
284 QgsPoint QgsDrapeToMAlgorithm::drapeVertex(
const QgsPoint &p,
double rasterVal )
const
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.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
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.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
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.
A raster band parameter for Processing algorithms.
@ Double
Double/float values.
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 QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
static bool hasM(Type type) SIP_HOLDGIL
Tests whether a WKB type contains m values.
Type
The WKB type describes the number of dimensions a geometry has.
static Type addZ(Type type) SIP_HOLDGIL
Adds the z dimension to a WKB type and returns the new type.
static bool hasZ(Type type) SIP_HOLDGIL
Tests whether a WKB type contains the z-dimension.
static Type addM(Type type) SIP_HOLDGIL
Adds the m dimension to a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList