Skip to content
Permalink
Browse files

Possibility to ignore features in the avoid intersection function

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 25, 2012
1 parent 9a129cc commit efc4cb68dd8e48a68d1a991b95d531437a0421b0
Showing with 26 additions and 9 deletions.
  1. +9 −2 src/core/qgsgeometry.cpp
  2. +5 −1 src/core/qgsgeometry.h
  3. +10 −5 src/core/qgsvectorlayer.cpp
  4. +2 −1 src/core/qgsvectorlayer.h
@@ -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;

@@ -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;
}
@@ -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;
@@ -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
{
@@ -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<QgsPoint>& 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 )
@@ -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

0 comments on commit efc4cb6

Please sign in to comment.
You can’t perform that action at this time.