Skip to content
Permalink
Browse files

Add a message if a geometry was fixed

  • Loading branch information
lbartoletti authored and nyalldawson committed Feb 12, 2021
1 parent 282ccb9 commit 7e7732218b751cd5d2b0452f780d5cbba8079afc
@@ -1921,7 +1921,8 @@ Modifies geometry to avoid intersections with the layers specified in project pr
:return: 0 in case of success,
1 if geometry is not of polygon type,
2 if avoid intersection would change the geometry type,
3 other error during intersection removal
3 other error during intersection removal,
4 in case of success but at least one geometry intersected was invalid and fixed to perform the operation

.. versionadded:: 1.5
%End
@@ -2603,12 +2603,19 @@ int QgsGeometry::avoidIntersections( const QList<QgsVectorLayer *> &avoidInterse
}

bool haveGeometryError = false;
std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, haveGeometryError, ignoreFeatures );
bool hadInvalidGeometry = false;
std::unique_ptr< QgsAbstractGeometry > diffGeom = QgsGeometryEditUtils::avoidIntersections( *( d->geometry ), avoidIntersectionsLayers, hadInvalidGeometry, haveGeometryError, ignoreFeatures );
if ( diffGeom )
{
reset( std::move( diffGeom ) );
}
return haveGeometryError ? 3 : 0;

if ( haveGeometryError )
return 3;
if ( hadInvalidGeometry )
return 4;

return 0;
}


@@ -2016,7 +2016,8 @@ class CORE_EXPORT QgsGeometry
* \returns 0 in case of success,
* 1 if geometry is not of polygon type,
* 2 if avoid intersection would change the geometry type,
* 3 other error during intersection removal
* 3 other error during intersection removal,
* 4 in case of success but at least one geometry intersected was invalid and fixed to perform the operation
* \since QGIS 1.5
*/
int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
@@ -224,10 +224,14 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry *geom, int partNum )

std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( const QgsAbstractGeometry &geom,
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
bool &hadInvalidGeometry,
bool &haveGeometryError,
const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures
)
{

haveGeometryError = false;
hadInvalidGeometry = false;
std::unique_ptr<QgsGeometryEngine> geomEngine( QgsGeometry::createGeometryEngine( &geom ) );
if ( !geomEngine )
{
@@ -267,9 +271,13 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( c
if ( !f.hasGeometry() )
continue;

if ( !f.geometry().isGeosValid() )
hadInvalidGeometry = true;

QgsGeometry geomValid = f.geometry().makeValid();
if ( geomValid.isNull() )
haveGeometryError = true;

nearGeometries << geomValid;

}
@@ -71,11 +71,13 @@ class QgsGeometryEditUtils
* Alters a geometry so that it avoids intersections with features from all open vector layers.
* \param geom geometry to alter
* \param avoidIntersectionsLayers list of layers to check for intersections
* \param hadInvalidGeometry returns true if at least one geometry intersected was invalid.
* \param haveGeometryError the method will use GEOS to fix the geometries, if at least one geometry cannot be fixed, it returns false (The geometry, may not be modified.)
* \param ignoreFeatures map of layer to feature id of features to ignore
*/
static std::unique_ptr< QgsAbstractGeometry > avoidIntersections( const QgsAbstractGeometry &geom,
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
bool &hadInvalidGeometry,
bool &haveGeometryError,
const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
};
@@ -341,9 +341,14 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsGeometry featGeom = f->geometry();
int avoidIntersectionsReturn = featGeom.avoidIntersections( avoidIntersectionsLayers );
f->setGeometry( featGeom );
if ( avoidIntersectionsReturn == 3 )
switch ( avoidIntersectionsReturn )
{
emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid and cannot be fixed automaticaly. The geometry added may overlap another geometry. You should fix geometries." ), Qgis::Warning );
case 3:
emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid and cannot be fixed automaticaly. The geometry added may overlap another geometry. You should fix geometries." ), Qgis::Warning );
break;
case 4:
emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid and has been modified to perform the operation. You should fix geometries." ), Qgis::Warning );
break;
}
if ( f->geometry().isEmpty() ) //avoid intersection might have removed the whole geometry
{

0 comments on commit 7e77322

Please sign in to comment.