Skip to content

Commit

Permalink
Improved the crs handling in wfs plugin
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7657 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 26, 2007
1 parent fca8d39 commit e47d33b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
59 changes: 54 additions & 5 deletions src/plugins/wfs/qgswfssourceselect.cpp
Expand Up @@ -21,6 +21,8 @@
#include "qgslayerprojectionselector.h"
#include "qgshttptransaction.h"
#include "qgscontexthelp.h"
#include "qgsproject.h"
#include "qgsspatialrefsys.h"
#include <QDomDocument>
#include <QListWidgetItem>
#include <QMessageBox>
Expand Down Expand Up @@ -82,6 +84,41 @@ void QgsWFSSourceSelect::populateConnectionList()
}
}

long QgsWFSSourceSelect::getPreferredCrs(const QSet<long>& crsSet) const
{
if(crsSet.size() < 1)
{
return -1;
}

//first: project CRS
long ProjectSRSID = QgsProject::instance()->readNumEntry("SpatialRefSys", "/ProjectSRSID", -1);
//convert to EPSG
QgsSpatialRefSys projectRefSys(ProjectSRSID, QgsSpatialRefSys::QGIS_SRSID);
int ProjectSRS = -1;
if(projectRefSys.isValid())
{
long ProjectSRS = projectRefSys.epsg();
}

if(ProjectSRS != -1)
{
if(crsSet.contains(ProjectSRS))
{
return ProjectSRS;
}
}

//second: WGS84
if(crsSet.contains(4326))
{
return 4326;
}

//third: first entry in set
return *(crsSet.constBegin());
}

int QgsWFSSourceSelect::getCapabilities(const QString& uri, QgsWFSSourceSelect::REQUEST_ENCODING e, std::list<QString>& typenames, std::list< std::list<QString> >& crs, std::list<QString>& titles, std::list<QString>& abstracts)
{
switch(e)
Expand Down Expand Up @@ -318,7 +355,8 @@ void QgsWFSSourceSelect::changeCRS()
{
if(mProjectionSelector->exec())
{

QString crsString = "EPSG: " + QString::number(mProjectionSelector->getCurrentEpsg());
labelCoordRefSys->setText(crsString);
}
}

Expand All @@ -335,15 +373,26 @@ void QgsWFSSourceSelect::changeCRSFilter()
if(crsIterator != mAvailableCRS.end())
{
std::list<QString> crsList = crsIterator->second;
QSet<QString> crsSet;

QSet<long> crsSet;
QSet<QString> crsNames;

for(std::list<QString>::const_iterator it = crsList.begin(); it != crsList.end(); ++it)
{
qWarning("inserting " + *it);
crsSet.insert(*it);
crsNames.insert(*it);
crsSet.insert(it->section(":", 1, 1).toLong());
}
if(mProjectionSelector)
{
mProjectionSelector->setOgcWmsCrsFilter(crsSet);
mProjectionSelector->setOgcWmsCrsFilter(crsNames);
long preferredSRS = getPreferredCrs(crsSet); //get preferred EPSG system
if(preferredSRS != -1)
{
QgsSpatialRefSys refSys(preferredSRS);
mProjectionSelector->setSelectedSRSID(refSys.srsid());

labelCoordRefSys->setText("EPSG: " + QString::number(preferredSRS));
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/wfs/qgswfssourceselect.h
Expand Up @@ -51,6 +51,13 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
QAbstractButton* btnAdd;
void populateConnectionList();

/**Returns the best suited CRS from a set of epsg numbers
1. project CRS if contained in the set
2. WGS84 if contained in the set
3. the first entry in the set else
@return the epsg number of the crs or -1 in case of error*/
long getPreferredCrs(const QSet<long>& crsSet) const;

/**Makes a GetCapabilities and returns the typenamse and crs supported by the server.
@param typenames a list of layers provided by the server
@param crs a list of crs supported by the server. The place in the list corresponds to the \
Expand Down

0 comments on commit e47d33b

Please sign in to comment.