Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
spatial query plugin: port to new QgsGeometry operators, gui cleanup
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13367 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 24, 2010
1 parent 91e93a3 commit 42e1f54
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 505 deletions.
2 changes: 0 additions & 2 deletions src/plugins/spatialquery/CMakeLists.txt
Expand Up @@ -41,13 +41,11 @@ INCLUDE_DIRECTORIES(
../../core/symbology
../../gui
..
${GEOS_INCLUDE_DIR}
)

TARGET_LINK_LIBRARIES(spatialqueryplugin
qgis_core
qgis_gui
${GEOS_LIBRARY}
)


Expand Down
45 changes: 18 additions & 27 deletions src/plugins/spatialquery/qgsspatialquery.cpp
Expand Up @@ -55,15 +55,15 @@ void QgsSpatialQuery::runQuery( QSet<int> & qsetIndexResult, int relation, QgsVe
setQuery( lyrTarget, lyrReference );

// Create Spatial index for Reference - Set mIndexReference
mPb->setFormat( "Processing 1/2 - %p%" );
mPb->setFormat( QObject::tr( "Processing 1/2 - %p%" ) );
int totalStep = mUseReferenceSelection
? mLayerReference->selectedFeatureCount()
: ( int )( mLayerReference->featureCount() );
mPb->init( 1, totalStep );
setSpatialIndexReference(); // Need set mLayerReference before

// Make Query
mPb->setFormat( "Processing 2/2 - %p%" );
mPb->setFormat( QObject::tr( "Processing 2/2 - %p%" ) );
totalStep = mUseTargetSelection
? mLayerTarget->selectedFeatureCount()
: ( int )( mLayerTarget->featureCount() );
Expand Down Expand Up @@ -181,9 +181,7 @@ bool QgsSpatialQuery::hasValidGeometry( QgsFeature &feature )
return false;
}

GEOSGeometry *geomGeos = geom->asGeos();

if ( GEOSisEmpty( geomGeos ) || 1 != GEOSisValid( geomGeos ) )
if ( geom->isGeosEmpty() || !geom->isGeosValid() )
{
return false;
}
Expand Down Expand Up @@ -218,33 +216,32 @@ void QgsSpatialQuery::setSpatialIndexReference()

void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
{
// Set GEOS function
char( *operation )( const GEOSGeometry *, const GEOSGeometry* );
bool ( QgsGeometry::* operation )( QgsGeometry * );
switch ( relation )
{
case Disjoint:
operation = &GEOSDisjoint;
operation = &QgsGeometry::disjoint;
break;
case Equals:
operation = &GEOSEquals;
operation = &QgsGeometry::equals;
break;
case Touches:
operation = &GEOSTouches;
operation = &QgsGeometry::touches;
break;
case Overlaps:
operation = &GEOSOverlaps;
operation = &QgsGeometry::overlaps;
break;
case Within:
operation = &GEOSWithin;
operation = &QgsGeometry::within;
break;
case Contains:
operation = &GEOSContains;
operation = &QgsGeometry::contains;
break;
case Crosses:
operation = &GEOSCrosses;
operation = &QgsGeometry::crosses;
break;
case Intersects:
operation = &GEOSIntersects;
operation = &QgsGeometry::intersects;
break;
}

Expand All @@ -253,20 +250,16 @@ void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )
coordinateTransform->setCoordinateTransform( mLayerTarget, mLayerReference );

// Set function for populate result
void ( QgsSpatialQuery::* funcPopulateIndexResult )
( QSet<int> &, int, QgsGeometry *,
char( * )( const GEOSGeometry *, const GEOSGeometry * ) );
void ( QgsSpatialQuery::* funcPopulateIndexResult )( QSet<int> &, int, QgsGeometry *, bool ( QgsGeometry::* )( QgsGeometry * ) );
funcPopulateIndexResult = ( relation == Disjoint )
? &QgsSpatialQuery::populateIndexResultDisjoint
: &QgsSpatialQuery::populateIndexResult;

