mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
raster calculator algorithm (WIP)
This commit is contained in:
parent
eda287d46c
commit
653402593f
@ -127,6 +127,7 @@
|
||||
<file>themes/default/algorithms/mAlgorithmRandomPointsWithinExtent.svg</file>
|
||||
<file>themes/default/algorithms/mAlgorithmRandomPoissonRaster.svg</file>
|
||||
<file>themes/default/algorithms/mAlgorithmRandomRaster.svg</file>
|
||||
<file>themes/default/algorithms/mAlgorithmRasterCalculator.svg</file>
|
||||
<file>themes/default/algorithms/mAlgorithmRegularPoints.svg</file>
|
||||
<file>themes/default/algorithms/mAlgorithmRoundRastervalues.svg</file>
|
||||
<file>themes/default/algorithms/mAlgorithmSelectLocation.svg</file>
|
||||
|
@ -0,0 +1 @@
|
||||
<svg height="24" width="24" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(.92307692 0 0 .92307692 -.846154 -.846154)"><path d="m6.333 2h4.334v4.333h-4.334z" fill="#aec7e2"/><path d="m2 2h4.333v4.333h-4.333zm4.333 4.333h4.334v4.334h-4.334zm4.334-4.333h4.333v4.333h-4.333z" fill="#2b3b4d"/><path d="m2 6.333h4.333v4.334h-4.333zm8.667 0h4.333v4.334h-4.333zm-4.334 4.334h4.334v4.333h-4.334z" fill="#aec7e2"/><path d="m2 10.667h4.333v4.333h-4.333z" fill="#2b3b4d"/></g><g transform="matrix(.72727273 0 0 .72727273 7.272727 .727273)"><g stroke="#5b5b5c"><path d="m1.5 28.5h21v2h-21z" fill="#c7c7c7" fill-rule="evenodd" stroke-linejoin="round"/><path d="m3 12.5h18" fill="none"/><path d="m3 18.5h18" fill="none"/><path d="m3 24.5h18" fill="none"/></g><g fill-opacity=".996078" fill-rule="evenodd"><circle cx="12.5" cy="18.5" fill="#c6f8c6" r="2" stroke="#619361"/><circle cx="7.5" cy="18.5" fill="#c6f8c6" r="2" stroke="#619361"/><g fill="#c3e1f5" stroke="#3f5e71"><circle cx="17.5" cy="24.500002" r="2"/><circle cx="12.5" cy="24.500002" r="2"/><circle cx="7.5" cy="24.500002" r="2"/></g><circle cx="17.5" cy="12.5" fill="#f7aeae" r="2" stroke="#a20404"/><circle cx="9.5" cy="12.5" fill="#f7aeae" r="2" stroke="#a20404"/></g><path d="m2.5 10.506742v17.986517" fill="none" stroke="#5b5b5c" stroke-linecap="round"/><path d="m21.5 10.506742v17.986517" fill="none" stroke="#5b5b5c" stroke-linecap="round"/></g></svg>
|
After Width: | Height: | Size: 1.4 KiB |
@ -168,6 +168,7 @@ set(QGIS_ANALYSIS_SRCS
|
||||
processing/qgsalgorithmrandompointsinpolygons.cpp
|
||||
processing/qgsalgorithmrandompointsonlines.cpp
|
||||
processing/qgsalgorithmrandomraster.cpp
|
||||
processing/qgsalgorithmrastercalculator.cpp
|
||||
processing/qgsalgorithmrasterdtmslopebasedfilter.cpp
|
||||
processing/qgsalgorithmrasterfrequencybycomparisonoperator.cpp
|
||||
processing/qgsalgorithmrasterlayerproperties.cpp
|
||||
|
80
src/analysis/processing/qgsalgorithmrastercalculator.cpp
Normal file
80
src/analysis/processing/qgsalgorithmrastercalculator.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmrastercalculator.cpp
|
||||
---------------------
|
||||
begin : July 2023
|
||||
copyright : (C) 2023 by Alexander Bruy
|
||||
email : alexander dot bruy at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsalgorithmrastercalculator.h"
|
||||
#include "qgsrasterfilewriter.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
QString QgsRasterCalculatorAlgorithm::name() const
|
||||
{
|
||||
return QStringLiteral( "rastercalc" );
|
||||
}
|
||||
|
||||
QString QgsRasterCalculatorAlgorithm::displayName() const
|
||||
{
|
||||
return QObject::tr( "Raster calculator" );
|
||||
}
|
||||
|
||||
QStringList QgsRasterCalculatorAlgorithm::tags() const
|
||||
{
|
||||
return QObject::tr( "raster,calculator" ).split( ',' );
|
||||
}
|
||||
|
||||
QString QgsRasterCalculatorAlgorithm::group() const
|
||||
{
|
||||
return QObject::tr( "Raster analysis" );
|
||||
}
|
||||
|
||||
QString QgsRasterCalculatorAlgorithm::groupId() const
|
||||
{
|
||||
return QStringLiteral( "rasteranalysis" );
|
||||
}
|
||||
|
||||
QString QgsRasterCalculatorAlgorithm::shortHelpString() const
|
||||
{
|
||||
return QObject::tr( "Performing algebraic operations using raster layers." );
|
||||
}
|
||||
|
||||
QgsRasterCalculatorAlgorithm *QgsRasterCalculatorAlgorithm::createInstance() const
|
||||
{
|
||||
return new QgsRasterCalculatorAlgorithm();
|
||||
}
|
||||
|
||||
void QgsRasterCalculatorAlgorithm::initAlgorithm( const QVariantMap & )
|
||||
{
|
||||
addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "INPUT" ), QObject::tr( "Input layers" ), QgsProcessing::SourceType::TypeRaster ) );
|
||||
addParameter( new QgsProcessingParameterExpression( QStringLiteral( "EXPRESSION" ), QObject::tr( "Expression" ), QVariant(), QStringLiteral( "INPUT" ), false, Qgis::ExpressionType::RasterCalculator ) );
|
||||
addParameter( new QgsProcessingParameterExtent( QStringLiteral( "EXTENT" ), QObject::tr( "Output extent" ), QVariant(), true ) );
|
||||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "CELL_SIZE" ), QObject::tr( "Output cell size (leave empty to set automatically)" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0.0 ) );
|
||||
addParameter( new QgsProcessingParameterCrs( QStringLiteral( "CRS" ), QObject::tr( "Output CRS" ), QVariant(), true ) );
|
||||
addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Calculated" ) ) );
|
||||
}
|
||||
|
||||
QVariantMap QgsRasterCalculatorAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
|
||||
{
|
||||
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
|
||||
const QFileInfo fi( outputFile );
|
||||
const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
|
||||
|
||||
QVariantMap outputs;
|
||||
outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
|
||||
return outputs;
|
||||
}
|
||||
|
||||
///@endcond
|
||||
|
57
src/analysis/processing/qgsalgorithmrastercalculator.h
Normal file
57
src/analysis/processing/qgsalgorithmrastercalculator.h
Normal file
@ -0,0 +1,57 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmrastercalculator.h
|
||||
---------------------
|
||||
begin : July 2023
|
||||
copyright : (C) 2023 by Alexander Bruy
|
||||
email : alexander dot bruy at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSALGORITHMRASTERCALCULATOR_H
|
||||
#define QGSALGORITHMRASTERCALCULATOR_H
|
||||
|
||||
#define SIP_NO_FILE
|
||||
|
||||
#include "qgis_sip.h"
|
||||
#include "qgsprocessingalgorithm.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
/**
|
||||
* Native raster calculator algorithm.
|
||||
*/
|
||||
class QgsRasterCalculatorAlgorithm : public QgsProcessingAlgorithm
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
QgsRasterCalculatorAlgorithm() = default;
|
||||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
|
||||
QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRasterCalculator.svg" ) ); }
|
||||
QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRasterCalculator.svg" ) ); }
|
||||
QString name() const override;
|
||||
QString displayName() const override;
|
||||
QStringList tags() const override;
|
||||
QString group() const override;
|
||||
QString groupId() const override;
|
||||
QString shortHelpString() const override;
|
||||
QgsRasterCalculatorAlgorithm *createInstance() const override SIP_FACTORY;
|
||||
|
||||
protected:
|
||||
|
||||
QVariantMap processAlgorithm( const QVariantMap ¶meters,
|
||||
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
|
||||
};
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
||||
#endif // QGSALGORITHMRASTERCALCULATOR_H
|
@ -152,6 +152,7 @@
|
||||
#include "qgsalgorithmrandompointsinpolygons.h"
|
||||
#include "qgsalgorithmrandompointsonlines.h"
|
||||
#include "qgsalgorithmrandomraster.h"
|
||||
#include "qgsalgorithmrastercalculator.h"
|
||||
#include "qgsalgorithmrasterdtmslopebasedfilter.h"
|
||||
#include "qgsalgorithmrasterfrequencybycomparisonoperator.h"
|
||||
#include "qgsalgorithmrasterlayerproperties.h"
|
||||
@ -440,6 +441,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
|
||||
addAlgorithm( new QgsRandomPointsOnLinesAlgorithm() );
|
||||
addAlgorithm( new QgsRandomPoissonRasterAlgorithm() );
|
||||
addAlgorithm( new QgsRandomUniformRasterAlgorithm() );
|
||||
addAlgorithm( new QgsRasterCalculatorAlgorithm() );
|
||||
addAlgorithm( new QgsRasterDtmSlopeBasedFilterAlgorithm() );
|
||||
addAlgorithm( new QgsRasterFrequencyByEqualOperatorAlgorithm() );
|
||||
addAlgorithm( new QgsRasterFrequencyByGreaterThanOperatorAlgorithm() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user