Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] add filter extent and filter rectangle to pdal algorithms
which support them
  • Loading branch information
alexbruy authored and wonder-sk committed Apr 14, 2023
1 parent 6207574 commit 15e6c77
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdalboundary.cpp
Expand Up @@ -60,9 +60,10 @@ QgsPdalBoundaryAlgorithm *QgsPdalBoundaryAlgorithm::createInstance() const
void QgsPdalBoundaryAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterVectorDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Boundary" ), QgsProcessing::TypeVectorPolygon ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of cells used to calculate boundary" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "THRESHOLD" ), QObject::tr( "Minimal number of points in a cell to consider cell occupied" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
createCommonParameters();
addParameter( new QgsProcessingParameterVectorDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Boundary" ), QgsProcessing::TypeVectorPolygon ) );
}

QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
Expand Down Expand Up @@ -99,6 +100,7 @@ QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &pa
args << QStringLiteral( "--threshold=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "THRESHOLD" ), context ) );
}

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/processing/pdal/qgsalgorithmpdalclip.cpp
Expand Up @@ -62,6 +62,7 @@ void QgsPdalClipAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterVectorLayer( QStringLiteral( "OVERLAY" ), QObject::tr( "Clipping polygons" ), QList< int >() << QgsProcessing::TypeVectorPolygon ) );
createCommonParameters();
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Clipped point cloud" ) ) );
}

Expand All @@ -87,6 +88,7 @@ QStringList QgsPdalClipAlgorithm::createArgumentLists( const QVariantMap &parame
QStringLiteral( "--polygon=%1" ).arg( overlayPath )
};

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/processing/pdal/qgsalgorithmpdaldensity.cpp
Expand Up @@ -70,6 +70,8 @@ void QgsPdalDensityAlgorithm::initAlgorithm( const QVariantMap & )
paramOriginY->setFlags( paramOriginY->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( paramOriginY.release() );

createCommonParameters();

addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Density raster" ) ) );
}

Expand Down Expand Up @@ -108,6 +110,7 @@ QStringList QgsPdalDensityAlgorithm::createArgumentLists( const QVariantMap &par
args << QStringLiteral( "--tile-origin-y=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "ORIGIN_Y" ), context ) );
}

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/processing/pdal/qgsalgorithmpdalexportraster.cpp
Expand Up @@ -71,6 +71,8 @@ void QgsPdalExportRasterAlgorithm::initAlgorithm( const QVariantMap & )
paramOriginY->setFlags( paramOriginY->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( paramOriginY.release() );

createCommonParameters();

addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Output raster" ) ) );
}

Expand Down Expand Up @@ -111,6 +113,7 @@ QStringList QgsPdalExportRasterAlgorithm::createArgumentLists( const QVariantMap
args << QStringLiteral( "--tile-origin-y=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "ORIGIN_Y" ), context ) );
}

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
Expand Up @@ -70,6 +70,8 @@ void QgsPdalExportRasterTinAlgorithm::initAlgorithm( const QVariantMap & )
paramOriginY->setFlags( paramOriginY->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( paramOriginY.release() );

createCommonParameters();

addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Output raster" ) ) );
}

Expand Down Expand Up @@ -108,6 +110,7 @@ QStringList QgsPdalExportRasterTinAlgorithm::createArgumentLists( const QVariant
args << QStringLiteral( "--tile-origin-y=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "ORIGIN_Y" ), context ) );
}

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/processing/pdal/qgsalgorithmpdalexportvector.cpp
Expand Up @@ -61,6 +61,7 @@ void QgsPdalExportVectorAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterPointCloudAttribute( QStringLiteral( "ATTRIBUTE" ), QObject::tr( "Attribute" ), QVariant(), QStringLiteral( "INPUT" ), true, true ) );
createCommonParameters();
addParameter( new QgsProcessingParameterVectorDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Output vector" ), QgsProcessing::TypeVectorPoint ) );
}

Expand Down Expand Up @@ -89,6 +90,7 @@ QStringList QgsPdalExportVectorAlgorithm::createArgumentLists( const QVariantMap
}
}

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/processing/pdal/qgsalgorithmpdalmerge.cpp
Expand Up @@ -60,6 +60,7 @@ QgsPdalMergeAlgorithm *QgsPdalMergeAlgorithm::createInstance() const
void QgsPdalMergeAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Input layers" ), QgsProcessing::TypePointCloud ) );
createCommonParameters();
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Destination file" ) ) );
}