QgsFeature featureTarget;
QgsGeometry * geomTarget;
int step = 1;
while ( true )
while ( mReaderFeaturesTarget->nextFeature( featureTarget ) )
{
if ( ! mReaderFeaturesTarget->nextFeature( featureTarget ) ) break;

mPb->step( step++ );

if ( ! hasValidGeometry( featureTarget ) )
Expand All @@ -285,23 +278,22 @@ void QgsSpatialQuery::execQuery( QSet<int> & qsetIndexResult, int relation )

void QgsSpatialQuery::populateIndexResult(
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) )
bool ( QgsGeometry::* op )( QgsGeometry * ) )
{
QList<int> listIdReference;
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
if ( listIdReference.count() == 0 )
{
return;
}
GEOSGeometry * geosTarget = geomTarget->asGeos();
QgsFeature featureReference;
QgsGeometry * geomReference;
QList<int>::iterator iterIdReference = listIdReference.begin();
for ( ; iterIdReference != listIdReference.end(); iterIdReference++ )
{
mLayerReference->featureAtId( *iterIdReference, featureReference );
geomReference = featureReference.geometry();
if (( *operation )( geosTarget, geomReference->asGeos() ) == 1 )
if (( geomTarget->*op )( geomReference ) == 1 )
{
qsetIndexResult.insert( idTarget );
break;
Expand All @@ -312,7 +304,7 @@ void QgsSpatialQuery::populateIndexResult(

void QgsSpatialQuery::populateIndexResultDisjoint(
QSet<int> &qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) )
bool ( QgsGeometry::* op )( QgsGeometry * ) )
{
QList<int> listIdReference;
listIdReference = mIndexReference.intersects( geomTarget->boundingBox() );
Expand All @@ -321,7 +313,6 @@ void QgsSpatialQuery::populateIndexResultDisjoint(
qsetIndexResult.insert( idTarget );
return;
}
GEOSGeometry * geosTarget = geomTarget->asGeos();
QgsFeature featureReference;
QgsGeometry * geomReference;
QList<int>::iterator iterIdReference = listIdReference.begin();
Expand All @@ -330,7 +321,7 @@ void QgsSpatialQuery::populateIndexResultDisjoint(
{
mLayerReference->featureAtId( *iterIdReference, featureReference );
geomReference = featureReference.geometry();
if (( *operation )( geosTarget, geomReference->asGeos() ) == 0 )
if (( geomTarget->*op )( geomTarget ) == 0 )
{
addIndex = false;
break;
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/spatialquery/qgsspatialquery.h
Expand Up @@ -19,8 +19,6 @@
#ifndef SPATIALQUERY_H
#define SPATIALQUERY_H

#include <geos_c.h>

#include <qgsvectorlayer.h>
#include <qgsspatialindex.h>

Expand Down Expand Up @@ -137,7 +135,7 @@ class QgsSpatialQuery
*/
void populateIndexResult(
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) );
bool ( QgsGeometry::* operation )( QgsGeometry * ) );
/**
* \brief Populate index Result Disjoint
* \param qsetIndexResult Reference to QSet contains the result query
Expand All @@ -147,7 +145,7 @@ class QgsSpatialQuery
*/
void populateIndexResultDisjoint(
QSet<int> & qsetIndexResult, int idTarget, QgsGeometry * geomTarget,
char( *operation )( const GEOSGeometry *, const GEOSGeometry * ) );
bool ( QgsGeometry::* operation )( QgsGeometry * ) );

MngProgressBar *mPb;
bool mUseReferenceSelection;
Expand Down
31 changes: 19 additions & 12 deletions src/plugins/spatialquery/qgsspatialquerydialog.cpp
Expand Up @@ -152,7 +152,7 @@ void QgsSpatialQueryDialog::evaluateCheckBox( bool isTarget )
checkbox->setChecked( isCheckBoxValid );
checkbox->setEnabled( isCheckBoxValid );
QString textCheckBox = isCheckBoxValid
? QString::number( selectedCount ) + " " + tr( "Selected geometries" )
? tr( "%n selected geometries", "selected geometries", selectedCount )
: tr( "Selected geometries" );
checkbox->setText( textCheckBox );

Expand Down Expand Up @@ -185,30 +185,37 @@ void QgsSpatialQueryDialog::runQuery()
buttonBox->setEnabled( true );

grpResults->show();
grpInputs->hide();
setInputsVisible( false );
progressBarStatus->hide();
buttonBox->button( QDialogButtonBox::Close )->show();
buttonBox->button( QDialogButtonBox::Cancel )->hide();
buttonBox->button( QDialogButtonBox::Ok )->hide();
} // void QgsSpatialQueryDialog::runQuery()

void QgsSpatialQueryDialog::setInputsVisible( bool show )
{
grpTargetGroupBox->setVisible( show );
grpReferenceGroupBox->setVisible( show );
grpOperationGroupBox->setVisible( show );
}

void QgsSpatialQueryDialog::showLogProcessing( bool hasShow )
{
static int heightDialogNoStatus = 0;

hasShow ? textEditStatus->show() : textEditStatus->hide();
this->adjustSize();
adjustSize();

if ( ! hasShow )
{
if ( heightDialogNoStatus == 0 )
{
heightDialogNoStatus = this->geometry().height();
heightDialogNoStatus = geometry().height();
}
else
{
this->setGeometry( this->geometry().x(), this->geometry().y(),
this->geometry().width(), heightDialogNoStatus );
setGeometry( geometry().x(), geometry().y(),
geometry().width(), heightDialogNoStatus );
}
}

Expand Down Expand Up @@ -613,18 +620,18 @@ void QgsSpatialQueryDialog::on_selectedFeatureListWidget_currentTextChanged( con
mRubberSelectId->reset();
selectedFeatureListWidget->setEnabled( false );

QCursor cursor;
cursor.setShape( Qt::WaitCursor );
Qt::CursorShape shapeCurrent = this->cursor().shape();
this->setCursor( cursor );
cursor.setShape( shapeCurrent );
QCursor c;
c.setShape( Qt::WaitCursor );
Qt::CursorShape shapeCurrent = cursor().shape();
setCursor( c );
c.setShape( shapeCurrent );

bool ok;
int Id = currentText.toInt( &ok );
mRubberSelectId->addFeature( mLayerTarget, Id );

selectedFeatureListWidget->setEnabled( true );
this->setCursor( cursor );
setCursor( c );
selectedFeatureListWidget->setFocus();
mRubberSelectId->show();

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/spatialquery/qgsspatialquerydialog.h
Expand Up @@ -122,10 +122,13 @@ class QgsSpatialQueryDialog : public QDialog, private Ui::QgsSpatialQueryDialogB
//! Rubber band for features result
QgsRubberSelectId* mRubberSelectId;

// Menssage
// Message
QString mMsgLayersLessTwo;

void MsgDEBUG( QString sMSg );

//! show/hide target, reference and operation group box
void setInputsVisible( bool show );
};

#endif // SPATIALQUERYDIALOG_H

0 comments on commit 42e1f54

Please sign in to comment.