Skip to content

Commit 4c271f2

Browse files
committed
Add mapserver qgsspatialfilter
1 parent b9f631f commit 4c271f2

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

src/mapserver/qgsspatialfilter.cpp

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
qgsspatialfilter.cpp
3+
-----------------------
4+
begin : Oct 19, 2012
5+
copyright : (C) 2012 by René-Luc D'Hont
6+
email : rldhont at 3liz dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsspatialfilter.h"
19+
#include "qgsgeometry.h"
20+
#include <QDomElement>
21+
22+
QgsSpatialFilter::QgsSpatialFilter(): QgsFilter(), mSpatialType( QgsSpatialFilter::UNKNOWN ), mGeom( 0 )
23+
{
24+
}
25+
26+
QgsSpatialFilter::QgsSpatialFilter( SPATIAL_TYPE st, QgsGeometry* geom ): QgsFilter(), mSpatialType( st ), mGeom( geom )
27+
{
28+
}
29+
30+
QgsSpatialFilter::~QgsSpatialFilter()
31+
{
32+
delete mGeom;
33+
}
34+
35+
bool QgsSpatialFilter::evaluate( const QgsFeature& f ) const
36+
{
37+
if ( !mGeom )
38+
{
39+
return true;
40+
}
41+
42+
QgsGeometry* geom = ( new QgsFeature( f ) )->geometry();
43+
switch ( mSpatialType )
44+
{
45+
case BBOX:
46+
return geom->intersects( mGeom->boundingBox() );
47+
break;
48+
case CONTAINS:
49+
return geom->contains( mGeom );
50+
break;
51+
case CROSSES:
52+
return geom->crosses( mGeom );
53+
break;
54+
case DISJOINT:
55+
return geom->disjoint( mGeom );
56+
break;
57+
case EQUALS:
58+
return geom->equals( mGeom );
59+
break;
60+
case INTERSECTS:
61+
return geom->intersects( mGeom );
62+
break;
63+
case OVERLAPS:
64+
return geom->overlaps( mGeom );
65+
break;
66+
case TOUCHES:
67+
return geom->touches( mGeom );
68+
break;
69+
case WITHIN:
70+
return geom->within( mGeom );
71+
break;
72+
case UNKNOWN:
73+
default:
74+
break;
75+
}
76+
return false;
77+
}

src/mapserver/qgsspatialfilter.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/***************************************************************************
2+
qgsspatialfilter.h
3+
---------------------
4+
begin : Oct 19, 2012
5+
copyright : (C) 2012 by René-Luc D'Hont
6+
email : rldhont at 3liz dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSSPATIALFILTER_H
19+
#define QGSSPATIALFILTER_H
20+
21+
#include <qgsfilter.h>
22+
#include <qgsgeometry.h>
23+
#include <QDomElement>
24+
25+
/**A filter for spatial filter (bbox, intersects, within, disjoint)
26+
Sample xml fragment:
27+
<Filter xmlns="http://www.opengis.net/ogc">
28+
<BBOX>
29+
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
30+
<gml:coordinates decimal="." cs="," ts=" ">135.45,-47.425 157.95,-36.175</gml:coordinates>
31+
</gml:Box>
32+
</BBOX>
33+
</Filter>
34+
*/
35+
class QgsSpatialFilter: public QgsFilter
36+
{
37+
public:
38+
enum SPATIAL_TYPE
39+
{
40+
BBOX,
41+
CONTAINS,
42+
CROSSES,
43+
EQUALS,
44+
DISJOINT,
45+
INTERSECTS,
46+
OVERLAPS,
47+
TOUCHES,
48+
WITHIN,
49+
UNKNOWN
50+
};
51+
52+
QgsSpatialFilter();
53+
QgsSpatialFilter( SPATIAL_TYPE st, QgsGeometry* geom );
54+
~QgsSpatialFilter();
55+
56+
/**Evaluates a feature against the filter.
57+
@return true if the filter applies for the feature*/
58+
bool evaluate( const QgsFeature& f ) const;
59+
60+
//setters and getters
61+
SPATIAL_TYPE spatialType() const {return mSpatialType;}
62+
void setSpatialType( SPATIAL_TYPE t ) {mSpatialType = t;}
63+
64+
//setters and getters
65+
QgsGeometry* geometry() const {return mGeom;}
66+
void setGeometry( QgsGeometry* g ) {mGeom = g;}
67+
68+
private:
69+
SPATIAL_TYPE mSpatialType;
70+
QgsGeometry* mGeom;
71+
};
72+
73+
#endif //QGSSPATIALFILTER_H

0 commit comments

Comments
 (0)