Skip to content

Commit

Permalink
Merge pull request #3606 from rldhont/fix_server_featureinfo_nogeometry
Browse files Browse the repository at this point in the history
[BUGFIX][QGIS Server] GetFeatureInfo: Feature with no geometry is not…
  • Loading branch information
rldhont authored Oct 17, 2016
2 parents e158eca + 697cd1b commit 82d9e05
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2225,35 +2225,45 @@ int QgsWmsServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
#endif

QgsFeatureIterator fit = layer->getFeatures( fReq );
QgsFeatureRenderer* r2 = layer->renderer();
if ( r2 )
{
r2->startRender( renderContext, layer->pendingFields() );
}

bool featureBBoxInitialized = false;
while ( fit.nextFeature( feature ) )
{
if ( layer->wkbType() == QgsWkbTypes::NoGeometry && ! searchRect.isEmpty() )
{
break;
}

++featureCounter;
if ( featureCounter > nFeatures )
{
break;
}

QgsFeatureRenderer* r2 = layer->renderer();
if ( !r2 )
if ( layer->wkbType() != QgsWkbTypes::NoGeometry && ! searchRect.isEmpty() )
{
continue;
}
if ( !r2 )
{
continue;
}

renderContext.expressionContext().setFeature( feature );
renderContext.expressionContext().setFeature( feature );

//check if feature is rendered at all
r2->startRender( renderContext, layer->pendingFields() );
bool render = r2->willRenderFeature( feature, renderContext );
r2->stopRender( renderContext );
if ( !render )
{
continue;
//check if feature is rendered at all
bool render = r2->willRenderFeature( feature, renderContext );
if ( !render )
{
continue;
}
}

QgsRectangle box;
if ( hasGeometry )
if ( layer->wkbType() != QgsWkbTypes::NoGeometry && hasGeometry )
{
box = mapRender->layerExtentToOutputExtent( layer, feature.geometry().boundingBox() );
if ( featureBBox ) //extend feature info bounding box if requested
Expand Down Expand Up @@ -2344,7 +2354,7 @@ int QgsWmsServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
}

//append feature bounding box to feature info xml
if ( hasGeometry && mapRender && mConfigParser )
if ( layer->wkbType() != QgsWkbTypes::NoGeometry && hasGeometry && mapRender && mConfigParser )
{
QDomElement bBoxElem = infoDocument.createElement( "BoundingBox" );
bBoxElem.setAttribute( version == "1.1.1" ? "SRS" : "CRS", outputCrs.authid() );
Expand All @@ -2356,7 +2366,7 @@ int QgsWmsServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
}

//also append the wkt geometry as an attribute
if ( addWktGeometry && hasGeometry )
if ( layer->wkbType() != QgsWkbTypes::NoGeometry && addWktGeometry && hasGeometry )
{
QgsGeometry geom = feature.geometry();
if ( !geom.isEmpty() )
Expand Down Expand Up @@ -2389,6 +2399,10 @@ int QgsWmsServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
}
}
}
if ( r2 )
{
r2->stopRender( renderContext );
}

return 0;
}
Expand Down

0 comments on commit 82d9e05

Please sign in to comment.