Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*************************************************************************** | ||
qgsspatialfilter.cpp | ||
----------------------- | ||
begin : Oct 19, 2012 | ||
copyright : (C) 2012 by René-Luc D'Hont | ||
email : rldhont at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsspatialfilter.h" | ||
#include "qgsgeometry.h" | ||
#include <QDomElement> | ||
|
||
QgsSpatialFilter::QgsSpatialFilter(): QgsFilter(), mSpatialType( QgsSpatialFilter::UNKNOWN ), mGeom( 0 ) | ||
{ | ||
} | ||
|
||
QgsSpatialFilter::QgsSpatialFilter( SPATIAL_TYPE st, QgsGeometry* geom ): QgsFilter(), mSpatialType( st ), mGeom( geom ) | ||
{ | ||
} | ||
|
||
QgsSpatialFilter::~QgsSpatialFilter() | ||
{ | ||
delete mGeom; | ||
} | ||
|
||
bool QgsSpatialFilter::evaluate( const QgsFeature& f ) const | ||
{ | ||
if ( !mGeom ) | ||
{ | ||
return true; | ||
} | ||
|
||
QgsGeometry* geom = ( new QgsFeature( f ) )->geometry(); | ||
switch ( mSpatialType ) | ||
{ | ||
case BBOX: | ||
return geom->intersects( mGeom->boundingBox() ); | ||
break; | ||
case CONTAINS: | ||
return geom->contains( mGeom ); | ||
break; | ||
case CROSSES: | ||
return geom->crosses( mGeom ); | ||
break; | ||
case DISJOINT: | ||
return geom->disjoint( mGeom ); | ||
break; | ||
case EQUALS: | ||
return geom->equals( mGeom ); | ||
break; | ||
case INTERSECTS: | ||
return geom->intersects( mGeom ); | ||
break; | ||
case OVERLAPS: | ||
return geom->overlaps( mGeom ); | ||
break; | ||
case TOUCHES: | ||
return geom->touches( mGeom ); | ||
break; | ||
case WITHIN: | ||
return geom->within( mGeom ); | ||
break; | ||
case UNKNOWN: | ||
default: | ||
break; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
qgsspatialfilter.h | ||
--------------------- | ||
begin : Oct 19, 2012 | ||
copyright : (C) 2012 by René-Luc D'Hont | ||
email : rldhont at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSPATIALFILTER_H | ||
#define QGSSPATIALFILTER_H | ||
|
||
#include <qgsfilter.h> | ||
#include <qgsgeometry.h> | ||
#include <QDomElement> | ||
|
||
/**A filter for spatial filter (bbox, intersects, within, disjoint) | ||
Sample xml fragment: | ||
<Filter xmlns="http://www.opengis.net/ogc"> | ||
<BBOX> | ||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"> | ||
<gml:coordinates decimal="." cs="," ts=" ">135.45,-47.425 157.95,-36.175</gml:coordinates> | ||
</gml:Box> | ||
</BBOX> | ||
</Filter> | ||
*/ | ||
class QgsSpatialFilter: public QgsFilter | ||
{ | ||
public: | ||
enum SPATIAL_TYPE | ||
{ | ||
BBOX, | ||
CONTAINS, | ||
CROSSES, | ||
EQUALS, | ||
DISJOINT, | ||
INTERSECTS, | ||
OVERLAPS, | ||
TOUCHES, | ||
WITHIN, | ||
UNKNOWN | ||
}; | ||
|
||
QgsSpatialFilter(); | ||
QgsSpatialFilter( SPATIAL_TYPE st, QgsGeometry* geom ); | ||
~QgsSpatialFilter(); | ||
|
||
/**Evaluates a feature against the filter. | ||
@return true if the filter applies for the feature*/ | ||
bool evaluate( const QgsFeature& f ) const; | ||
|
||
//setters and getters | ||
SPATIAL_TYPE spatialType() const {return mSpatialType;} | ||
void setSpatialType( SPATIAL_TYPE t ) {mSpatialType = t;} | ||
|
||
//setters and getters | ||
QgsGeometry* geometry() const {return mGeom;} | ||
void setGeometry( QgsGeometry* g ) {mGeom = g;} | ||
|
||
private: | ||
SPATIAL_TYPE mSpatialType; | ||
QgsGeometry* mGeom; | ||
}; | ||
|
||
#endif //QGSSPATIALFILTER_H |