diff --git a/src/core/qgsgeometry.cpp b/src/core/qgsgeometry.cpp index 2c65bb4c72b..51ad2213693 100644 --- a/src/core/qgsgeometry.cpp +++ b/src/core/qgsgeometry.cpp @@ -6696,7 +6696,7 @@ bool QgsGeometry::deletePart( int partNum ) return true; } -int QgsGeometry::avoidIntersections() +int QgsGeometry::avoidIntersections( QMap > ignoreFeatures ) { int returnValue = 0; @@ -6724,7 +6724,14 @@ int QgsGeometry::avoidIntersections() currentLayer = dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) ); if ( currentLayer ) { - if ( currentLayer->removePolygonIntersections( this ) != 0 ) + QgsFeatureIds ignoreIds; + QMap >::const_iterator ignoreIt = ignoreFeatures.find( currentLayer ); + if ( ignoreIt != ignoreFeatures.constEnd() ) + { + ignoreIds = ignoreIt.value(); + } + + if ( currentLayer->removePolygonIntersections( this, ignoreIds ) != 0 ) { returnValue = 3; } diff --git a/src/core/qgsgeometry.h b/src/core/qgsgeometry.h index e0b8c47ceb9..70c43070f79 100644 --- a/src/core/qgsgeometry.h +++ b/src/core/qgsgeometry.h @@ -30,6 +30,9 @@ email : morb at ozemail dot com dot au #include "qgspoint.h" #include "qgscoordinatetransform.h" +#include + +class QgsVectorLayer; /** polyline is represented as a vector of points */ typedef QVector QgsPolyline; @@ -429,9 +432,10 @@ class CORE_EXPORT QgsGeometry * 1 if geometry is not of polygon type, * 2 if avoid intersection would change the geometry type, * 3 other error during intersection removal + * @ignoreFeatures possibility to give a list of features where intersections should be ignored * @note added in 1.5 */ - int avoidIntersections(); + int avoidIntersections( QMap > ignoreFeatures = QMap >() ); class Error { diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 85d13a608f3..1b45bb312da 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -430,8 +430,8 @@ unsigned char *QgsVectorLayer::drawLineString( unsigned char *feature, QgsRender // the rest of them so end the loop at that point. for ( int i = 0; i < nPoints; ++i ) { - if ( qAbs( x.at(i) ) > QgsClipper::MAX_X || - qAbs( y.at(i) ) > QgsClipper::MAX_Y ) + if ( qAbs( x.at( i ) ) > QgsClipper::MAX_X || + qAbs( y.at( i ) ) > QgsClipper::MAX_Y ) { QgsClipper::trimFeature( x, y, true ); // true = polyline nPoints = x.size(); // trimming may change nPoints. @@ -443,8 +443,8 @@ unsigned char *QgsVectorLayer::drawLineString( unsigned char *feature, QgsRender QPolygonF pa( nPoints ); for ( int i = 0; i < nPoints; ++i ) { - pa[i].setX( x.at(i) ); - pa[i].setY( y.at(i) ); + pa[i].setX( x.at( i ) ); + pa[i].setY( y.at( i ) ); } // The default pen gives bevelled joins between segements of the @@ -2489,7 +2489,7 @@ int QgsVectorLayer::splitFeatures( const QList& splitLine, bool topolo return returnCode; } -int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom ) +int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom, QgsFeatureIds ignoreFeatures ) { if ( !hasGeometryType() ) return 1; @@ -2511,6 +2511,11 @@ int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom ) QgsFeature f; while ( nextFeature( f ) ) { + if ( ignoreFeatures.contains( f.id() ) ) + { + continue; + } + //call geometry->makeDifference for each feature QgsGeometry *currentGeom = f.geometry(); if ( currentGeom ) diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index 9928934d26d..6be26e30fff 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -442,9 +442,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer /**Changes the specified geometry such that it has no intersections with other * polygon (or multipolygon) geometries in this vector layer * @param geom geometry to modify + * @param ignoreFeatures list of feature ids where intersections should be ignored * @return 0 in case of success */ - int removePolygonIntersections( QgsGeometry* geom ); + int removePolygonIntersections( QgsGeometry* geom, QgsFeatureIds ignoreFeatures = QgsFeatureIds() ); /** Adds topological points for every vertex of the geometry. * @param geom the geometry where each vertex is added to segments of other features