Skip to content
Permalink
Browse files

Add CQL_FILTER to WFS for QgsExpression

  • Loading branch information
rldhont committed Nov 14, 2012
1 parent 0e11e93 commit 20d57b95d2cff2c7dec680802c6ab39531d2c19d
Showing with 42 additions and 25 deletions.
  1. +42 −25 src/mapserver/qgswfsserver.cpp
@@ -585,6 +585,15 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
}

//read cql_filter
bool cqlFilterOk = false;
QString cqlFilter;
QMap<QString, QString>::const_iterator cqlFilterIt = mParameterMap.find( "CQL_FILTER" );
if ( cqlFilterIt != mParameterMap.end() )
{
cqlFilterOk = true;
cqlFilter = cqlFilterIt.value();
}

bool conversionSuccess;
double minx, miny, maxx, maxy;
@@ -667,49 +676,57 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
provider->featureAtId( fid.toInt(), feature, mWithGeom, attrIndexes );
sendGetFeature( request, format, &feature, 0, layerCrs, fields, layerExcludedAttributes );
}
else if ( filterOk )
else if ( cqlFilterOk )
{
provider->select( attrIndexes, searchRect, mWithGeom, true );
try
QgsExpression *mFilter = new QgsExpression( cqlFilter );
if (mFilter->hasParserError())
{
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->parserErrorString() );
}
if ( mFilter )
{
QDomElement filterElem = filter.firstChildElement();
QgsExpression *mFilter = QgsExpression::createFromOgcFilter( filterElem );
if (mFilter->hasParserError())
{
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->parserErrorString() );
}
while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
{
if ( mFilter )
QVariant res = mFilter->evaluate( &feature, fields );
if (mFilter->hasEvalError())
{
QVariant res = mFilter->evaluate( &feature, fields );
if (mFilter->hasEvalError())
{
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->evalErrorString() );
}
if ( res.toInt() != 0 )
{
sendGetFeature( request, format, &feature, featureCounter, layerCrs, fields, layerExcludedAttributes );
++featureCounter;
}
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->evalErrorString() );
}
else
if ( res.toInt() != 0 )
{
sendGetFeature( request, format, &feature, featureCounter, layerCrs, fields, layerExcludedAttributes );
++featureCounter;
}
}
delete mFilter;
}
catch ( QgsMapServiceException& e )
}
else if ( filterOk )
{
provider->select( attrIndexes, searchRect, mWithGeom, true );
QDomElement filterElem = filter.firstChildElement();
QgsExpression *mFilter = QgsExpression::createFromOgcFilter( filterElem );
if (mFilter->hasParserError())
{
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->parserErrorString() );
}
if ( mFilter )
{
Q_UNUSED( e );

while ( provider->nextFeature( feature ) && featureCounter < maxFeat )
{
sendGetFeature( request, format, &feature, featureCounter, layerCrs, fields, layerExcludedAttributes );
++featureCounter;
QVariant res = mFilter->evaluate( &feature, fields );
if (mFilter->hasEvalError())
{
throw QgsMapServiceException( "RequestNotWellFormed", mFilter->evalErrorString() );
}
if ( res.toInt() != 0 )
{
sendGetFeature( request, format, &feature, featureCounter, layerCrs, fields, layerExcludedAttributes );
++featureCounter;
}
}
delete mFilter;
}
}
else

0 comments on commit 20d57b9

Please sign in to comment.
You can’t perform that action at this time.