Skip to content

Commit

Permalink
Add mapserver qgsspatialfilter
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Oct 26, 2012
1 parent b9f631f commit 4c271f2
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
77 changes: 77 additions & 0 deletions 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 <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;
}
73 changes: 73 additions & 0 deletions 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 <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

0 comments on commit 4c271f2

Please sign in to comment.