Skip to content

Commit d06ad4c

Browse files
author
mhugent
committedNov 26, 2007
Improved the crs handling in wfs plugin
git-svn-id: http://svn.osgeo.org/qgis/trunk@7657 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c39a9b7 commit d06ad4c

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed
 

‎src/plugins/wfs/qgswfssourceselect.cpp

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "qgslayerprojectionselector.h"
2222
#include "qgshttptransaction.h"
2323
#include "qgscontexthelp.h"
24+
#include "qgsproject.h"
25+
#include "qgsspatialrefsys.h"
2426
#include <QDomDocument>
2527
#include <QListWidgetItem>
2628
#include <QMessageBox>
@@ -82,6 +84,41 @@ void QgsWFSSourceSelect::populateConnectionList()
8284
}
8385
}
8486

87+
long QgsWFSSourceSelect::getPreferredCrs(const QSet<long>& crsSet) const
88+
{
89+
if(crsSet.size() < 1)
90+
{
91+
return -1;
92+
}
93+
94+
//first: project CRS
95+
long ProjectSRSID = QgsProject::instance()->readNumEntry("SpatialRefSys", "/ProjectSRSID", -1);
96+
//convert to EPSG
97+
QgsSpatialRefSys projectRefSys(ProjectSRSID, QgsSpatialRefSys::QGIS_SRSID);
98+
int ProjectSRS = -1;
99+
if(projectRefSys.isValid())
100+
{
101+
long ProjectSRS = projectRefSys.epsg();
102+
}
103+
104+
if(ProjectSRS != -1)
105+
{
106+
if(crsSet.contains(ProjectSRS))
107+
{
108+
return ProjectSRS;
109+
}
110+
}
111+
112+
//second: WGS84
113+
if(crsSet.contains(4326))
114+
{
115+
return 4326;
116+
}
117+
118+
//third: first entry in set
119+
return *(crsSet.constBegin());
120+
}
121+
85122
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)
86123
{
87124
switch(e)
@@ -318,7 +355,8 @@ void QgsWFSSourceSelect::changeCRS()
318355
{
319356
if(mProjectionSelector->exec())
320357
{
321-
358+
QString crsString = "EPSG: " + QString::number(mProjectionSelector->getCurrentEpsg());
359+
labelCoordRefSys->setText(crsString);
322360
}
323361
}
324362

@@ -335,15 +373,26 @@ void QgsWFSSourceSelect::changeCRSFilter()
335373
if(crsIterator != mAvailableCRS.end())
336374
{
337375
std::list<QString> crsList = crsIterator->second;
338-
QSet<QString> crsSet;
376+
377+
QSet<long> crsSet;
378+
QSet<QString> crsNames;
379+
339380
for(std::list<QString>::const_iterator it = crsList.begin(); it != crsList.end(); ++it)
340381
{
341-
qWarning("inserting " + *it);
342-
crsSet.insert(*it);
382+
crsNames.insert(*it);
383+
crsSet.insert(it->section(":", 1, 1).toLong());
343384
}
344385
if(mProjectionSelector)
345386
{
346-
mProjectionSelector->setOgcWmsCrsFilter(crsSet);
387+
mProjectionSelector->setOgcWmsCrsFilter(crsNames);
388+
long preferredSRS = getPreferredCrs(crsSet); //get preferred EPSG system
389+
if(preferredSRS != -1)
390+
{
391+
QgsSpatialRefSys refSys(preferredSRS);
392+
mProjectionSelector->setSelectedSRSID(refSys.srsid());
393+
394+
labelCoordRefSys->setText("EPSG: " + QString::number(preferredSRS));
395+
}
347396
}
348397
}
349398
}

‎src/plugins/wfs/qgswfssourceselect.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
5151
QAbstractButton* btnAdd;
5252
void populateConnectionList();
5353

54+
/**Returns the best suited CRS from a set of epsg numbers
55+
1. project CRS if contained in the set
56+
2. WGS84 if contained in the set
57+
3. the first entry in the set else
58+
@return the epsg number of the crs or -1 in case of error*/
59+
long getPreferredCrs(const QSet<long>& crsSet) const;
60+
5461
/**Makes a GetCapabilities and returns the typenamse and crs supported by the server.
5562
@param typenames a list of layers provided by the server
5663
@param crs a list of crs supported by the server. The place in the list corresponds to the \

0 commit comments

Comments
 (0)
Please sign in to comment.