21
21
#include " qgslayerprojectionselector.h"
22
22
#include " qgshttptransaction.h"
23
23
#include " qgscontexthelp.h"
24
+ #include " qgsproject.h"
25
+ #include " qgsspatialrefsys.h"
24
26
#include < QDomDocument>
25
27
#include < QListWidgetItem>
26
28
#include < QMessageBox>
@@ -82,6 +84,41 @@ void QgsWFSSourceSelect::populateConnectionList()
82
84
}
83
85
}
84
86
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
+
85
122
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)
86
123
{
87
124
switch (e)
@@ -318,7 +355,8 @@ void QgsWFSSourceSelect::changeCRS()
318
355
{
319
356
if (mProjectionSelector ->exec ())
320
357
{
321
-
358
+ QString crsString = " EPSG: " + QString::number (mProjectionSelector ->getCurrentEpsg ());
359
+ labelCoordRefSys->setText (crsString);
322
360
}
323
361
}
324
362
@@ -335,15 +373,26 @@ void QgsWFSSourceSelect::changeCRSFilter()
335
373
if (crsIterator != mAvailableCRS .end ())
336
374
{
337
375
std::list<QString> crsList = crsIterator->second ;
338
- QSet<QString> crsSet;
376
+
377
+ QSet<long > crsSet;
378
+ QSet<QString> crsNames;
379
+
339
380
for (std::list<QString>::const_iterator it = crsList.begin (); it != crsList.end (); ++it)
340
381
{
341
- qWarning ( " inserting " + *it);
342
- crsSet.insert (*it );
382
+ crsNames. insert ( *it);
383
+ crsSet.insert (it-> section ( " : " , 1 , 1 ). toLong () );
343
384
}
344
385
if (mProjectionSelector )
345
386
{
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
+ }
347
396
}
348
397
}
349
398
}
0 commit comments