Skip to content

Commit

Permalink
Merge pull request #8103 from m-kuhn/geometryValidatorCode_1
Browse files Browse the repository at this point in the history
Geometry validation of editing session
  • Loading branch information
m-kuhn committed Oct 16, 2018
2 parents ee8e1ce + 6c97fcf commit 190f938
Show file tree
Hide file tree
Showing 70 changed files with 2,698 additions and 263 deletions.
Expand Up @@ -15,6 +15,12 @@ class QgsFeaturePool : QgsFeatureSink /Abstract/
{
%Docstring
A feature pool is based on a vector layer and caches features.

.. note::

This class is a technology preview and unstable API.

.. versionadded:: 3.4
%End

%TypeHeaderCode
Expand All @@ -31,6 +37,7 @@ It will be retrieved from the cache or from the underlying layer if unavailable.
If the feature is neither available from the cache nor from the layer it will return false.
%End


virtual void updateFeature( QgsFeature &feature ) = 0;
%Docstring
Updates a feature in this pool.
Expand Down Expand Up @@ -89,6 +96,7 @@ To be used by implementations of ``deleteFeature``.
%End



private:
QgsFeaturePool( const QgsFeaturePool &other );
};
Expand Down
Expand Up @@ -10,24 +10,19 @@




class QgsGeometryCheck
{
%Docstring
*************************************************************************
qgsgeometrycheck.h
---------------------
begin : September 2014
copyright : (C) 2014 by Sandro Mani / Sourcepole AG
email : smani at sourcepole dot ch
**************************************************************************

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. *

**************************************************************************
This class manages all known geometry check factories.

QgsGeometryCheckRegistry is not usually directly created, but rather accessed through
:py:func:`QgsAnalysis.geometryCheckRegistry()`

.. note::

This class is a technology preview and unstable API.

.. versionadded:: 3.4
%End

%TypeHeaderCode
Expand Down Expand Up @@ -120,7 +115,7 @@ A list of geometry types for which this check can be performed.
Flags for this geometry check.
%End

virtual void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors /In,Out/, QStringList &messages /In,Out/, QgsFeedback *feedback = 0, const LayerFeatureIds &ids = QgsGeometryCheck::LayerFeatureIds() ) const = 0;
virtual void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors /In,Out/, QStringList &messages /In,Out/, QgsFeedback *feedback, const LayerFeatureIds &ids = QgsGeometryCheck::LayerFeatureIds() ) const = 0;
%Docstring
The main worker method.
Check all features available from ``featurePools`` and write errors found to ``errors``.
Expand Down
Expand Up @@ -11,18 +11,16 @@




