Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[BUGFIX][Server] WFS GeoJSON: QGIS Server 2.18 much slower than 2.14
Fixed #18249

The JsonExporter was generated for each feature exported to GeoJSON.
  • Loading branch information
rldhont committed Mar 20, 2018
1 parent dfb0c4f commit e70982a
Showing 1 changed file with 24 additions and 45 deletions.
69 changes: 24 additions & 45 deletions src/server/services/wfs/qgswfsgetfeature.cpp
Expand Up @@ -51,8 +51,6 @@ namespace QgsWfs

const QgsAttributeList &attributeIndexes;

const QSet<QString> &excludedAttributes;

const QString &typeName;

bool withGeom;
Expand Down Expand Up @@ -82,6 +80,8 @@ namespace QgsWfs

QgsServerRequest::Parameters mRequestParameters;
QgsWfsParameters mWfsParameters;
/* GeoJSON Exporter */
QgsJsonExporter mJsonExporter;
}

void writeGetFeature( QgsServerInterface *serverIface, const QgsProject *project,
Expand Down Expand Up @@ -241,13 +241,13 @@ namespace QgsWfs

//Using pending attributes and pending fields
QgsAttributeList attrIndexes = vlayer->attributeList();
QgsFields fields = vlayer->fields();
bool withGeom = true;
if ( !propertyList.isEmpty() && propertyList.first() != QStringLiteral( "*" ) )
{
withGeom = false;
QStringList::const_iterator plstIt;
QList<int> idxList;
QgsFields fields = vlayer->fields();
// build corresponding propertyname
QList<QString> propertynames;
for ( int idx = 0; idx < fields.count(); ++idx )
Expand All @@ -274,6 +274,20 @@ namespace QgsWfs
}
}

//excluded attributes for this layer
const QSet<QString> &layerExcludedAttributes = vlayer->excludeAttributesWfs();
if ( !attrIndexes.isEmpty() && !layerExcludedAttributes.isEmpty() )
{
foreach ( const QString &excludedAttribute, layerExcludedAttributes )
{
int fieldNameIdx = fields.indexOf( excludedAttribute );
if ( fieldNameIdx > -1 && attrIndexes.contains( fieldNameIdx ) )
{
attrIndexes.removeOne( fieldNameIdx );
}
}
}


// update request
QgsFeatureRequest featureRequest = query.featureRequest;
Expand Down Expand Up @@ -325,8 +339,7 @@ namespace QgsWfs
int layerPrecision = QgsServerProjectUtils::wfsLayerPrecision( *project, vlayer->id() );
// specific layer crs
QgsCoordinateReferenceSystem layerCrs = vlayer->crs();
//excluded attributes for this layer
const QSet<QString> &layerExcludedAttributes = vlayer->excludeAttributesWfs();

// Geometry name
QString geometryName = aRequest.geometryName;
if ( !withGeom )
Expand Down Expand Up @@ -359,7 +372,6 @@ namespace QgsWfs
const createFeatureParams cfp = { layerPrecision,
layerCrs,
attrIndexes,
layerExcludedAttributes,
typeName,
withGeom,
geometryName,
Expand Down Expand Up @@ -1145,6 +1157,10 @@ namespace QgsWfs
fcString += QLatin1String( " " );
else
fcString += QLatin1String( " ," );
mJsonExporter.setSourceCrs( params.crs );
mJsonExporter.setIncludeGeometry( false );
mJsonExporter.setIncludeAttributes( !params.attributeIndexes.isEmpty() );
mJsonExporter.setAttributes( params.attributeIndexes );
fcString += createFeatureGeoJSON( feat, params );
fcString += QLatin1String( "\n" );

Expand Down Expand Up @@ -1190,21 +1206,16 @@ namespace QgsWfs
QString createFeatureGeoJSON( QgsFeature *feat, const createFeatureParams &params )
{
QString id = QStringLiteral( "%1.%2" ).arg( params.typeName, FID_TO_STRING( feat->id() ) );

QgsJsonExporter exporter;
exporter.setSourceCrs( params.crs );
//QgsJsonExporter force transform geometry to ESPG:4326
//and the RFC 7946 GeoJSON specification recommends limiting coordinate precision to 6
//Q_UNUSED( prec );
//exporter.setPrecision( prec );

//copy feature so we can modify its geometry as required
QgsFeature f( *feat );
QgsGeometry geom = feat->geometry();
exporter.setIncludeGeometry( false );
if ( !geom.isNull() && params.withGeom && params.geometryName != QLatin1String( "NONE" ) )
{
exporter.setIncludeGeometry( true );
mJsonExporter.setIncludeGeometry( true );
if ( params.geometryName == QLatin1String( "EXTENT" ) )
{
QgsRectangle box = geom.boundingBox();
Expand All @@ -1216,29 +1227,7 @@ namespace QgsWfs
}
}

QgsFields fields = feat->fields();
QgsAttributeList attrsToExport;
for ( int i = 0; i < params.attributeIndexes.count(); ++i )
{
int idx = params.attributeIndexes[i];
if ( idx >= fields.count() )
{
continue;
}
QString attributeName = fields.at( idx ).name();
//skip attribute if it is excluded from WFS publication
if ( params.excludedAttributes.contains( attributeName ) )
{
continue;
}

attrsToExport << idx;
}

exporter.setIncludeAttributes( !attrsToExport.isEmpty() );
exporter.setAttributes( attrsToExport );

return exporter.exportFeature( f, QVariantMap(), id );
return mJsonExporter.exportFeature( f, QVariantMap(), id );
}


Expand Down Expand Up @@ -1329,11 +1318,6 @@ namespace QgsWfs
continue;
}
QString attributeName = fields.at( idx ).name();
//skip attribute if it is excluded from WFS publication
if ( params.excludedAttributes.contains( attributeName ) )
{
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
Expand Down Expand Up @@ -1431,11 +1415,6 @@ namespace QgsWfs
continue;
}
QString attributeName = fields.at( idx ).name();
//skip attribute if it is excluded from WFS publication
if ( params.excludedAttributes.contains( attributeName ) )
{
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
Expand Down

0 comments on commit e70982a

Please sign in to comment.