26QString QgsFixGeometryGapAlgorithm::name()
 const 
   28  return QStringLiteral( 
"fixgeometrygap" );
 
   31QString QgsFixGeometryGapAlgorithm::displayName()
 const 
   33  return QObject::tr( 
"Fill gaps" );
 
   36QString QgsFixGeometryGapAlgorithm::shortDescription()
 const 
   38  return QObject::tr( 
"Fills gaps detected with the \"Small gaps\" algorithm from the \"Check geometry\" section." );
 
   41QStringList QgsFixGeometryGapAlgorithm::tags()
 const 
   43  return QObject::tr( 
"fix,fill,gap" ).split( 
',' );
 
   46QString QgsFixGeometryGapAlgorithm::group()
 const 
   48  return QObject::tr( 
"Fix geometry" );
 
   51QString QgsFixGeometryGapAlgorithm::groupId()
 const 
   53  return QStringLiteral( 
"fixgeometry" );
 
   56QString QgsFixGeometryGapAlgorithm::shortHelpString()
 const 
   58  return QObject::tr( 
"This algorithm fills the gaps based on a gap and neighbors layer from the \"Small gaps\" algorithm in the \"Check geometry\" section.\n\n" 
   59                      "3 different fixing methods are available, which will give different results." );
 
   62QgsFixGeometryGapAlgorithm *QgsFixGeometryGapAlgorithm::createInstance()
 const 
   64  return new QgsFixGeometryGapAlgorithm();
 
   67void QgsFixGeometryGapAlgorithm::initAlgorithm( 
const QVariantMap &configuration )
 
   69  Q_UNUSED( configuration )
 
   87      checkMethods.cbegin(), checkMethods.cend() - 1, std::inserter( methods, methods.begin() ),
 
   94    QStringLiteral( 
"UNIQUE_ID" ), QObject::tr( 
"Field of original feature unique identifier" ),
 
   95    QString(), QStringLiteral( 
"INPUT" )
 
   98    QStringLiteral( 
"ERROR_ID_IDX" ), QObject::tr( 
"Field of error id" ),
 
   99    QStringLiteral( 
"gc_errorid" ), QStringLiteral( 
"GAPS" ),
 
  111  std::unique_ptr<QgsProcessingParameterNumber> tolerance = std::make_unique<QgsProcessingParameterNumber>(
 
  115  tolerance->setHelp( QObject::tr( 
"The \"Tolerance\" advanced parameter defines the numerical precision of geometric operations, " 
  116                                   "given as an integer n, meaning that any difference smaller than 10⁻ⁿ (in map units) is considered zero." ) );
 
  117  addParameter( tolerance.release() );
 
  122  const std::unique_ptr<QgsProcessingFeatureSource> input( parameterAsSource( parameters, QStringLiteral( 
"INPUT" ), context ) );
 
  126  const std::unique_ptr<QgsProcessingFeatureSource> neighbors( parameterAsSource( parameters, QStringLiteral( 
"NEIGHBORS" ), context ) );
 
  130  const std::unique_ptr<QgsProcessingFeatureSource> gaps( parameterAsSource( parameters, QStringLiteral( 
"GAPS" ), context ) );
 
  136  const QString featIdFieldName = parameterAsString( parameters, QStringLiteral( 
"UNIQUE_ID" ), context );
 
  137  const QString errorIdFieldName = parameterAsString( parameters, QStringLiteral( 
"ERROR_ID_IDX" ), context );
 
  140  int method = parameterAsEnum( parameters, QStringLiteral( 
"METHOD" ), context );
 
  157  if ( gaps->fields().indexFromName( errorIdFieldName ) == -1 )
 
  158    throw QgsProcessingException( QObject::tr( 
"Field \"%1\" does not exist in the gaps layer." ).arg( errorIdFieldName ) );
 
  159  if ( neighbors->fields().indexFromName( featIdFieldName ) == -1 )
 
  160    throw QgsProcessingException( QObject::tr( 
"Field \"%1\" does not exist in the neighbors layer." ).arg( featIdFieldName ) );
 
  161  int inputIdFieldIndex = input->fields().indexFromName( featIdFieldName );
 
  162  if ( inputIdFieldIndex == -1 )
 
  163    throw QgsProcessingException( QObject::tr( 
"Field \"%1\" does not exist in input layer." ).arg( featIdFieldName ) );
 
  165  const QgsField inputFeatIdField = input->fields().at( inputIdFieldIndex );
 
  166  const QMetaType::Type inputFeatIdFieldType = inputFeatIdField.
type();
 
  167  if ( inputFeatIdFieldType != neighbors->fields().at( neighbors->fields().indexFromName( featIdFieldName ) ).type() )
 
  168    throw QgsProcessingException( QObject::tr( 
"Field \"%1\" does not have the same type as in the neighbors layer." ).arg( featIdFieldName ) );
 
  171  const std::unique_ptr<QgsFeatureSink> sink_output( parameterAsSink(
 
  172    parameters, QStringLiteral( 
"OUTPUT" ), context, dest_output, input->fields(), input->wkbType(), input->sourceCrs()
 
  179  reportFields.
append( 
QgsField( QStringLiteral( 
"report" ), QMetaType::QString ) );
 
  180  reportFields.
append( 
QgsField( QStringLiteral( 
"error_fixed" ), QMetaType::Bool ) );
 
  181  const std::unique_ptr<QgsFeatureSink> sink_report( parameterAsSink(
 
  182    parameters, QStringLiteral( 
"REPORT" ), context, dest_report, reportFields, 
Qgis::WkbType::Point, gaps->sourceCrs()
 
  191  QStringList messages;
 
  195  multiStepFeedback.setCurrentStep( 1 );
 
  196  multiStepFeedback.setProgressText( QObject::tr( 
"Preparing features..." ) );
 
  197  std::unique_ptr<QgsVectorLayer> fixedLayer( input->materialize( 
QgsFeatureRequest() ) );
 
  199  QMap<QString, QgsFeaturePool *> featurePools;
 
  200  featurePools.insert( fixedLayer->id(), &featurePool );
 
  205    project->
addMapLayer( fixedLayer.get(), 
false, 
false );
 
  206    fixedLayer->startEditing();
 
  213  long long progression = 0;
 
  214  long long totalProgression = gaps->featureCount();
 
  215  multiStepFeedback.setCurrentStep( 2 );
 
  216  multiStepFeedback.setProgressText( QObject::tr( 
"Fixing errors..." ) );
 
  223    multiStepFeedback.setProgress( 
static_cast<double>( 
static_cast<long double>( progression ) / totalProgression ) * 100 );
 
  226    QVariant gapId = gapFeature.
attribute( errorIdFieldName );
 
  227    if ( !gapId.isValid() || gapId.isNull() )
 
  228      throw QgsProcessingException( QObject::tr( 
"NULL or invalid value found in field \"%1\"" ).arg( errorIdFieldName ) );
 
  233    const QString errorIdValue = gapFeature.
attribute( errorIdFieldName ).toString();
 
  237      QString neighborIdValue = f.
attribute( featIdFieldName ).toString();
 
  238      if ( inputFeatIdFieldType == QMetaType::QString )
 
  239        neighborIdValue = 
"'" + neighborIdValue + 
"'";
 
  241      if ( fixedLayer->getFeatures( 
QgsFeatureRequest().setFilterExpression( 
"\"" + featIdFieldName + 
"\" = " + neighborIdValue ) ).nextFeature( neighborFeature ) )
 
  242        neighborIds << neighborFeature.
id();
 
  245    QMap<QString, QgsFeatureIds> neighborsMap;
 
  246    neighborsMap.insert( fixedLayer->id(), neighborIds );
 
  258    check.fixError( featurePools, &gapError, method, QMap<QString, int>(), changes );
 
  262      resolutionMessage = QObject::tr( 
"Error is obsolete" );
 
  267      throw QgsProcessingException( writeFeatureError( sink_report.get(), parameters, QStringLiteral( 
"REPORT" ) ) );
 
  269  multiStepFeedback.setProgress( 100 );
 
  273    if ( !fixedLayer->commitChanges() )
 
  279  totalProgression = fixedLayer->featureCount();
 
  280  multiStepFeedback.setCurrentStep( 2 );
 
  281  multiStepFeedback.setProgressText( QObject::tr( 
"Exporting fixed layer..." ) );
 
  284  while ( fixedFeaturesIt.
nextFeature( fixedFeature ) )
 
  290    multiStepFeedback.setProgress( 
static_cast<double>( 
static_cast<long double>( progression ) / totalProgression ) * 100 );
 
  292      throw QgsProcessingException( writeFeatureError( sink_output.get(), parameters, QStringLiteral( 
"OUTPUT" ) ) );
 
  294  multiStepFeedback.setProgress( 100 );
 
  297  outputs.insert( QStringLiteral( 
"OUTPUT" ), dest_output );
 
  298  outputs.insert( QStringLiteral( 
"REPORT" ), dest_report );
 
  305  mTolerance = parameterAsInt( parameters, QStringLiteral( 
"TOLERANCE" ), context );
 
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
 
@ VectorPoint
Vector point layers.
 
@ VectorPolygon
Vector polygon layers.
 
@ Numeric
Accepts numeric fields.
 
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
 
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
 
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
 
Wrapper for iterator of features from vector data provider or vector layer.
 
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
 
Wraps a request for features to a vector layer (or directly its vector data provider).
 
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
 
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
 
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
 
void setFields(const QgsFields &fields, bool initAttributes=false)
Assigns a field map with the feature to allow attribute access by attribute name.
 
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
 
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
 
bool isCanceled() const
Tells whether the operation has been canceled already.
 
Encapsulate a field in an attribute table or data source.
 
Container of fields for a vector layer.
 
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
 
Base configuration for geometry checks.
 
@ StatusFixed
The error is fixed.
 
@ StatusObsolete
The error is obsolete because of other modifications.
 
Status status() const
The status of the error.
 
QString resolutionMessage() const
A message with details, how the error has been resolved.
 
Implements a resolution for problems detected in geometry checks.
 
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
 
An error produced by a QgsGeometryGapCheck.
 
Checks for gaps between neighbouring polygons.
 
QList< QgsGeometryCheckResolutionMethod > availableResolutionMethods() const override
Returns a list of available resolution methods.
 
@ CreateNewFeature
Create a new feature with the gap geometry.
 
@ MergeLongestEdge
Merge the gap with the polygon with the longest shared edge.
 
@ MergeLargestArea
Merge with neighbouring polygon with largest area.
 
QgsGeometry centroid() const
Returns the center of mass of a geometry.
 
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
 
Contains information about the context in which a processing algorithm is executed.
 
Custom exception class for processing related exceptions.
 
Base class for providing feedback from a processing algorithm.
 
Processing feedback object for multi-step operations.
 
An enum based parameter for processing algorithms, allowing for selection from predefined values.
 
A feature sink output for processing algorithms.
 
An input feature source (such as vector layers) parameter for processing algorithms.
 
A vector layer or feature source field parameter for processing algorithms.
 
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
 
void removeMapLayer(const QString &layerId)
Remove a layer from the registry by layer ID.
 
static QgsProject * instance()
Returns the QgsProject singleton instance.
 
QgsCoordinateTransformContext transformContext
 
QgsMapLayer * addMapLayer(QgsMapLayer *mapLayer, bool addToLegend=true, bool takeOwnership=true)
Add a layer to the map of loaded layers.
 
A rectangle specified with double values.
 
A feature pool based on a vector data provider.
 
QSet< QgsFeatureId > QgsFeatureIds