Improved the crs handling in wfs plugin

git-svn-id: http://svn.osgeo.org/qgis/trunk@7657 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2007-11-26 11:34:25 +00:00
parent c39a9b743f
commit d06ad4c31c
2 changed files with 61 additions and 5 deletions

View File

@ -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>
@ -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)
@ -318,7 +355,8 @@ void QgsWFSSourceSelect::changeCRS()
{
if(mProjectionSelector->exec())
{
QString crsString = "EPSG: " + QString::number(mProjectionSelector->getCurrentEpsg());
labelCoordRefSys->setText(crsString);
}
}
@ -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));
}
}
}
}

View File

@ -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 \