Skip to content

Commit

Permalink
Improvements to spatial select plugin from Luiz Motta (#2634)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15137 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Feb 8, 2011
1 parent e106293 commit 7661f4b
Show file tree
Hide file tree
Showing 7 changed files with 701 additions and 380 deletions.
15 changes: 9 additions & 6 deletions src/plugins/spatialquery/qgsspatialquery.cpp
Expand Up @@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
/* $Id: qgsspatialquery.cpp 13447 2010-05-09 00:45:17Z jef $ */

#include <QMessageBox>

Expand Down Expand Up @@ -50,7 +50,8 @@ void QgsSpatialQuery::setSelectedFeaturesReference( bool useSelected )

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

void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, QSet<int> & qsetIndexInvalidReference,
int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference )
{
setQuery( lyrTarget, lyrReference );

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

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

execQuery( qsetIndexResult, relation );
execQuery( qsetIndexResult, qsetIndexInvalidTarget, relation );

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

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

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

void QgsSpatialQuery::setSpatialIndexReference()
void QgsSpatialQuery::setSpatialIndexReference( QSet<int> & qsetIndexInvalidReference )
{
QgsReaderFeatures * readerFeaturesReference = new QgsReaderFeatures( mLayerReference, mUseReferenceSelection );
QgsFeature feature;
Expand All @@ -201,6 +202,7 @@ void QgsSpatialQuery::setSpatialIndexReference()

if ( ! hasValidGeometry( feature ) )
{
qsetIndexInvalidReference.insert( feature.id() );
continue;
}

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

} // void QgsSpatialQuery::setSpatialIndexReference()

void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, int relation )
{
bool ( QgsGeometry::* operation )( QgsGeometry * );
switch ( relation )
Expand Down Expand Up @@ -263,6 +265,7 @@ void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )

if ( ! hasValidGeometry( featureTarget ) )
{
qsetIndexInvalidTarget.insert( featureTarget.id() );
continue;
}

Expand Down
9 changes: 5 additions & 4 deletions src/plugins/spatialquery/qgsspatialquery.h
Expand Up @@ -15,7 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
/* $Id: qgsspatialquery.h 13380 2010-04-25 12:51:49Z jef $ */
#ifndef SPATIALQUERY_H
#define SPATIALQUERY_H

Expand Down Expand Up @@ -82,7 +82,8 @@ class QgsSpatialQuery
* \param lyrTarget Pointer to Target Layer
* \param lyrReference Pointer to Reference Layer
*/
void runQuery( QSet<int> & qsetIndexResult, int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference );
void runQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, QSet<int> & qsetIndexInvalidReference,
int relation, QgsVectorLayer* lyrTarget, QgsVectorLayer* lyrReference );

/**
* \brief Gets the possible topologic relations
Expand Down Expand Up @@ -117,14 +118,14 @@ class QgsSpatialQuery
/**
* \brief Build the Spatial Index
*/
void setSpatialIndexReference();
void setSpatialIndexReference( QSet<int> & qsetIndexInvalidReference );

/**
* \brief Execute query
* \param qsetIndexResult Reference to QSet contains the result query
* \param relation Enum Topologic Relation
*/
void execQuery( QSet<int> & qsetIndexResult, int relation );
void execQuery( QSet<int> & qsetIndexResult, QSet<int> & qsetIndexInvalidTarget, int relation );

/**
* \brief Populate index Result
Expand Down

0 comments on commit 7661f4b

Please sign in to comment.