Skip to content

Commit efc4cb6

Browse files
author
Marco Hugentobler
committedSep 25, 2012
Possibility to ignore features in the avoid intersection function
1 parent 9a129cc commit efc4cb6

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6696,7 +6696,7 @@ bool QgsGeometry::deletePart( int partNum )
66966696
return true;
66976697
}
66986698

6699-
int QgsGeometry::avoidIntersections()
6699+
int QgsGeometry::avoidIntersections( QMap<QgsVectorLayer*, QSet<qint64> > ignoreFeatures )
67006700
{
67016701
int returnValue = 0;
67026702

@@ -6724,7 +6724,14 @@ int QgsGeometry::avoidIntersections()
67246724
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
67256725
if ( currentLayer )
67266726
{
6727-
if ( currentLayer->removePolygonIntersections( this ) != 0 )
6727+
QgsFeatureIds ignoreIds;
6728+
QMap<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find( currentLayer );
6729+
if ( ignoreIt != ignoreFeatures.constEnd() )
6730+
{
6731+
ignoreIds = ignoreIt.value();
6732+
}
6733+
6734+
if ( currentLayer->removePolygonIntersections( this, ignoreIds ) != 0 )
67286735
{
67296736
returnValue = 3;
67306737
}

‎src/core/qgsgeometry.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ email : morb at ozemail dot com dot au
3030

3131
#include "qgspoint.h"
3232
#include "qgscoordinatetransform.h"
33+
#include <QSet>
34+
35+
class QgsVectorLayer;
3336

3437
/** polyline is represented as a vector of points */
3538
typedef QVector<QgsPoint> QgsPolyline;
@@ -429,9 +432,10 @@ class CORE_EXPORT QgsGeometry
429432
* 1 if geometry is not of polygon type,
430433
* 2 if avoid intersection would change the geometry type,
431434
* 3 other error during intersection removal
435+
* @ignoreFeatures possibility to give a list of features where intersections should be ignored
432436
* @note added in 1.5
433437
*/
434-
int avoidIntersections();
438+
int avoidIntersections( QMap<QgsVectorLayer*, QSet<qint64> > ignoreFeatures = QMap<QgsVectorLayer*, QSet<qint64> >() );
435439

436440
class Error
437441
{

‎src/core/qgsvectorlayer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ unsigned char *QgsVectorLayer::drawLineString( unsigned char *feature, QgsRender
430430
// the rest of them so end the loop at that point.
431431
for ( int i = 0; i < nPoints; ++i )
432432
{
433-
if ( qAbs( x.at(i) ) > QgsClipper::MAX_X ||
434-
qAbs( y.at(i) ) > QgsClipper::MAX_Y )
433+
if ( qAbs( x.at( i ) ) > QgsClipper::MAX_X ||
434+
qAbs( y.at( i ) ) > QgsClipper::MAX_Y )
435435
{
436436
QgsClipper::trimFeature( x, y, true ); // true = polyline
437437
nPoints = x.size(); // trimming may change nPoints.
@@ -443,8 +443,8 @@ unsigned char *QgsVectorLayer::drawLineString( unsigned char *feature, QgsRender
443443
QPolygonF pa( nPoints );
444444
for ( int i = 0; i < nPoints; ++i )
445445
{
446-
pa[i].setX( x.at(i) );
447-
pa[i].setY( y.at(i) );
446+
pa[i].setX( x.at( i ) );
447+
pa[i].setY( y.at( i ) );
448448
}
449449

450450
// The default pen gives bevelled joins between segements of the
@@ -2489,7 +2489,7 @@ int QgsVectorLayer::splitFeatures( const QList<QgsPoint>& splitLine, bool topolo
24892489
return returnCode;
24902490
}
24912491

2492-
int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom )
2492+
int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom, QgsFeatureIds ignoreFeatures )
24932493
{
24942494
if ( !hasGeometryType() )
24952495
return 1;
@@ -2511,6 +2511,11 @@ int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom )
25112511
QgsFeature f;
25122512
while ( nextFeature( f ) )
25132513
{
2514+
if ( ignoreFeatures.contains( f.id() ) )
2515+
{
2516+
continue;
2517+
}
2518+
25142519
//call geometry->makeDifference for each feature
25152520
QgsGeometry *currentGeom = f.geometry();
25162521
if ( currentGeom )

‎src/core/qgsvectorlayer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
442442
/**Changes the specified geometry such that it has no intersections with other
443443
* polygon (or multipolygon) geometries in this vector layer
444444
* @param geom geometry to modify
445+
* @param ignoreFeatures list of feature ids where intersections should be ignored
445446
* @return 0 in case of success
446447
*/
447-
int removePolygonIntersections( QgsGeometry* geom );
448+
int removePolygonIntersections( QgsGeometry* geom, QgsFeatureIds ignoreFeatures = QgsFeatureIds() );
448449

449450
/** Adds topological points for every vertex of the geometry.
450451
* @param geom the geometry where each vertex is added to segments of other features

0 commit comments

Comments
 (0)
Please sign in to comment.