Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sldfix 11863 #1975

Merged
merged 4 commits into from
May 4, 2015
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/core/qgsogcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,27 +1931,38 @@ QDomElement QgsOgcUtils::expressionNodeToOgcFilter( const QgsExpression::Node* n

QDomElement QgsOgcUtils::expressionUnaryOperatorToOgcFilter( const QgsExpression::NodeUnaryOperator* node, QDomDocument& doc, QString& errorMessage )
{

QDomElement operandElem = expressionNodeToOgcFilter( node->operand(), doc, errorMessage );
if ( !errorMessage.isEmpty() )
return QDomElement();

QDomElement uoElem;
switch ( node->op() )
{
case QgsExpression::uoMinus:
uoElem = doc.createElement( "ogc:Literal" );
uoElem.appendChild( doc.createTextNode( "-" ) );
if ( node->operand()->nodeType() == QgsExpression::ntLiteral )
{
// operand expression already created a Literal node:
// take the literal value, prepend - and remove old literal node
uoElem.appendChild( doc.createTextNode( "-" + operandElem.text() ) );
doc.removeChild(operandElem);
}
else // not sure if this will ever happen
{
uoElem.appendChild( doc.createTextNode( "-" ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this may happen - e.g. with expression "-fldA + fldB = 0"

From a quick look into OGC Filter Encoding specs it seems to me that v1.1 defined arithmetic operators like [Add] and [Sub], the latest v2.0 does not mention them anymore. The expression "-X" could be handled the same way as "0-X" is handled - with [Sub] tag.

Or we could just return an error message stating it is not supported - better than just creating invalid filter...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wonder-sk I kept that line to not break historical use of it...

I'm fine with an error message, as I think (espcially in the ogc/sld context) this will never be used/happen.

Should I change it and add it to this PR then?

}
break;
case QgsExpression::uoNot:
uoElem = doc.createElement( "ogc:Not" );
uoElem.appendChild( operandElem );
break;

default:
errorMessage = QString( "Unary operator %1 not implemented yet" ).arg( QgsExpression::UnaryOperatorText[node->op()] );
return QDomElement();
}

QDomElement operandElem = expressionNodeToOgcFilter( node->operand(), doc, errorMessage );
if ( !errorMessage.isEmpty() )
return QDomElement();

uoElem.appendChild( operandElem );
return uoElem;
}

Expand Down