Skip to content

Commit

Permalink
Possibility to ignore features in the avoid intersection function
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Sep 25, 2012
1 parent 9a129cc commit efc4cb6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/core/qgsgeometry.cpp
Expand Up @@ -6696,7 +6696,7 @@ bool QgsGeometry::deletePart( int partNum )
return true;
}

int QgsGeometry::avoidIntersections()
int QgsGeometry::avoidIntersections( QMap<QgsVectorLayer*, QSet<qint64> > ignoreFeatures )
{
int returnValue = 0;

Expand Down Expand Up @@ -6724,7 +6724,14 @@ int QgsGeometry::avoidIntersections()
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
if ( currentLayer )
{
if ( currentLayer->removePolygonIntersections( this ) != 0 )
QgsFeatureIds ignoreIds;
QMap<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find( currentLayer );
if ( ignoreIt != ignoreFeatures.constEnd() )
{
ignoreIds = ignoreIt.value();
}

if ( currentLayer->removePolygonIntersections( this, ignoreIds ) != 0 )
{
returnValue = 3;
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsgeometry.h
Expand Up @@ -30,6 +30,9 @@ email : morb at ozemail dot com dot au

#include "qgspoint.h"
#include "qgscoordinatetransform.h"
#include <QSet>

class QgsVectorLayer;

/** polyline is represented as a vector of points */
typedef QVector<QgsPoint> QgsPolyline;
Expand Down Expand Up @@ -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<QgsVectorLayer*, QSet<qint64> > ignoreFeatures = QMap<QgsVectorLayer*, QSet<qint64> >() );

class Error
{
Expand Down
15 changes: 10 additions & 5 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -2489,7 +2489,7 @@ int QgsVectorLayer::splitFeatures( const QList<QgsPoint>& splitLine, bool topolo
return returnCode;
}

int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom )
int QgsVectorLayer::removePolygonIntersections( QgsGeometry* geom, QgsFeatureIds ignoreFeatures )
{
if ( !hasGeometryType() )
return 1;
Expand All @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -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
Expand Down

0 comments on commit efc4cb6

Please sign in to comment.