Skip to content
Permalink
Browse files
move QgsMapToolFeature::avoidIntersections to QgsGeometry
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12700 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 7, 2010
1 parent 5a1d9a9 commit d25a9c4c1fdd63d9ef958ec6407a72257fed47ac
Showing with 69 additions and 58 deletions.
  1. +9 −0 python/core/qgsgeometry.sip
  2. +2 −4 src/app/gps/qgsgpsinformationwidget.cpp
  3. +1 −45 src/app/qgsmaptooladdfeature.cpp
  4. +1 −9 src/app/qgsmaptooladdfeature.h
  5. +48 −0 src/core/qgsgeometry.cpp
  6. +8 −0 src/core/qgsgeometry.h
@@ -314,5 +314,14 @@ not disjoint with existing polygons of the feature*/
@return true in case of success and false else*/
bool convertToMultiType();

/** Modifies geometry to avoid intersections with the layers specified in project properties
* @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
* @note added in 1.5
*/
int avoidIntersections();

}; // class QgsGeometry

@@ -30,6 +30,7 @@
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsattributedialog.h"
#include "qgsgeometry.h"

//for avoid intersections static method
#include "qgsmaptooladdfeature.h"
@@ -449,9 +450,6 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
mGPSTextEdit->append( "hdop: " + QString::number( info.hdop ) );
mGPSTextEdit->append( "vdop: " + QString::number( info.vdop ) );




// Avoid refreshing / panning if we havent moved
if ( mLastGpsPosition != myNewCenter )
{
@@ -768,7 +766,7 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )
memcpy( &wkb[position], &y, sizeof( double ) );
f->setGeometryAndOwnership( &wkb[0], size );

int avoidIntersectionsReturn = QgsMapToolAddFeature::avoidIntersections( f->geometry() );
int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
if ( avoidIntersectionsReturn == 1 )
{
//not a polygon type. Impossible to get there
@@ -443,7 +443,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
}
f->setGeometryAndOwnership( &wkb[0], size );

int avoidIntersectionsReturn = avoidIntersections( f->geometry() );
int avoidIntersectionsReturn = f->geometry()->avoidIntersections();
if ( avoidIntersectionsReturn == 1 )
{
//not a polygon type. Impossible to get there
@@ -519,47 +519,3 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
}
}
}

int QgsMapToolAddFeature::avoidIntersections( QgsGeometry* g )
{
int returnValue = 0;

//check if g has polygon type
if ( !g || g->type() != QGis::Polygon )
{
return 1;
}

QGis::WkbType geomTypeBeforeModification = g->wkbType();

//read avoid intersections list from project properties
bool listReadOk;
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
if ( !listReadOk )
{
return true; //no intersections stored in project does not mean error
}

//go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
QgsVectorLayer* currentLayer = 0;
QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
{
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
if ( currentLayer )
{
if ( currentLayer->removePolygonIntersections( g ) != 0 )
{
returnValue = 3;
}
}
}

//make sure the geometry still has the same type (e.g. no change from polygon to multipolygon)
if ( g->wkbType() != geomTypeBeforeModification )
{
return 2;
}

return returnValue;
}
@@ -21,15 +21,7 @@ class QgsMapToolAddFeature: public QgsMapToolCapture
{
Q_OBJECT
public:
QgsMapToolAddFeature( QgsMapCanvas* canvas, enum CaptureMode tool );
QgsMapToolAddFeature( QgsMapCanvas* canvas, CaptureMode mode );
virtual ~QgsMapToolAddFeature();
void canvasReleaseEvent( QMouseEvent * e );

/**Modifies geometry to avoid intersections with the layers specified in project properties
@return 0 in case of success,
@return 1 if geometry is not of polygon type,
@return 2 if avoid intersection would change the geometry type, \
3 other error during intersection removal
@note Consider moving this into analysis lib since it is now used by QgsGpsInformation too. */
static int avoidIntersections( QgsGeometry* g );
};
@@ -27,6 +27,10 @@ email : morb at ozemail dot com dot au
#include "qgsrectangle.h"
#include "qgslogger.h"

#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"

#define DEFAULT_QUADRANT_SEGMENTS 8

#define CATCH_GEOS(r) \
@@ -6210,3 +6214,47 @@ bool QgsGeometry::deletePart( int partNum )

return TRUE;
}

int QgsGeometry::avoidIntersections()
{
int returnValue = 0;

//check if g has polygon type
if ( type() != QGis::Polygon )
{
return 1;
}

QGis::WkbType geomTypeBeforeModification = wkbType();

//read avoid intersections list from project properties
bool listReadOk;
QStringList avoidIntersectionsList = QgsProject::instance()->readListEntry( "Digitizing", "/AvoidIntersectionsList", &listReadOk );
if ( !listReadOk )
{
return true; //no intersections stored in project does not mean error
}

//go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
QgsVectorLayer* currentLayer = 0;
QStringList::const_iterator aIt = avoidIntersectionsList.constBegin();
for ( ; aIt != avoidIntersectionsList.constEnd(); ++aIt )
{
currentLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( *aIt ) );
if ( currentLayer )
{
if ( currentLayer->removePolygonIntersections( this ) != 0 )
{
returnValue = 3;
}
}
}

//make sure the geometry still has the same type (e.g. no change from polygon to multipolygon)
if ( wkbType() != geomTypeBeforeModification )
{
return 2;
}

return returnValue;
}
@@ -353,6 +353,14 @@ class CORE_EXPORT QgsGeometry
@return true in case of success and false else*/
bool convertToMultiType();

/** Modifies geometry to avoid intersections with the layers specified in project properties
* @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
* @note added in 1.5
*/
int avoidIntersections();

private:
// Private variables

0 comments on commit d25a9c4

Please sign in to comment.