Skip to content
Permalink
Browse files

[QGIS-Server] The parameter PROPERTYNAME does not filter attributes

Bug #8155
In the OGC standard, the parameter PROPERTYNAME is ussed to filter attributes in the request getFeature. In version 1.8 this parameter works. Because of changes in the vector API, this parameter does not filter attribute.
  • Loading branch information
rldhont committed Jun 25, 2013
1 parent 52dc17a commit a5ca9d71808b505a84009b952bafcc21b7fb3dc2
Showing with 47 additions and 39 deletions.
  1. +43 −35 src/mapserver/qgswfsserver.cpp
  2. +4 −4 src/mapserver/qgswfsserver.h
@@ -442,12 +442,13 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
layer->getFeatures( QgsFeatureRequest()
.setFilterFid( fid.toInt() )
.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) )
.setSubsetOfAttributes( attrIndexes )
).nextFeature( feature );

if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );

fid = "";
++featCounter;
@@ -460,7 +461,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QDomElement childElem = bboxElem.firstChildElement();

QgsFeatureRequest req;
req.setSubsetOfAttributes( attrIndexes );
req.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );

while ( !childElem.isNull() )
@@ -477,14 +477,15 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
childElem = childElem.nextSiblingElement();
}
req.setSubsetOfAttributes( attrIndexes );

QgsFeatureIterator fit = layer->getFeatures( req );
while ( fit.nextFeature( feature ) && featureCounter < maxFeat )
{
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
@@ -510,7 +511,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featureCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featureCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featureCounter;
++featCounter;
}
@@ -525,7 +526,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
@@ -759,20 +760,20 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
layer->getFeatures( QgsFeatureRequest()
.setFilterFid( fidStr.section( ".", 1, 1 ).toInt() )
.setFlags( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( attrIndexes )
).nextFeature( feature );

if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
}
else if ( expFilterOk )
{
QgsFeatureRequest req;
req.setSubsetOfAttributes( attrIndexes );
if ( layer->wkbType() != QGis::WKBNoGeometry )
{
req.setFilterRect( searchRect )
@@ -783,6 +784,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
req.setFlags( QgsFeatureRequest::NoGeometry );
mWithGeom = false;
}
req.setSubsetOfAttributes( attrIndexes );
QgsFeatureIterator fit = layer->getFeatures( req );
QgsExpression *mFilter = new QgsExpression( expFilter );
if ( mFilter->hasParserError() )
@@ -803,7 +805,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
@@ -834,12 +836,13 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
layer->getFeatures( QgsFeatureRequest()
.setFilterFid( fid.toInt() )
.setFlags( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( attrIndexes )
).nextFeature( feature );

if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );

fid = "";
++featCounter;
@@ -852,7 +855,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QDomElement childElem = bboxElem.firstChildElement();

QgsFeatureRequest req;
req.setSubsetOfAttributes( attrIndexes );
req.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );

while ( !childElem.isNull() )
@@ -869,14 +871,15 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
childElem = childElem.nextSiblingElement();
}
req.setSubsetOfAttributes( attrIndexes );

