Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when adding WMS/WFS layers from Browser use project CRS if it is supported by the server (fix #44325) #60476

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/providers/wfs/qgswfsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "qgswfsdatasourceuri.h"
#include "qgswfsprovider.h"
#include "qgssettings.h"
#include "qgsproject.h"

#ifdef HAVE_GUI
#include "qgswfssourceselect.h"
Expand Down Expand Up @@ -123,13 +124,31 @@ QVector<QgsDataItem *> QgsWfsConnectionItem::createChildren()
QVector<QgsDataItem *> layers;
if ( capabilities.errorCode() == QgsWfsCapabilities::NoError )
{
const QString projectCrs = QgsProject::instance()->crs().authid();
const auto featureTypes = capabilities.capabilities().featureTypes;
for ( const QgsWfsCapabilities::FeatureType &featureType : featureTypes )
{
// if project CRS is supported then use it, otherwise use first available CRS (which is the default CRS)
QString crs;
if ( !featureType.crslist.isEmpty() )
{
for ( const QString &c : std::as_const( featureType.crslist ) )
{
if ( c.compare( projectCrs, Qt::CaseInsensitive ) == 0 )
{
crs = projectCrs;
break;
}
}

if ( crs.isEmpty() )
{
crs = featureType.crslist.first();
}
}
QgsWfsLayerItem *layer = new QgsWfsLayerItem(
this, mName, uri, featureType.name, featureType.title,
!featureType.crslist.isEmpty() ? featureType.crslist.first() : QString(),
QgsWFSProvider::WFS_PROVIDER_KEY
crs, QgsWFSProvider::WFS_PROVIDER_KEY
);
layers.append( layer );
}
Expand Down
29 changes: 18 additions & 11 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgswmscapabilities.h"
#include "qgswmsconnection.h"
#include "qgsxyzconnection.h"
#include "qgsproject.h"


// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -455,22 +456,28 @@ QString QgsWMSItemBase::createUri( bool withStyle )
}
mDataSourceUri.setParam( QStringLiteral( "format" ), format );

const QString projectCrs = QgsProject::instance()->crs().authid();
QString crs;
// get first known if possible
QgsCoordinateReferenceSystem testCrs;
for ( const QString &c : std::as_const( mLayerProperty.crs ) )
// if project CRS is supported then use it, otherwise use first available CRS
if ( !mLayerProperty.crs.isEmpty() )
{
testCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( c );
if ( testCrs.isValid() )
QgsCoordinateReferenceSystem testCrs;
for ( const QString &c : std::as_const( mLayerProperty.crs ) )
{
crs = c;
break;
testCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( c );
if ( testCrs.authid().compare( projectCrs, Qt::CaseInsensitive ) == 0 )
{
crs = projectCrs;
break;
}
}

if ( crs.isEmpty() )
{
crs = mLayerProperty.crs[0];
}
}
if ( crs.isEmpty() && !mLayerProperty.crs.isEmpty() )
{
crs = mLayerProperty.crs[0];
}

mDataSourceUri.setParam( QStringLiteral( "crs" ), crs );

// Set default featureCount to 10, old connections might miss this
Expand Down
Loading