Expand All @@ -82,6 +83,7 @@ QStringList QgsPdalMergeAlgorithm::createArgumentLists( const QVariantMap &param
args << QStringLiteral( "merge" )
<< QStringLiteral( "--output=%1" ).arg( outputFile );

applyCommonParameters( args, layers.at( 0 )->crs(), parameters, context );
applyThreadsParameter( args );

for ( const QgsMapLayer *layer : std::as_const( layers ) )
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/processing/pdal/qgsalgorithmpdalthin.cpp
Expand Up @@ -62,6 +62,7 @@ void QgsPdalThinAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "MODE" ), QObject::tr( "Mode" ), QStringList() << QObject::tr( "Every N-th" ) << QObject::tr( "Sample" ), false, 0 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "STEP" ), QObject::tr( "Step" ), QgsProcessingParameterNumber::Integer, 20, false, 1 ) );
createCommonParameters();
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Output layer" ) ) );
}

Expand All @@ -86,6 +87,7 @@ QStringList QgsPdalThinAlgorithm::createArgumentLists( const QVariantMap &parame
QStringLiteral( "--%1=%2" ).arg( mode == 0 ? QStringLiteral( "step-every-nth" ) : QStringLiteral( "step-sample" ) ).arg( step )
};

applyCommonParameters( args, layer->crs(), parameters, context );
applyThreadsParameter( args );
return args;
}
Expand Down
43 changes: 43 additions & 0 deletions src/analysis/processing/pdal/qgspdalalgorithmbase.cpp
Expand Up @@ -45,6 +45,49 @@ QString QgsPdalAlgorithmBase::wrenchExecutableBinary() const
return QString( wrenchExecutable );
}

void QgsPdalAlgorithmBase::createCommonParameters()
{
std::unique_ptr< QgsProcessingParameterString > filterParam = std::make_unique< QgsProcessingParameterString >( QStringLiteral( "FILTER_EXPRESSION" ), QObject::tr( "Filter expression" ), QVariant(), false, true );
filterParam->setFlags( filterParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( filterParam.release() );

std::unique_ptr< QgsProcessingParameterExtent > extentParam = std::make_unique< QgsProcessingParameterExtent >( QStringLiteral( "FILTER_EXTENT" ), QObject::tr( "Cropping extent" ), QVariant(), true );
extentParam->setFlags( extentParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( extentParam.release() );
}

void QgsPdalAlgorithmBase::applyCommonParameters( QStringList &arguments, QgsCoordinateReferenceSystem crs, const QVariantMap &parameters, QgsProcessingContext &context )
{
const QString filterExpression = parameterAsString( parameters, QStringLiteral( "FILTER_EXPRESSION" ), context ).trimmed();
if ( !filterExpression.isEmpty() )
{
arguments << QStringLiteral( "--filter=%1" ).arg( filterExpression );
}

if ( parameters.value( QStringLiteral( "FILTER_EXTENT" ) ).isValid() )
{
if ( crs.isValid() )
{
const QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral( "FILTER_EXTENT" ), context, crs );
arguments << QStringLiteral( "--bounds=([%1, %2], [%3, %4])" )
.arg( extent.xMinimum() )
.arg( extent.xMaximum() )
.arg( extent.yMinimum() )
.arg( extent.yMaximum() );

}
else
{
const QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral( "FILTER_EXTENT" ), context );
arguments << QStringLiteral( "--bounds=([%1, %2], [%3, %4])" )
.arg( extent.xMinimum() )
.arg( extent.xMaximum() )
.arg( extent.yMinimum() )
.arg( extent.yMaximum() );
}
}
}

void QgsPdalAlgorithmBase::applyThreadsParameter( QStringList &arguments )
{
QgsSettings settings;
Expand Down
14 changes: 12 additions & 2 deletions src/analysis/processing/pdal/qgspdalalgorithmbase.h
Expand Up @@ -42,8 +42,18 @@ class QgsPdalAlgorithmBase : public QgsProcessingAlgorithm
void setOutputValue( const QString &name, const QVariant &value );

/**
* Applies max number of concurrent threads for parallel runs parameter
* if user has MAX_THREADS option set in Processing options.
* Creates common advanced parameters, such as expression and rectangle filters
*/
void createCommonParameters();

/**
* Evaluates common advanced parameters and adds them to the pdal_wrench
* command line.
*/
void applyCommonParameters( QStringList &arguments, QgsCoordinateReferenceSystem crs, const QVariantMap &parameters, QgsProcessingContext &context );

/**
* Adds "--threads"parameter to the pdal_wrench command line.
*/
void applyThreadsParameter( QStringList &arguments );

Expand Down

0 comments on commit 15e6c77

Please sign in to comment.