Skip to content

Commit 7661f4b

Browse files
author
timlinux
committed
Improvements to spatial select plugin from Luiz Motta (#2634)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15137 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e106293 commit 7661f4b

7 files changed

+701
-380
lines changed

src/plugins/spatialquery/qgsspatialquery.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18-
/* $Id$ */
18+
/* $Id: qgsspatialquery.cpp 13447 2010-05-09 00:45:17Z jef $ */
1919

2020
#include <QMessageBox>
2121

@@ -50,7 +50,8 @@ void QgsSpatialQuery::setSelectedFeaturesReference( bool useSelected )
5050

5151
} // void QgsSpatialQuery::setSelectedFeaturesReference(bool useSelected)
5252

53-
void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
53+
void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, QSet<int> & qsetIndexInvalidReference,
54+
int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
5455
{
5556
setQuery( lyrTarget, lyrReference );
5657

@@ -60,7 +61,7 @@ void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVe
6061
? mLayerReference->selectedFeatureCount()
6162
: ( int )( mLayerReference->featureCount() );
6263
mPb->init( 1, totalStep );
63-
setSpatialIndexReference(); // Need set mLayerReference before
64+
setSpatialIndexReference( qsetIndexInvalidReference ); // Need set mLayerReference before
6465

6566
// Make Query
6667
mPb->setFormat( QObject::tr( "Processing 2/2 - %p%" ) );
@@ -69,7 +70,7 @@ void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVe
6970
: ( int )( mLayerTarget->featureCount() );
7071
mPb->init( 1, totalStep );
7172

72-
execQuery( qsetIndexResult, relation );
73+
execQuery( qsetIndexResult, qsetIndexInvalidTarget, relation );
7374

7475
} // QSet<int> QgsSpatialQuery::runQuery( int relation)
7576

@@ -190,7 +191,7 @@ bool QgsSpatialQuery::hasValidGeometry( QgsFeature &feature )
190191

191192
} // bool QgsSpatialQuery::hasValidGeometry(QgsFeature &feature)
192193

193-
void QgsSpatialQuery::setSpatialIndexReference()
194+
void QgsSpatialQuery::setSpatialIndexReference( QSet<int> & qsetIndexInvalidReference )
194195
{
195196
QgsReaderFeatures * readerFeaturesReference = new QgsReaderFeatures( mLayerReference, mUseReferenceSelection );
196197
QgsFeature feature;
@@ -201,6 +202,7 @@ void QgsSpatialQuery::setSpatialIndexReference()
201202

202203
if ( ! hasValidGeometry( feature ) )
203204
{
205+
qsetIndexInvalidReference.insert( feature.id() );
204206
continue;
205207
}
206208

@@ -210,7 +212,7 @@ void QgsSpatialQuery::setSpatialIndexReference()
210212

211213
} // void QgsSpatialQuery::setSpatialIndexReference()
212214

213-
void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
215+
void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, int relation )
214216
{
215217
bool ( QgsGeometry::* operation )( QgsGeometry * );
216218
switch ( relation )
@@ -263,6 +265,7 @@ void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
263265

264266
if ( ! hasValidGeometry( featureTarget ) )
265267
{
268+
qsetIndexInvalidTarget.insert( featureTarget.id() );
266269
continue;
267270
}
268271

src/plugins/spatialquery/qgsspatialquery.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (at your option) any later version. *
1616
* *
1717
***************************************************************************/
18-
/* $Id$ */
18+
/* $Id: qgsspatialquery.h 13380 2010-04-25 12:51:49Z jef $ */
1919
#ifndef SPATIALQUERY_H
2020
#define SPATIALQUERY_H
2121

@@ -82,7 +82,8 @@ class QgsSpatialQuery
8282
* \param lyrTarget Pointer to Target Layer
8383
* \param lyrReference Pointer to Reference Layer
8484
*/
85-
void runQuery( QSet<int> & qsetIndexResult, int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference );
85+
void runQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, QSet<int> & qsetIndexInvalidReference,
86+
int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference );
8687

8788
/**
8889
* \brief Gets the possible topologic relations
@@ -117,14 +118,14 @@ class QgsSpatialQuery
117118
/**
118119
* \brief Build the Spatial Index
119120
*/
120-
void setSpatialIndexReference();
121+
void setSpatialIndexReference( QSet<int> & qsetIndexInvalidReference );
121122

122123
/**
123124
* \brief Execute query
124125
* \param qsetIndexResult Reference to QSet contains the result query
125126
* \param relation Enum Topologic Relation
126127
*/
127-
void execQuery( QSet<int> & qsetIndexResult, int relation );
128+
void execQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, int relation );
128129

129130
/**
130131
* \brief Populate index Result

0 commit comments

Comments
 (0)