Skip to content

Commit

Permalink
WMS cascading: fix unreported issue wih missing fids
Browse files Browse the repository at this point in the history
1. in WMS provider try to set fid from external getFeatureInfo JSON response
2. in WMS server, make sure we transform integer FID to string

This fixes an unreported issue where getFeatureInfo from cascaded WMS in
JSON format have no feature IDs.

Funded by Gis3W https://www.gis3w.it

(cherry picked from commit 0189efa)
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2021
1 parent 3bba063 commit 44d2b4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -3489,6 +3489,23 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPointXY &point, QgsRa
params.insert( QStringLiteral( "getFeatureInfoUrl" ), requestUrl.toString() );
featureStore.setParams( params );

// Try to parse and set feature id if matches "<some string>.<integer>"
if ( f.value( QLatin1String( "id" ) ).isString() )
{
static const QRegularExpression re{ R"raw(\.(\d+)$)raw" };
const QString idVal { f.value( QLatin1String( "id" ) ).toString() };
const QRegularExpressionMatch match { re.match( idVal ) };
if ( match.hasMatch() )
{
bool ok;
QgsFeatureId id { match.captured( 1 ).toLongLong( &ok ) };
if ( ok )
{
feature.setId( id );
}
}
}

feature.setValid( true );
featureStore.addFeature( feature );

Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2432,7 +2432,7 @@ namespace QgsWms
if ( layer && layer->dataProvider() )
fid = QgsServerFeatureId::getServerFid( *feat, layer->dataProvider()->pkAttributeIndexes() );
else
fid = feat->id();
fid = QString::number( feat->id() );

typeNameElement.setAttribute( QStringLiteral( "fid" ), QStringLiteral( "%1.%2" ).arg( typeName, fid ) );

Expand Down

0 comments on commit 44d2b4b

Please sign in to comment.