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