Skip to content
Permalink
Browse files

spatial query plugin: port to new QgsGeometry operators, gui cleanup

git-svn-id: http://svn.osgeo.org/qgis/trunk@13367 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Apr 24, 2010
1 parent e946ed1 commit bf0c30bcbf6a01ceccb496371b3154f92b34cd26
@@ -41,13 +41,11 @@ INCLUDE_DIRECTORIES(
../../core/symbology
../../gui
..
${GEOS_INCLUDE_DIR}
)

TARGET_LINK_LIBRARIES(spatialqueryplugin
qgis_core
qgis_gui
${GEOS_LIBRARY}
)


@@ -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() );
@@ -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;
}
@@ -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;
}

@@ -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 ) )
@@ -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;
@@ -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() );
@@ -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();
@@ -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;
@@ -19,8 +19,6 @@
#ifndef SPATIALQUERY_H
#define SPATIALQUERY_H

#include <geos_c.h>

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

@@ -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
@@ -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;
@@ -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 );

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

@@ -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();

@@ -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 bf0c30b

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