mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
Processing: Add Fix Geometry Algorithm and test: Overlap
This commit is contained in:
parent
de98779ebb
commit
9551e993e8
@ -62,6 +62,7 @@ set(QGIS_ANALYSIS_SRCS
|
||||
processing/qgsalgorithmcellstatistics.cpp
|
||||
processing/qgsalgorithmcentroid.cpp
|
||||
processing/qgsalgorithmcheckgeometryangle.cpp
|
||||
processing/qgsalgorithmfixgeometryoverlap.cpp
|
||||
processing/qgsalgorithmfixgeometryangle.cpp
|
||||
processing/qgsalgorithmcheckgeometryhole.cpp
|
||||
processing/qgsalgorithmfixgeometryhole.cpp
|
||||
|
274
src/analysis/processing/qgsalgorithmfixgeometryoverlap.cpp
Normal file
274
src/analysis/processing/qgsalgorithmfixgeometryoverlap.cpp
Normal file
@ -0,0 +1,274 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmfixgeometryoverlap.cpp
|
||||
---------------------
|
||||
begin : April 2025
|
||||
copyright : (C) 2025 by Jacky Volpes
|
||||
email : jacky dot volpes at oslandia 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 "qgsalgorithmfixgeometryoverlap.h"
|
||||
#include "qgsgeometrycheckerror.h"
|
||||
#include "qgsgeometrycheckerutils.h"
|
||||
#include "qgsgeometryoverlapcheck.h"
|
||||
#include "qgsvectordataproviderfeaturepool.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectorfilewriter.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
QString QgsFixGeometryOverlapAlgorithm::name() const
|
||||
{
|
||||
return QStringLiteral( "fixgeometryoverlap" );
|
||||
}
|
||||
|
||||
QString QgsFixGeometryOverlapAlgorithm::displayName() const
|
||||
{
|
||||
return QObject::tr( "Fix geometry (overlap)" );
|
||||
}
|
||||
|
||||
QStringList QgsFixGeometryOverlapAlgorithm::tags() const
|
||||
{
|
||||
return QObject::tr( "delete,area,fix,overlap" ).split( ',' );
|
||||
}
|
||||
|
||||
QString QgsFixGeometryOverlapAlgorithm::group() const
|
||||
{
|
||||
return QObject::tr( "Fix geometry" );
|
||||
}
|
||||
|
||||
QString QgsFixGeometryOverlapAlgorithm::groupId() const
|
||||
{
|
||||
return QStringLiteral( "fixgeometry" );
|
||||
}
|
||||
|
||||
QString QgsFixGeometryOverlapAlgorithm::shortHelpString() const
|
||||
{
|
||||
return QObject::tr( "This algorithm deletes overlap sections based on an error layer from the check overlap algorithm.\n" );
|
||||
}
|
||||
|
||||
QgsFixGeometryOverlapAlgorithm *QgsFixGeometryOverlapAlgorithm::createInstance() const
|
||||
{
|
||||
return new QgsFixGeometryOverlapAlgorithm();
|
||||
}
|
||||
|
||||
void QgsFixGeometryOverlapAlgorithm::initAlgorithm( const QVariantMap &configuration )
|
||||
{
|
||||
Q_UNUSED( configuration )
|
||||
|
||||
// Inputs
|
||||
addParameter( new QgsProcessingParameterFeatureSource(
|
||||
QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon )
|
||||
) );
|
||||
addParameter( new QgsProcessingParameterFeatureSource(
|
||||
QStringLiteral( "ERRORS" ), QObject::tr( "Error layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorPoint )
|
||||
) );
|
||||
addParameter( new QgsProcessingParameterField(
|
||||
QStringLiteral( "UNIQUE_ID" ), QObject::tr( "Field of original feature unique identifier" ),
|
||||
QString(), QStringLiteral( "ERRORS" )
|
||||
) );
|
||||
addParameter( new QgsProcessingParameterField(
|
||||
QStringLiteral( "OVERLAP_FEATURE_UNIQUE_IDX" ), QObject::tr( "Field of overlap feature unique identifier" ),
|
||||
QString(), QStringLiteral( "ERRORS" ),
|
||||
Qgis::ProcessingFieldParameterDataType::Numeric
|
||||
) );
|
||||
addParameter( new QgsProcessingParameterField(
|
||||
QStringLiteral( "ERROR_VALUE_ID" ), QObject::tr( "Field of error value" ),
|
||||
QStringLiteral( "gc_error" ), QStringLiteral( "ERRORS" ),
|
||||
Qgis::ProcessingFieldParameterDataType::Numeric
|
||||
) );
|
||||
|
||||
// Outputs
|
||||
addParameter( new QgsProcessingParameterFeatureSink(
|
||||
QStringLiteral( "OUTPUT" ), QObject::tr( "Output layer" ), Qgis::ProcessingSourceType::VectorPolygon
|
||||
) );
|
||||
addParameter( new QgsProcessingParameterFeatureSink(
|
||||
QStringLiteral( "REPORT" ), QObject::tr( "Report layer" ), Qgis::ProcessingSourceType::VectorPoint
|
||||
) );
|
||||
|
||||
std::unique_ptr<QgsProcessingParameterNumber> tolerance = std::make_unique<QgsProcessingParameterNumber>(
|
||||
QStringLiteral( "TOLERANCE" ), QObject::tr( "Tolerance" ), Qgis::ProcessingNumberParameterType::Integer, 8, false, 1, 13
|
||||
);
|
||||
tolerance->setFlags( tolerance->flags() | Qgis::ProcessingParameterFlag::Advanced );
|
||||
addParameter( tolerance.release() );
|
||||
}
|
||||
|
||||
QVariantMap QgsFixGeometryOverlapAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
|
||||
{
|
||||
const std::unique_ptr<QgsProcessingFeatureSource> input( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
|
||||
if ( !input )
|
||||
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "INPUT" ) ) );
|
||||
|
||||
const std::unique_ptr<QgsProcessingFeatureSource> errors( parameterAsSource( parameters, QStringLiteral( "ERRORS" ), context ) );
|
||||
if ( !errors )
|
||||
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "ERRORS" ) ) );
|
||||
|
||||
QgsProcessingMultiStepFeedback multiStepFeedback( 2, feedback );
|
||||
|
||||
const QString featIdFieldName = parameterAsString( parameters, QStringLiteral( "UNIQUE_ID" ), context );
|
||||
const QString overlapFeatIdFieldName = parameterAsString( parameters, QStringLiteral( "OVERLAP_FEATURE_UNIQUE_IDX" ), context );
|
||||
const QString errorValueIdFieldName = parameterAsString( parameters, QStringLiteral( "ERROR_VALUE_ID" ), context );
|
||||
|
||||
// Verify that input fields exists
|
||||
if ( errors->fields().indexFromName( featIdFieldName ) == -1 )
|
||||
throw QgsProcessingException( QObject::tr( "Field \"%1\" does not exist in the error layer." ).arg( featIdFieldName ) );
|
||||
if ( errors->fields().indexFromName( errorValueIdFieldName ) == -1 )
|
||||
throw QgsProcessingException( QObject::tr( "Field \"%1\" does not exist in the error layer." ).arg( errorValueIdFieldName ) );
|
||||
int overlapIdFieldIndex = errors->fields().indexFromName( overlapFeatIdFieldName );
|
||||
if ( overlapIdFieldIndex == -1 )
|
||||
throw QgsProcessingException( QObject::tr( "Field \"%1\" does not exist in the error layer." ).arg( overlapFeatIdFieldName ) );
|
||||
int inputIdFieldIndex = input->fields().indexFromName( featIdFieldName );
|
||||
if ( inputIdFieldIndex == -1 )
|
||||
throw QgsProcessingException( QObject::tr( "Field \"%1\" does not exist in input layer." ).arg( featIdFieldName ) );
|
||||
|
||||
const QgsField inputFeatIdField = input->fields().at( inputIdFieldIndex );
|
||||
const QMetaType::Type inputFeatIdFieldType = inputFeatIdField.type();
|
||||
if ( inputFeatIdFieldType != errors->fields().at( errors->fields().indexFromName( featIdFieldName ) ).type() )
|
||||
throw QgsProcessingException( QObject::tr( "Field \"%1\" does not have the same type as in the error layer." ).arg( featIdFieldName ) );
|
||||
|
||||
const QgsField overlapFeatIdField = errors->fields().at( overlapIdFieldIndex );
|
||||
const QMetaType::Type overlapFeatIdFieldType = overlapFeatIdField.type();
|
||||
if ( inputFeatIdFieldType != errors->fields().at( errors->fields().indexFromName( overlapFeatIdFieldName ) ).type() )
|
||||
throw QgsProcessingException( QObject::tr( "Field \"%1\" does not have the same type as \"%2\" in the input layer." ).arg( overlapFeatIdFieldName ).arg( featIdFieldName ) );
|
||||
|
||||
QString dest_output;
|
||||
const std::unique_ptr<QgsFeatureSink> sink_output( parameterAsSink(
|
||||
parameters, QStringLiteral( "OUTPUT" ), context, dest_output, input->fields(), input->wkbType(), input->sourceCrs()
|
||||
) );
|
||||
if ( !sink_output )
|
||||
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
|
||||
|
||||
QString dest_report;
|
||||
QgsFields reportFields = errors->fields();
|
||||
reportFields.append( QgsField( QStringLiteral( "report" ), QMetaType::QString ) );
|
||||
reportFields.append( QgsField( QStringLiteral( "error_fixed" ), QMetaType::Bool ) );
|
||||
const std::unique_ptr<QgsFeatureSink> sink_report( parameterAsSink(
|
||||
parameters, QStringLiteral( "REPORT" ), context, dest_report, reportFields, errors->wkbType(), errors->sourceCrs()
|
||||
) );
|
||||
if ( !sink_report )
|
||||
throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "REPORT" ) ) );
|
||||
|
||||
const QgsProject *project = QgsProject::instance();
|
||||
QgsGeometryCheckContext checkContext = QgsGeometryCheckContext( mTolerance, input->sourceCrs(), project->transformContext(), project );
|
||||
QStringList messages;
|
||||
|
||||
const QgsGeometryOverlapCheck check( &checkContext, QVariantMap() );
|
||||
|
||||
std::unique_ptr<QgsVectorLayer> fixedLayer( input->materialize( QgsFeatureRequest() ) );
|
||||
QgsVectorDataProviderFeaturePool featurePool = QgsVectorDataProviderFeaturePool( fixedLayer.get() );
|
||||
QMap<QString, QgsFeaturePool *> featurePools;
|
||||
featurePools.insert( fixedLayer->id(), &featurePool );
|
||||
|
||||
QgsFeature errorFeature, inputFeature, overlapFeature, testDuplicateIdFeature;
|
||||
QgsFeatureIterator errorFeaturesIt = errors->getFeatures();
|
||||
QList<QgsGeometryCheck::Changes> changesList;
|
||||
QgsFeature reportFeature;
|
||||
reportFeature.setFields( reportFields );
|
||||
long long progression = 0;
|
||||
long long totalProgression = errors->featureCount();
|
||||
multiStepFeedback.setCurrentStep( 1 );
|
||||
multiStepFeedback.setProgressText( QObject::tr( "Fixing errors..." ) );
|
||||
while ( errorFeaturesIt.nextFeature( errorFeature ) )
|
||||
{
|
||||
progression++;
|
||||
multiStepFeedback.setProgress( static_cast<double>( static_cast<long double>( progression ) / totalProgression ) * 100 );
|
||||
reportFeature.setGeometry( errorFeature.geometry() );
|
||||
|
||||
QString idValue = errorFeature.attribute( featIdFieldName ).toString();
|
||||
if ( inputFeatIdFieldType == QMetaType::QString )
|
||||
idValue = "'" + idValue + "'";
|
||||
QgsFeatureIterator it = fixedLayer->getFeatures( QgsFeatureRequest().setFilterExpression( "\"" + featIdFieldName + "\" = " + idValue ) );
|
||||
|
||||
QString overlapIdValue = errorFeature.attribute( overlapFeatIdFieldName ).toString();
|
||||
if ( overlapFeatIdFieldType == QMetaType::QString )
|
||||
overlapIdValue = "'" + overlapIdValue + "'";
|
||||
QgsFeatureIterator overlapIt = fixedLayer->getFeatures( QgsFeatureRequest().setFilterExpression( "\"" + featIdFieldName + "\" = " + overlapIdValue ) );
|
||||
|
||||
if ( !it.nextFeature( inputFeature ) || !inputFeature.isValid() )
|
||||
reportFeature.setAttributes( errorFeature.attributes() << QObject::tr( "Source feature not found or invalid" ) << false );
|
||||
|
||||
else if ( !overlapIt.nextFeature( overlapFeature ) || !overlapFeature.isValid() )
|
||||
reportFeature.setAttributes( errorFeature.attributes() << QObject::tr( "Overlap feature not found or invalid" ) << false );
|
||||
|
||||
else if ( it.nextFeature( testDuplicateIdFeature ) )
|
||||
throw QgsProcessingException( QObject::tr( "More than one feature found in input layer with value \"%1\" in unique field \"%2\"" ).arg( idValue ).arg( featIdFieldName ) );
|
||||
|
||||
else if ( overlapIt.nextFeature( testDuplicateIdFeature ) )
|
||||
throw QgsProcessingException( QObject::tr( "More than one overlap feature found in input layer with value \"%1\" in unique field \"%2\"" ).arg( overlapIdValue ).arg( overlapFeatIdFieldName ) );
|
||||
|
||||
else if ( inputFeature.geometry().isNull() )
|
||||
reportFeature.setAttributes( errorFeature.attributes() << QObject::tr( "Feature geometry is null" ) << false );
|
||||
|
||||
else if ( overlapFeature.geometry().isNull() )
|
||||
reportFeature.setAttributes( errorFeature.attributes() << QObject::tr( "Overlap feature geometry is null" ) << false );
|
||||
|
||||
else
|
||||
{
|
||||
QgsGeometryOverlapCheckError checkError = QgsGeometryOverlapCheckError(
|
||||
&check,
|
||||
QgsGeometryCheckerUtils::LayerFeature( &featurePool, inputFeature, &checkContext, false ),
|
||||
inputFeature.geometry(),
|
||||
errorFeature.geometry().asPoint(),
|
||||
errorFeature.attribute( errorValueIdFieldName ),
|
||||
QgsGeometryCheckerUtils::LayerFeature( &featurePool, overlapFeature, &checkContext, false )
|
||||
);
|
||||
for ( QgsGeometryCheck::Changes changes : changesList )
|
||||
checkError.handleChanges( changes );
|
||||
|
||||
QgsGeometryCheck::Changes changes;
|
||||
check.fixError( featurePools, &checkError, QgsGeometryOverlapCheck::ResolutionMethod::Subtract, QMap<QString, int>(), changes );
|
||||
changesList << changes;
|
||||
QString resolutionMessage = checkError.resolutionMessage();
|
||||
if ( checkError.status() == QgsGeometryCheckError::StatusObsolete )
|
||||
resolutionMessage = QObject::tr( "Error is obsolete" );
|
||||
reportFeature.setAttributes( errorFeature.attributes() << resolutionMessage << ( checkError.status() == QgsGeometryCheckError::StatusFixed ) );
|
||||
}
|
||||
|
||||
if ( !sink_report->addFeature( reportFeature, QgsFeatureSink::FastInsert ) )
|
||||
throw QgsProcessingException( writeFeatureError( sink_report.get(), parameters, QStringLiteral( "REPORT" ) ) );
|
||||
}
|
||||
multiStepFeedback.setProgress( 100 );
|
||||
|
||||
progression = 0;
|
||||
totalProgression = fixedLayer->featureCount();
|
||||
multiStepFeedback.setCurrentStep( 2 );
|
||||
multiStepFeedback.setProgressText( QObject::tr( "Exporting fixed layer..." ) );
|
||||
QgsFeature fixedFeature;
|
||||
QgsFeatureIterator fixedFeaturesIt = fixedLayer->getFeatures();
|
||||
while ( fixedFeaturesIt.nextFeature( fixedFeature ) )
|
||||
{
|
||||
progression++;
|
||||
multiStepFeedback.setProgress( static_cast<double>( static_cast<long double>( progression ) / totalProgression ) * 100 );
|
||||
if ( !sink_output->addFeature( fixedFeature, QgsFeatureSink::FastInsert ) )
|
||||
throw QgsProcessingException( writeFeatureError( sink_output.get(), parameters, QStringLiteral( "OUTPUT" ) ) );
|
||||
}
|
||||
multiStepFeedback.setProgress( 100 );
|
||||
|
||||
QVariantMap outputs;
|
||||
outputs.insert( QStringLiteral( "OUTPUT" ), dest_output );
|
||||
outputs.insert( QStringLiteral( "REPORT" ), dest_report );
|
||||
|
||||
return outputs;
|
||||
}
|
||||
|
||||
bool QgsFixGeometryOverlapAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * )
|
||||
{
|
||||
mTolerance = parameterAsInt( parameters, QStringLiteral( "TOLERANCE" ), context );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Qgis::ProcessingAlgorithmFlags QgsFixGeometryOverlapAlgorithm::flags() const
|
||||
{
|
||||
return QgsProcessingAlgorithm::flags() | Qgis::ProcessingAlgorithmFlag::NoThreading;
|
||||
}
|
||||
|
||||
///@endcond
|
52
src/analysis/processing/qgsalgorithmfixgeometryoverlap.h
Normal file
52
src/analysis/processing/qgsalgorithmfixgeometryoverlap.h
Normal file
@ -0,0 +1,52 @@
|
||||
/***************************************************************************
|
||||
qgsalgorithmfixgeometryoverlap.h
|
||||
---------------------
|
||||
begin : April 2025
|
||||
copyright : (C) 2025 by Jacky Volpes
|
||||
email : jacky dot volpes at oslandia 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 QGSALGORITHMFIXGEOMETRYOVERLAP_H
|
||||
#define QGSALGORITHMFIXGEOMETRYOVERLAP_H
|
||||
|
||||
#define SIP_NO_FILE
|
||||
|
||||
#include "qgis_sip.h"
|
||||
#include "qgsprocessingalgorithm.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
|
||||
class QgsFixGeometryOverlapAlgorithm : public QgsProcessingAlgorithm
|
||||
{
|
||||
public:
|
||||
QgsFixGeometryOverlapAlgorithm() = default;
|
||||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
|
||||
QString name() const override;
|
||||
QString displayName() const override;
|
||||
QStringList tags() const override;
|
||||
QString group() const override;
|
||||
QString groupId() const override;
|
||||
QString shortHelpString() const override;
|
||||
Qgis::ProcessingAlgorithmFlags flags() const override;
|
||||
QgsFixGeometryOverlapAlgorithm *createInstance() const override SIP_FACTORY;
|
||||
|
||||
protected:
|
||||
bool prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
|
||||
QVariantMap processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
|
||||
|
||||
private:
|
||||
int mTolerance { 8 };
|
||||
};
|
||||
|
||||
///@endcond PRIVATE
|
||||
|
||||
#endif // QGSALGORITHMFIXGEOMETRYOVERLAP_H
|
@ -46,6 +46,7 @@
|
||||
#include "qgsalgorithmcheckgeometryangle.h"
|
||||
#include "qgsalgorithmcheckgeometryarea.h"
|
||||
#include "qgsalgorithmfixgeometryarea.h"
|
||||
#include "qgsalgorithmfixgeometryoverlap.h"
|
||||
#include "qgsalgorithmfixgeometryhole.h"
|
||||
#include "qgsalgorithmfixgeometrymissingvertex.h"
|
||||
#include "qgsalgorithmcheckgeometryhole.h"
|
||||
@ -593,6 +594,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
|
||||
addAlgorithm( new QgsPolygonsToLinesAlgorithm() );
|
||||
addAlgorithm( new QgsDensifyGeometriesByIntervalAlgorithm() );
|
||||
addAlgorithm( new QgsDensifyGeometriesByCountAlgorithm() );
|
||||
addAlgorithm( new QgsFixGeometryOverlapAlgorithm() );
|
||||
addAlgorithm( new QgsFixGeometryAngleAlgorithm() );
|
||||
addAlgorithm( new QgsFixGeometryAreaAlgorithm() );
|
||||
addAlgorithm( new QgsFixGeometryHoleAlgorithm() );
|
||||
|
@ -40,6 +40,7 @@ class TestQgsProcessingFixGeometry : public QgsTest
|
||||
void fixAreaAlg();
|
||||
|
||||
void fixHoleAlg();
|
||||
void fixOverlapAlg();
|
||||
void fixMissingVertexAlg();
|
||||
|
||||
private:
|
||||
@ -315,6 +316,55 @@ void TestQgsProcessingFixGeometry::fixHoleAlg()
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsProcessingFixGeometry::fixOverlapAlg()
|
||||
{
|
||||
const QDir testDataDir( QDir( TEST_DATA_DIR ).absoluteFilePath( "geometry_checker" ) );
|
||||
QgsVectorLayer sourceLayer = QgsVectorLayer( testDataDir.absoluteFilePath( "polygon_layer.shp" ), QStringLiteral( "polygons" ), QStringLiteral( "ogr" ) );
|
||||
QgsVectorLayer errorsLayer = QgsVectorLayer( mDataDir.absoluteFilePath( "remove_overlaps.gpkg|layername=overlap_errors" ), QString(), QStringLiteral( "ogr" ) );
|
||||
QVERIFY( sourceLayer.isValid() );
|
||||
QVERIFY( errorsLayer.isValid() );
|
||||
const QStringList reportList = QStringList()
|
||||
<< QStringLiteral( "Remove overlapping area from neighboring polygon with shortest shared edge" )
|
||||
<< QStringLiteral( "Remove overlapping area from neighboring polygon with shortest shared edge" );
|
||||
|
||||
const std::unique_ptr<QgsProcessingAlgorithm> alg(
|
||||
QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:fixgeometryoverlap" ) )
|
||||
);
|
||||
QVERIFY( alg != nullptr );
|
||||
|
||||
QVariantMap parameters;
|
||||
parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( &sourceLayer ) );
|
||||
parameters.insert( QStringLiteral( "UNIQUE_ID" ), "id" );
|
||||
parameters.insert( QStringLiteral( "OVERLAP_FEATURE_UNIQUE_IDX" ), "gc_overlap_feature_id" );
|
||||
parameters.insert( QStringLiteral( "ERRORS" ), QVariant::fromValue( &errorsLayer ) );
|
||||
parameters.insert( QStringLiteral( "OUTPUT" ), QgsProcessing::TEMPORARY_OUTPUT );
|
||||
parameters.insert( QStringLiteral( "REPORT" ), QgsProcessing::TEMPORARY_OUTPUT );
|
||||
|
||||
bool ok = false;
|
||||
QgsProcessingFeedback feedback;
|
||||
auto context = std::make_unique<QgsProcessingContext>();
|
||||
|
||||
QVariantMap results;
|
||||
results = alg->run( parameters, *context, &feedback, &ok );
|
||||
QVERIFY( ok );
|
||||
|
||||
const std::unique_ptr<QgsVectorLayer> outputLayer( qobject_cast<QgsVectorLayer *>( context->getMapLayer( results.value( QStringLiteral( "OUTPUT" ) ).toString() ) ) );
|
||||
const std::unique_ptr<QgsVectorLayer> reportLayer( qobject_cast<QgsVectorLayer *>( context->getMapLayer( results.value( QStringLiteral( "REPORT" ) ).toString() ) ) );
|
||||
QVERIFY( reportLayer->isValid() );
|
||||
QVERIFY( outputLayer->isValid() );
|
||||
|
||||
QCOMPARE( outputLayer->featureCount(), 25 );
|
||||
QCOMPARE( reportLayer->featureCount(), reportList.count() );
|
||||
int idx = 1;
|
||||
for ( const QString &expectedReport : reportList )
|
||||
{
|
||||
const QgsFeature reportFeature = reportLayer->getFeature( idx );
|
||||
QCOMPARE( reportFeature.attribute( "report" ), expectedReport );
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
void TestQgsProcessingFixGeometry::fixMissingVertexAlg()
|
||||
{
|
||||
const QDir testDataDir( QDir( TEST_DATA_DIR ).absoluteFilePath( "geometry_checker" ) );
|
||||
|
BIN
tests/testdata/geometry_fix/remove_overlaps.gpkg
vendored
Normal file
BIN
tests/testdata/geometry_fix/remove_overlaps.gpkg
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user