From 4c271f2c81b1f3596c4fde465f934054afa05490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=27Hont=20Ren=C3=A9-Luc?= Date: Fri, 26 Oct 2012 16:38:40 +0200 Subject: [PATCH] Add mapserver qgsspatialfilter --- src/mapserver/qgsspatialfilter.cpp | 77 ++++++++++++++++++++++++++++++ src/mapserver/qgsspatialfilter.h | 73 ++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 src/mapserver/qgsspatialfilter.cpp create mode 100644 src/mapserver/qgsspatialfilter.h diff --git a/src/mapserver/qgsspatialfilter.cpp b/src/mapserver/qgsspatialfilter.cpp new file mode 100644 index 000000000000..aa2153c23229 --- /dev/null +++ b/src/mapserver/qgsspatialfilter.cpp @@ -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 + +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; +} diff --git a/src/mapserver/qgsspatialfilter.h b/src/mapserver/qgsspatialfilter.h new file mode 100644 index 000000000000..c5e42faeb491 --- /dev/null +++ b/src/mapserver/qgsspatialfilter.h @@ -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 +#include +#include + +/**A filter for spatial filter (bbox, intersects, within, disjoint) +Sample xml fragment: + + + +135.45,-47.425 157.95,-36.175 + + + +*/ +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