class QgsGeometryCheckError
{
%Docstring
*************************************************************************
This represents an error reported by a geometry check.

.. note::

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. *
This class is a technology preview and unstable API.

**************************************************************************
.. versionadded:: 3.4
%End

%TypeHeaderCode
Expand Down
Expand Up @@ -10,17 +10,18 @@




class QgsGeometryCheckerUtils
{
%Docstring
*************************************************************************

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. *
Contains utilities required for geometry checks.

.. note::

This class is a technology preview and unstable API.

**************************************************************************
.. versionadded:: 3.4
%End

%TypeHeaderCode
Expand Down
Expand Up @@ -14,6 +14,16 @@

class QgsGeometryCheckFactory /Abstract/
{
%Docstring

A factory for geometry checks.

.. note::

This class is a technology preview and unstable API.

.. versionadded:: 3.4
%End

%TypeHeaderCode
#include "qgsgeometrycheckfactory.h"
Expand Down
Expand Up @@ -19,6 +19,10 @@ This class manages all known geometry check factories.
QgsGeometryCheckRegistry is not usually directly created, but rather accessed through
:py:func:`QgsAnalysis.geometryCheckRegistry()`

.. note::

This class is a technology preview and unstable API.

.. versionadded:: 3.4
%End

Expand Down
Expand Up @@ -17,6 +17,10 @@ class QgsSingleGeometryCheckError

An error from a QgsSingleGeometryCheck.

.. note::

This class is a technology preview and unstable API.

.. versionadded:: 3.4
%End

Expand Down Expand Up @@ -78,6 +82,10 @@ class QgsGeometryCheckErrorSingle : QgsGeometryCheckError
Wraps a QgsSingleGeometryError into a standard :py:class:`QgsGeometryCheckError`.
The single error can be obtained via singleError.

.. note::

This class is a technology preview and unstable API.

.. versionadded:: 3.4
%End

Expand Down
63 changes: 62 additions & 1 deletion python/core/auto_generated/qgsgeometryoptions.sip.in
Expand Up @@ -9,7 +9,8 @@



class QgsGeometryOptions

class QgsGeometryOptions : QObject
{
%Docstring

Expand Down Expand Up @@ -72,6 +73,34 @@ Determines if at least one fix is enabled.
%Docstring
Apply any fixes configured on this class to ``geometry``.

.. versionadded:: 3.4
%End

QStringList geometryChecks() const;
%Docstring
A list of activated geometry checks.

.. versionadded:: 3.4
%End

void setGeometryChecks( const QStringList &geometryChecks );
%Docstring
A list of activated geometry checks.

.. versionadded:: 3.4
%End

QVariantMap checkConfiguration( const QString &checkId ) const;
%Docstring
Access the configuration for the check ``checkId``.

.. versionadded:: 3.4
%End

void setCheckConfiguration( const QString &checkId, const QVariantMap &checkConfiguration );
%Docstring
Set the configuration for the check ``checkId``.

.. versionadded:: 3.4
%End

Expand All @@ -86,6 +115,38 @@ Write the geometry options to the ``node``.
%Docstring
Read the geometry options from ``node``.

.. versionadded:: 3.4
%End

signals:

void checkConfigurationChanged();
%Docstring
Access the configuration for the check ``checkId``.

.. versionadded:: 3.4
%End

void geometryChecksChanged();
%Docstring
A list of activated geometry checks.

.. versionadded:: 3.4
%End

void removeDuplicateNodesChanged();
%Docstring
Automatically remove duplicate nodes on all geometries which are edited on this layer.

.. versionadded:: 3.4
%End

void geometryPrecisionChanged();
%Docstring
The precision in which geometries on this layer should be saved.
Geometries which are edited on this layer will be rounded to multiples of this value (snap to grid).
Set to 0.0 to disable.

.. versionadded:: 3.4
%End

Expand Down
2 changes: 1 addition & 1 deletion python/core/core_auto.sip
Expand Up @@ -54,7 +54,6 @@
%Include auto_generated/qgsfields.sip
%Include auto_generated/qgsfileutils.sip
%Include auto_generated/qgsfontutils.sip
%Include auto_generated/qgsgeometryoptions.sip
%Include auto_generated/qgsgeometrysimplifier.sip
%Include auto_generated/qgshistogram.sip
%Include auto_generated/qgshstoreutils.sip
Expand Down Expand Up @@ -327,6 +326,7 @@
%Include auto_generated/qgsfieldproxymodel.sip
%Include auto_generated/qgsfiledownloader.sip
%Include auto_generated/qgsfeaturefiltermodel.sip
%Include auto_generated/qgsgeometryoptions.sip
%Include auto_generated/qgsgeometryvalidator.sip
%Include auto_generated/qgsgml.sip
%Include auto_generated/qgsgmlschema.sip
Expand Down
7 changes: 3 additions & 4 deletions src/analysis/CMakeLists.txt
Expand Up @@ -152,7 +152,6 @@ SET(QGIS_ANALYSIS_SRCS
vector/geometry_checker/qgsgeometryduplicatecheck.cpp
vector/geometry_checker/qgsgeometryduplicatenodescheck.cpp
vector/geometry_checker/qgsgeometryfollowboundariescheck.cpp
vector/geometry_checker/qgsgeometrymissingvertexcheck.cpp
vector/geometry_checker/qgsgeometrygapcheck.cpp
vector/geometry_checker/qgsgeometrymissingvertexcheck.cpp
vector/geometry_checker/qgsgeometryholecheck.cpp
Expand Down Expand Up @@ -186,6 +185,9 @@ SET(QGIS_ANALYSIS_MOC_HDRS

vector/geometry_checker/qgsgeometrychecker.h
vector/geometry_checker/qgsgeometrycheck.h
vector/geometry_checker/qgsvectorlayerfeaturepool.h
vector/geometry_checker/qgsgeometrygapcheck.h
vector/geometry_checker/qgsgeometrymissingvertexcheck.h
)

INCLUDE_DIRECTORIES(SYSTEM ${SPATIALITE_INCLUDE_DIR})
Expand Down Expand Up @@ -252,7 +254,6 @@ SET(QGIS_ANALYSIS_HDRS
vector/geometry_checker/qgsgeometrycheckerutils.h
vector/geometry_checker/qgsfeaturepool.h
vector/geometry_checker/qgsvectordataproviderfeaturepool.h
vector/geometry_checker/qgsvectorlayerfeaturepool.h

interpolation/qgsinterpolator.h
interpolation/qgsgridfilewriter.h
Expand Down Expand Up @@ -292,8 +293,6 @@ SET(QGIS_ANALYSIS_HDRS
vector/geometry_checker/qgsgeometryduplicatecheck.h
vector/geometry_checker/qgsgeometryduplicatenodescheck.h
vector/geometry_checker/qgsgeometryfollowboundariescheck.h
vector/geometry_checker/qgsgeometrygapcheck.h
vector/geometry_checker/qgsgeometrymissingvertexcheck.h
vector/geometry_checker/qgsgeometryholecheck.h
vector/geometry_checker/qgsgeometrylineintersectioncheck.h
vector/geometry_checker/qgsgeometrylinelayerintersectioncheck.h
Expand Down
22 changes: 22 additions & 0 deletions src/analysis/vector/geometry_checker/qgsfeaturepool.cpp
Expand Up @@ -62,6 +62,23 @@ bool QgsFeaturePool::getFeature( QgsFeatureId id, QgsFeature &feature )
return true;
}

QgsFeatureIds QgsFeaturePool::getFeatures( const QgsFeatureRequest &request )
{
QgsFeatureIds fids;

std::unique_ptr<QgsVectorLayerFeatureSource> source = QgsVectorLayerUtils::getFeatureSource( mLayer );

QgsFeatureIterator it = source->getFeatures( request );
QgsFeature feature;
while ( it.nextFeature( feature ) )
{
insertFeature( feature );
fids << feature.id();
}

return fids;
}

QgsFeatureIds QgsFeaturePool::allFeatureIds() const
{
return mFeatureIds;
Expand Down Expand Up @@ -123,6 +140,11 @@ void QgsFeaturePool::setFeatureIds( const QgsFeatureIds &ids )
mFeatureIds = ids;
}

bool QgsFeaturePool::isFeatureCached( QgsFeatureId fid )
{
return mFeatureCache.contains( fid );
}

QgsCoordinateReferenceSystem QgsFeaturePool::crs() const
{
return mCrs;
Expand Down
20 changes: 20 additions & 0 deletions src/analysis/vector/geometry_checker/qgsfeaturepool.h
Expand Up @@ -31,6 +31,9 @@ class QgsVectorLayer;
/**
* \ingroup analysis
* A feature pool is based on a vector layer and caches features.
*
* \note This class is a technology preview and unstable API.
* \since QGIS 3.4
*/
class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
{
Expand All @@ -46,6 +49,15 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
*/
bool getFeature( QgsFeatureId id, QgsFeature &feature );

/**
* Get features for the provided \a request. No features will be fetched
* from the cache and the request is sent directly to the underlying feature source.
* Results of the request are cached in the pool and the ids of all the features
* are returned. This can be used to warm the cache for a particular area of interest
* (bounding box) or other set of features.
*/
QgsFeatureIds getFeatures( const QgsFeatureRequest &request ) SIP_SKIP;

/**
* Updates a feature in this pool.
* Implementations will update the feature on the layer or on the data provider.
Expand Down Expand Up @@ -136,6 +148,14 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
*/
void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP;

/**
* Checks if the feature \a fid is cached.
*
* \note not available in Python bindings
* \since QGIS 3.4
*/
bool isFeatureCached( QgsFeatureId fid ) SIP_SKIP;

private:
#ifdef SIP_RUN
QgsFeaturePool( const QgsFeaturePool &other )
Expand Down
Expand Up @@ -34,7 +34,7 @@ class ANALYSIS_EXPORT QgsGeometryAngleCheck : public QgsGeometryCheck
, mMinAngle( configuration.value( QStringLiteral( "minAngle" ), 0.0 ).toDouble() )
{}

void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback = nullptr, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;

QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override;
Expand Down

0 comments on commit 190f938

Please sign in to comment.