Skip to content
Permalink
Browse files
OGC filter export: support for basic comparison operators, literal an…
…d propertyName
  • Loading branch information
mhugent committed Dec 7, 2011
1 parent 0f74e07 commit b72f086409ecc872664e0bc389caa0e140fd3e2f
Showing with 92 additions and 7 deletions.
  1. +72 −0 src/core/qgsexpression.cpp
  2. +10 −0 src/core/qgsexpression.h
  3. +10 −7 src/providers/wfs/qgswfsconnection.cpp
@@ -16,6 +16,7 @@
#include "qgsexpression.h"

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

@@ -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;
}
@@ -24,6 +24,8 @@

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

/**
Class for parsing and evaluation of expressions (formerly called "search strings").
@@ -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)
@@ -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
@@ -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 );
@@ -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;
};
@@ -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;
@@ -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";

@@ -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;

0 comments on commit b72f086

Please sign in to comment.