Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/analysis/processing/pdal/qgsalgorithmpdaldensity.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/*************************************************************************** | ||
qgsalgorithmpdaldensity.cpp | ||
--------------------- | ||
begin : February 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 "qgsalgorithmpdaldensity.h" | ||
|
||
#include "qgsrunprocess.h" | ||
#include "qgspointcloudlayer.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsPdalDensityAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "density" ); | ||
} | ||
|
||
QString QgsPdalDensityAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Density" ); | ||
} | ||
|
||
QString QgsPdalDensityAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Point cloud extraction" ); | ||
} | ||
|
||
QString QgsPdalDensityAlgorithm::groupId() const | ||
{ | ||
return QStringLiteral( "pointcloudextraction" ); | ||
} | ||
|
||
QStringList QgsPdalDensityAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "cell,count,density,raster" ).split( ',' ); | ||
} | ||
|
||
QString QgsPdalDensityAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "This algorithm exports a raster file where each cell contains number of points that are in that cell's area." ); | ||
} | ||
|
||
QgsPdalDensityAlgorithm *QgsPdalDensityAlgorithm::createInstance() const | ||
{ | ||
return new QgsPdalDensityAlgorithm(); | ||
} | ||
|
||
void QgsPdalDensityAlgorithm::initAlgorithm( const QVariantMap & ) | ||
{ | ||
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) ); | ||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resoultion of the density raster" ), QgsProcessingParameterNumber::Integer, 1, false, 1 ) ); | ||
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TILE_SIZE" ), QObject::tr( "Tile size for parallel runs" ), QgsProcessingParameterNumber::Integer, 1000, false, 1 ) ); | ||
|
||
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 ); | ||
paramOriginX->setFlags( paramOriginX->flags() | QgsProcessingParameterDefinition::FlagAdvanced ); | ||
addParameter( paramOriginX.release() ); | ||
std::unique_ptr< QgsProcessingParameterNumber > paramOriginY = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_Y" ), QObject::tr( "Y origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 ); | ||
paramOriginY->setFlags( paramOriginY->flags() | QgsProcessingParameterDefinition::FlagAdvanced ); | ||
addParameter( paramOriginY.release() ); | ||
|
||
addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Density raster" ) ) ); | ||
} | ||
|
||
QStringList QgsPdalDensityAlgorithm::createArgumentLists( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) | ||
{ | ||
Q_UNUSED( feedback ); | ||
|
||
QgsPointCloudLayer *layer = parameterAsPointCloudLayer( parameters, QStringLiteral( "INPUT" ), context ); | ||
if ( !layer ) | ||
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) ); | ||
|
||
bool hasOriginX = parameters.value( QStringLiteral( "ORIGIN_X" ) ).isValid(); | ||
bool hasOriginY = parameters.value( QStringLiteral( "ORIGIN_Y" ) ).isValid(); | ||
|
||
if ( ( hasOriginX && !hasOriginY ) || ( !hasOriginX && hasOriginY ) ) | ||
{ | ||
throw QgsProcessingException( QObject::tr( "Specify both X and Y tile origin or don't set any of them." ) ); | ||
} | ||
|
||
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context ); | ||
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile ); | ||
|
||
int resolution = parameterAsInt( parameters, QStringLiteral( "RESOLUTION" ), context ); | ||
int tileSize = parameterAsInt( parameters, QStringLiteral( "TILE_SIZE" ), context ); | ||
|
||
QStringList args = { QStringLiteral( "density" ), | ||
QStringLiteral( "--input=%1" ).arg( layer->source() ), | ||
QStringLiteral( "--output=%1" ).arg( outputFile ), | ||
QStringLiteral( "--resolution=%1" ).arg( resolution ), | ||
QStringLiteral( "--tile-size=%1" ).arg( tileSize ) | ||
}; | ||
|
||
if ( hasOriginX && hasOriginY ) | ||
{ | ||
args << QStringLiteral( "--tile-origin-x=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "ORIGIN_X" ), context ) ); | ||
args << QStringLiteral( "--tile-origin-y=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "ORIGIN_Y" ), context ) ); | ||
} | ||
|
||
addThreadsParameter( args ); | ||
return args; | ||
} | ||
|
||
///@endcond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
qgsalgorithmpdaldensity.h | ||
--------------------- | ||
begin : February 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 QGSALGORITHMPDALDENSITY_H | ||
#define QGSALGORITHMPDALDENSITY_H | ||
|
||
#define SIP_NO_FILE | ||
|
||
#include "qgis_sip.h" | ||
#include "qgspdalalgorithmbase.h" | ||
|
||
///@cond PRIVATE | ||
|
||
/** | ||
* Native point cloud density algorithm. | ||
*/ | ||
class QgsPdalDensityAlgorithm : public QgsPdalAlgorithmBase | ||
{ | ||
|
||
public: | ||
|
||
QgsPdalDensityAlgorithm() = default; | ||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; | ||
QString name() const override; | ||
QString displayName() const override; | ||
QString group() const override; | ||
QString groupId() const override; | ||
QStringList tags() const override; | ||
QString shortHelpString() const override; | ||
QgsPdalDensityAlgorithm *createInstance() const override SIP_FACTORY; | ||
|
||
QStringList createArgumentLists( const QVariantMap ¶meters, | ||
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; | ||
|
||
friend class TestQgsProcessingPdalAlgs; | ||
}; | ||
|
||
///@endcond PRIVATE | ||
|
||
#endif // QGSALGORITHMPDALDENSITY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters