Skip to content

Commit

Permalink
OGC filter export: support for basic comparison operators, literal an…
Browse files Browse the repository at this point in the history
…d propertyName
  • Loading branch information
mhugent committed Dec 7, 2011
1 parent 0f74e07 commit b72f086
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
72 changes: 72 additions & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgsexpression.h"

#include <QtDebug>
#include <QDomDocument>
#include <QSettings>
#include <math.h>

Expand Down Expand Up @@ -968,3 +969,74 @@ QString QgsExpression::NodeColumnRef::dump() const
{
return mName;
}

bool QgsExpression::toOGCFilter( QDomDocument& doc ) const
{
if ( !mRootNode )
{
return false;
}

doc.clear();
QDomElement filterElem = doc.createElementNS( "http://www.opengis.net/fes/2.0", "Filter" );
doc.appendChild( filterElem );
return mRootNode->toOGCFilter( doc, filterElem );
}

bool QgsExpression::NodeBinaryOperator::toOGCFilter( QDomDocument& doc, QDomElement& parent ) const
{
QDomElement opElem;
switch ( mOp )
{
case boEQ:
opElem = doc.createElement( "PropertyIsEqualTo" );
break;
case boNE:
opElem = doc.createElement( "PropertyIsNotEqualTo" );
break;
case boLE:
opElem = doc.createElement( "PropertyIsLessThanOrEqualTo" );
break;
case boGE:
opElem = doc.createElement( "PropertyIsLessThanOrEqualTo" );
break;
case boLT:
opElem = doc.createElement( "PropertyIsLessThan" );
break;
case boGT:
opElem = doc.createElement( "PropertyIsGreaterThan" );
break;
default:
return false;
}

if ( mOpLeft )
{
mOpLeft->toOGCFilter( doc, opElem );
}
if ( mOpRight )
{
mOpRight->toOGCFilter( doc, opElem );
}

parent.appendChild( opElem );
return true;
}

bool QgsExpression::NodeLiteral::toOGCFilter( QDomDocument& doc, QDomElement& parent ) const
{
QDomElement literalElem = doc.createElement( "Literal" );
QDomText literalText = doc.createTextNode( mValue.toString() );
literalElem.appendChild( literalText );
parent.appendChild( literalElem );
return true;
}

bool QgsExpression::NodeColumnRef::toOGCFilter( QDomDocument& doc, QDomElement& parent ) const
{
QDomElement propertyElem = doc.createElement( "PropertyName" );
QDomText propertyText = doc.createTextNode( mName );
propertyElem.appendChild( propertyText );
parent.appendChild( propertyElem );
return true;
}
10 changes: 10 additions & 0 deletions src/core/qgsexpression.h
Expand Up @@ -24,6 +24,8 @@

class QgsDistanceArea;
class QgsFeature;
class QDomDocument;
class QDomElement;

/**
Class for parsing and evaluation of expressions (formerly called "search strings").
Expand Down Expand Up @@ -120,6 +122,9 @@ class CORE_EXPORT QgsExpression

//! Return the parsed expression as a string - useful for debugging
QString dump() const;
//! Creates ogc filter xml document
//! @return true in case of success
bool toOGCFilter( QDomDocument& doc ) const;

//! Return calculator used for distance and area calculations
//! (used by internal functions)
Expand Down Expand Up @@ -222,6 +227,7 @@ class CORE_EXPORT QgsExpression

virtual QStringList referencedColumns() const = 0;
virtual bool needsGeometry() const = 0;
virtual bool toOGCFilter( QDomDocument& doc, QDomElement& parent ) const { return false; }
};

class NodeList
Expand Down Expand Up @@ -265,6 +271,8 @@ class CORE_EXPORT QgsExpression
virtual QString dump() const;
virtual QStringList referencedColumns() const { return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
virtual bool needsGeometry() const { return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
virtual bool toOGCFilter( QDomDocument& doc, QDomElement& parent ) const;

protected:
bool compare( double diff );
int computeInt( int x, int y );
Expand Down Expand Up @@ -320,6 +328,7 @@ class CORE_EXPORT QgsExpression
virtual QString dump() const;
virtual QStringList referencedColumns() const { return QStringList(); }
virtual bool needsGeometry() const { return false; }
virtual bool toOGCFilter( QDomDocument& doc, QDomElement& parent ) const;
protected:
QVariant mValue;
};
Expand All @@ -334,6 +343,7 @@ class CORE_EXPORT QgsExpression
virtual QString dump() const;
virtual QStringList referencedColumns() const { return QStringList( mName ); }
virtual bool needsGeometry() const { return false; }
virtual bool toOGCFilter( QDomDocument& doc, QDomElement& parent ) const;
protected:
QString mName;
int mIndex;
Expand Down
17 changes: 10 additions & 7 deletions src/providers/wfs/qgswfsconnection.cpp
@@ -1,14 +1,12 @@
#include "qgswfsconnection.h"

#include "qgsexpression.h"
#include "qgslogger.h"

#include <QDomDocument>
#include <QSettings>
#include <QStringList>

#include "qgsnetworkaccessmanager.h"
#include <QDomDocument>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QSettings>
#include <QStringList>

static const QString WFS_NAMESPACE = "http://www.opengis.net/wfs";

Expand Down Expand Up @@ -57,7 +55,12 @@ QString QgsWFSConnection::uriGetFeature( QString typeName, QString crsString, QS
QString filterString;
if ( !filter.isEmpty() )
{
filterString = "&FILTER=" + filter;
QgsExpression filterExpression( filter );
QDomDocument filterDoc;
if ( filterExpression.toOGCFilter( filterDoc ) )
{
filterString = "&FILTER=" + filterDoc.toString();
}
}

QString bBoxString;
Expand Down

0 comments on commit b72f086

Please sign in to comment.