Skip to content

Commit

Permalink
[WFS/OGCAPI] In source select dialog box, better handle list of CRS
Browse files Browse the repository at this point in the history
- Use an orderered list instead of a set, so that the first element
  is really the preferred one
- Do not trust the project CRS if the project has no layers: it is
  better to rely on the preferred CRS of the source instead
  • Loading branch information
rouault authored and nyalldawson committed Apr 3, 2023
1 parent b0b2d9b commit 7413c35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
40 changes: 19 additions & 21 deletions src/providers/wfs/qgswfssourceselect.cpp
Expand Up @@ -176,35 +176,33 @@ void QgsWFSSourceSelect::populateConnectionList()
changeConnection();
}

QString QgsWFSSourceSelect::getPreferredCrs( const QSet<QString> &crsSet ) const
QString QgsWFSSourceSelect::getPreferredCrs( const QList<QString> &crsList ) const
{
if ( crsSet.size() < 1 )
if ( crsList.size() < 1 )
{
return QString();
}

//first: project CRS
QgsCoordinateReferenceSystem projectRefSys = QgsProject::instance()->crs();
//convert to EPSG
QString ProjectCRS;
if ( projectRefSys.isValid() )
//first: project CRS (if the project is not empty)
QgsProject *project = QgsProject::instance();
if ( !project->mapLayers().isEmpty() )
{
ProjectCRS = projectRefSys.authid();
}

if ( !ProjectCRS.isEmpty() && crsSet.contains( ProjectCRS ) )
{
return ProjectCRS;
}
QgsCoordinateReferenceSystem projectRefSys = QgsProject::instance()->crs();
//convert to EPSG
QString projectCRS;
if ( projectRefSys.isValid() )
{
projectCRS = projectRefSys.authid();
}

//second: WGS84
if ( crsSet.contains( geoEpsgCrsAuthId() ) )
{
return geoEpsgCrsAuthId();
if ( !projectCRS.isEmpty() && crsList.contains( projectCRS ) )
{
return projectCRS;
}
}

//third: first entry in set
return *( crsSet.constBegin() );
//otherwise: first entry in set
return crsList[0];
}

void QgsWFSSourceSelect::refresh()
Expand Down Expand Up @@ -705,7 +703,7 @@ void QgsWFSSourceSelect::changeCRSFilter()
mProjectionSelector = new QgsProjectionSelectionDialog( this );

mProjectionSelector->setOgcWmsCrsFilter( crsNames );
QString preferredCRS = getPreferredCrs( crsNames ); //get preferred EPSG system
QString preferredCRS = getPreferredCrs( *crsIterator ); //get preferred EPSG system
if ( !preferredCRS.isEmpty() )
{
QgsCoordinateReferenceSystem refSys = QgsCoordinateReferenceSystem::fromOgcWmsCrs( preferredCRS );
Expand Down
9 changes: 4 additions & 5 deletions src/providers/wfs/qgswfssourceselect.h
Expand Up @@ -80,15 +80,14 @@ class QgsWFSSourceSelect: public QgsAbstractDataSourceWidget, private Ui::QgsWFS
QString mVersion;

/**
* Returns the best suited CRS from a set of authority ids
* Returns the best suited CRS from a list of authority ids
*
* 1. project CRS if contained in the set
* 2. WGS84 if contained in the set
* 3. the first entry in the set else
* 1. project CRS if contained in the list and the project is not empty
* 2. the first entry in the list else
*
* \returns the authority id of the crs or an empty string in case of error
*/
QString getPreferredCrs( const QSet<QString> &crsSet ) const;
QString getPreferredCrs( const QList<QString> &crsList ) const;

void showHelp();

Expand Down

0 comments on commit 7413c35

Please sign in to comment.