Skip to content
Permalink
Browse files

GeoServer compatibility

  • Loading branch information
pblottiere committed Jan 28, 2019
1 parent df75801 commit 724813a52eacdc45efd69ab22d17bcc84b4765af
Showing with 17 additions and 28 deletions.
  1. +1 −5 src/core/qgsjsonutils.cpp
  2. +0 −15 src/core/qgsjsonutils.h
  3. +16 −8 src/server/services/wms/qgswmsrenderer.cpp
@@ -243,11 +243,7 @@ QString QgsJsonExporter::exportFeatures( const QgsFeatureList &features ) const
featureJSON << exportFeature( feature );
}

QString layerName;
if ( mIncludeName )
layerName = QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( mLayer->name() );

return QStringLiteral( "{%1 \"type\": \"FeatureCollection\",\n \"features\":[\n%2\n]}" ).arg( layerName, featureJSON.join( QStringLiteral( ",\n" ) ) );
return QStringLiteral( "{\"type\": \"FeatureCollection\",\n \"features\":[\n%2\n]}" ).arg( featureJSON.join( QStringLiteral( ",\n" ) ) );
}


@@ -75,21 +75,6 @@ class CORE_EXPORT QgsJsonExporter
*/
bool includeGeometry() const { return mIncludeGeometry; }

/**
* Sets whether to include layer's name in the JSON exports.
* \param includeName set to false to prevent name inclusion
* \see includeName()
* \since QGIS 3.6
*/
void setIncludeName( bool includeName ) { mIncludeName = includeName; }

/**
* Returns whether layer's name will be included in the JSON exports.
* \see setIncludeName()
* \since QGIS 3.6
*/
bool includeName() const { return mIncludeName; }

/**
* Sets whether to include attributes in the JSON exports.
* \param includeAttributes set to false to prevent attribute inclusion
@@ -2281,7 +2281,8 @@ namespace QgsWms
QByteArray QgsRenderer::convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const
{
QString json;
json.append( QStringLiteral( "{\n\"layers\":[" ) );
json.append( QStringLiteral( "{\"type\": \"FeatureCollection\",\n" ) );
json.append( QStringLiteral( " \"features\":[\n" ) );

const bool withGeometry = ( QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject ) && mWmsParameters.withGeometry() );

@@ -2340,17 +2341,24 @@ namespace QgsWms
exporter.setAttributeDisplayName( true );
exporter.setAttributes( attributes );
exporter.setIncludeGeometry( withGeometry );
exporter.setIncludeName( true );

if ( i > 0 )
json.append( QStringLiteral( "," ) );
for ( const auto feature : features )
{
if ( json.right( 1 ).compare( QStringLiteral( "}" ) ) == 0 )
{
json.append( QStringLiteral( "," ) );
}

json.append( exporter.exportFeatures( features ) );
const QString id = QStringLiteral( "%1.%2" ).arg( layer->name(), QgsJsonUtils::encodeValue( feature.id() ) );
json.append( exporter.exportFeature( feature, QVariantMap(), id ) );
}
}
else // raster layer
{
json.append( QStringLiteral( "{" ) );
json.append( QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( layer->name() ) );
json.append( QStringLiteral( "\"type\":\"Feature\",\n" ) );
json.append( QStringLiteral( "\"id\":\"%1\",\n" ).arg( layer->name() ) );
json.append( QStringLiteral( "\"properties\":{\n" ) );

const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral( "Attribute" ) );
for ( int j = 0; j < attributesNode.size(); ++j )
@@ -2362,10 +2370,10 @@ namespace QgsWms
if ( j > 0 )
json.append( QStringLiteral( ",\n" ) );

json.append( QStringLiteral( "\"%1\": \"%2\"" ).arg( name, value ) );
json.append( QStringLiteral( " \"%1\": \"%2\"" ).arg( name, value ) );
}

json.append( QStringLiteral( "\n}" ) );
json.append( QStringLiteral( "\n}\n}" ) );
}
}

0 comments on commit 724813a

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