Skip to content
Permalink
Browse files

Remove automagic fix and tiny refacto

  • Loading branch information
lbartoletti authored and nyalldawson committed Feb 12, 2021
1 parent aa95fd0 commit e336b831c2e25bdd4bb4682326146ae261cfa0b3
@@ -1921,8 +1921,7 @@ 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,
4 in case of success but at least one geometry intersected was invalid and fixed to perform the operation
3 at least one geometry intersected is invalid. The algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries.

.. versionadded:: 1.5
%End
@@ -1322,7 +1322,7 @@ void QgsGpsInformationWidget::mBtnCloseFeature_clicked()
}
else if ( avoidIntersectionsReturn == 3 )
{
QgisApp::instance()->messageBar()->pushCritical( tr( "Add Feature" ), tr( "An error was reported during intersection removal." ) );
QgisApp::instance()->messageBar()->pushCritical( tr( "Add Feature" ), tr( "The feature has been added, but at least one geometry intersected is invalid. You should fix geometries." ) );
connectGpsSlot();
return;
}
@@ -179,7 +179,7 @@ void QgsMapToolReshape::reshape( QgsVectorLayer *vlayer )
if ( avoidIntersectionsLayers.size() > 0 )
{
res = geom.avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers(), ignoreFeatures );
if ( res == 1 || res == 3 )
if ( res == 1 )
{
emit messageEmitted( tr( "An error was reported during intersection removal" ), Qgis::Critical );
vlayer->destroyEditCommand();
@@ -194,7 +194,7 @@ void QgsMapToolReshape::reshape( QgsVectorLayer *vlayer )
vlayer->destroyEditCommand();
return;
}
if ( res == 2 || res == 4 )
if ( res == 3 )
{
emit messageEmitted( tr( "At least one geometry intersected is invalid. You should fix geometries." ), Qgis::Warning );
}
@@ -2604,19 +2604,16 @@ int QgsGeometry::avoidIntersections( const QList<QgsVectorLayer *> &avoidInterse

QgsWkbTypes::Type geomTypeBeforeModification = wkbType();

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

if ( geomTypeBeforeModification != wkbType() )
return 2;
if ( haveGeometryError )
return 3;
if ( hadInvalidGeometry )
if ( haveInvalidGeometry )
return 4;

return 0;
@@ -2016,8 +2016,7 @@ 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,
* 4 in case of success but at least one geometry intersected was invalid and fixed to perform the operation
* 3 at least one geometry intersected is invalid. The algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries.
* \since QGIS 1.5
*/
int avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
@@ -224,14 +224,12 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry *geom, int partNum )

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

haveGeometryError = false;
hadInvalidGeometry = false;
haveInvalidGeometry = false;
std::unique_ptr<QgsGeometryEngine> geomEngine( QgsGeometry::createGeometryEngine( &geom ) );
if ( !geomEngine )
{
@@ -272,14 +270,9 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeometryEditUtils::avoidIntersections( c
continue;

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

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

nearGeometries << geomValid;
haveInvalidGeometry = true;

nearGeometries << f.geometry();
}
}

@@ -71,14 +71,12 @@ 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 haveInvalidGeometry returns true if at least one geometry intersected is invalid. In this case, the algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries.
* \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,
bool &haveInvalidGeometry,
const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
};

@@ -341,14 +341,9 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QgsGeometry featGeom = f->geometry();
int avoidIntersectionsReturn = featGeom.avoidIntersections( avoidIntersectionsLayers );
f->setGeometry( featGeom );
switch ( avoidIntersectionsReturn )
if ( avoidIntersectionsReturn == 3 )
{
case 3:
emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid and cannot be fixed automatically. 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;
emit messageEmitted( tr( "The feature has been added, but at least one geometry intersected is invalid. You should fix geometries." ), Qgis::Warning );
}
if ( f->geometry().isEmpty() ) //avoid intersection might have removed the whole geometry
{

0 comments on commit e336b83

Please sign in to comment.