QgsFeatureIterator fit = layer->getFeatures( req );
while ( fit.nextFeature( feature ) && featureCounter < maxFeat )
{
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
@@ -891,7 +894,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( mFilter )
{
QgsFeatureRequest req;
req.setSubsetOfAttributes( attrIndexes );
if ( layer->wkbType() != QGis::WKBNoGeometry )
{
req.setFilterRect( searchRect )
@@ -902,6 +904,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
req.setFlags( QgsFeatureRequest::NoGeometry );
mWithGeom = false;
}
req.setSubsetOfAttributes( attrIndexes );
QgsFeatureIterator fit = layer->getFeatures( req );
while ( fit.nextFeature( feature ) && featureCounter < maxFeat )
{
@@ -915,7 +918,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featureCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featureCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featureCounter;
++featCounter;
}
@@ -926,8 +929,8 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}
else
{
//throw QgsMapServiceException( "RequestNotWellFormed", QString( "attrIndexes length: %1." ).arg( attrIndexes.count() ) );
QgsFeatureRequest req;
req.setSubsetOfAttributes( attrIndexes );
if ( layer->wkbType() != QGis::WKBNoGeometry )
{
req.setFilterRect( searchRect )
@@ -938,14 +941,15 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
req.setFlags( QgsFeatureRequest::NoGeometry );
mWithGeom = false;
}
req.setSubsetOfAttributes( attrIndexes );
QgsFeatureIterator fit = layer->getFeatures( req );
while ( fit.nextFeature( feature ) && featureCounter < maxFeat )
{
mErrors << QString( "The feature %2 of layer for the TypeName '%1'" ).arg( tnStr ).arg( featureCounter );
if ( featureCounter == 0 )
startGetFeature( request, format, layerCrs, &searchRect );

sendGetFeature( request, format, &feature, featCounter, layerCrs, fields, layerExcludedAttributes );
sendGetFeature( request, format, &feature, featCounter, layerCrs, attrIndexes, layerExcludedAttributes );
++featCounter;
++featureCounter;
}
@@ -1096,7 +1100,7 @@ void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& f
fcString = "";
}

void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
{
if ( !feat->isValid() )
return;
@@ -1109,7 +1113,7 @@ void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& fo
fcString += " ";
else
fcString += " ,";
fcString += createFeatureGeoJSON( feat, crs, fields, excludedAttributes );
fcString += createFeatureGeoJSON( feat, crs, attrIndexes, excludedAttributes );
fcString += "\n";

result = fcString.toUtf8();
@@ -1122,12 +1126,12 @@ void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& fo
QDomElement featureElement;
if ( format == "GML3" )
{
featureElement = createFeatureGML3( feat, gmlDoc, crs, fields, excludedAttributes );
featureElement = createFeatureGML3( feat, gmlDoc, crs, attrIndexes, excludedAttributes );
gmlDoc.appendChild( featureElement );
}
else
{
featureElement = createFeatureGML2( feat, gmlDoc, crs, fields, excludedAttributes );
featureElement = createFeatureGML2( feat, gmlDoc, crs, attrIndexes, excludedAttributes );
gmlDoc.appendChild( featureElement );
}

@@ -1570,7 +1574,7 @@ QgsFeatureIds QgsWFSServer::getFeatureIdsFromFilter( QDomElement filterElem, Qgs
return fids;
}

QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem &, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem &, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
{
QString fStr = "{\"type\": \"Feature\",\n";

@@ -1593,16 +1597,18 @@ QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateRefer
//read all attribute values from the feature
fStr += " \"properties\": {\n";
QgsAttributes featureAttributes = feat->attributes();
const QgsFields* fields = feat->fields();
int attributeCounter = 0;
for ( int i = 0; i < featureAttributes.count(); ++i )
for ( int i = 0; i < attrIndexes.count(); ++i )
{
QString attributeName = fields[i].name();
int idx = attrIndexes[i];
QString attributeName = fields->at(idx).name();
//skip attribute if it is excluded from WFS publication
if ( excludedAttributes.contains( attributeName ) )
{
continue;
}
QVariant val = featureAttributes[i];
QVariant val = featureAttributes[idx];

if ( attributeCounter == 0 )
fStr += " \"";
@@ -1631,7 +1637,7 @@ QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateRefer
return fStr;
}

QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
{
//gml:FeatureMember
QDomElement featureElement = doc.createElement( "gml:featureMember"/*wfs:FeatureMember*/ );
@@ -1670,26 +1676,27 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc

//read all attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
for ( int i = 0; i < featureAttributes.count(); ++i )
const QgsFields* fields = feat->fields();
for ( int i = 0; i < attrIndexes.count(); ++i )
{

QString attributeName = fields[i].name();
//skip attribute if is explicitly excluded from WFS publication
int idx = attrIndexes[i];
QString attributeName = fields->at(idx).name();
//skip attribute if it is excluded from WFS publication
if ( excludedAttributes.contains( attributeName ) )
{
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
QDomText fieldText = doc.createTextNode( featureAttributes[i].toString() );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
}

return featureElement;
}

QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
{
//gml:FeatureMember
QDomElement featureElement = doc.createElement( "gml:featureMember"/*wfs:FeatureMember*/ );
@@ -1728,18 +1735,19 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc

//read all attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
for ( int i = 0; i < featureAttributes.count(); ++i )
const QgsFields* fields = feat->fields();
for ( int i = 0; i < attrIndexes.count(); ++i )
{

QString attributeName = fields[i].name();
//skip attribute if is explicitly excluded from WFS publication
int idx = attrIndexes[i];
QString attributeName = fields->at(idx).name();
//skip attribute if it is excluded from WFS publication
if ( excludedAttributes.contains( attributeName ) )
{
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
QDomText fieldText = doc.createTextNode( featureAttributes[i].toString() );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
}
@@ -99,20 +99,20 @@ class QgsWFSServer
protected:

void startGetFeature( QgsRequestHandler& request, const QString& format, QgsCoordinateReferenceSystem& crs, QgsRectangle* rect );
void sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes );
void sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes );
void endGetFeature( QgsRequestHandler& request, const QString& format );

//method for transaction
QgsFeatureIds getFeatureIdsFromFilter( QDomElement filter, QgsVectorLayer* layer );

//methods to write GeoJSON
QString createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;
QString createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/;

//methods to write GML2
QDomElement createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;
QDomElement createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/;

//methods to write GML3
QDomElement createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;
QDomElement createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/;
};

#endif

0 comments on commit a5ca9d7

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