Skip to content

Commit eef2433

Browse files
author
morb_au
committed
More improvements to WMS provider: Coordinate Reference Systems are now handled end-to-end in a basic fashion by the WMS provider. However the Project Projection still needs to be made aware of what the WMS provider is doing.
* Correction and readability enhancements of commentary in QgsCoordinateTransform. * QgsSpatialRefSys can now create from the OGC WMS CRS format. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4968 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8ec87ff commit eef2433

10 files changed

+188
-53
lines changed

src/core/qgsrasterdataprovider.h

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class QgsRasterDataProvider : public QgsDataProvider
6666
* Set the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server
6767
*/
6868
virtual void setImageEncoding(QString const & mimeType) = 0;
69+
70+
/**
71+
* Set the image projection (in WMS CRS format) used in the transfer from (e.g.) the WMS server
72+
*/
73+
virtual void setImageCrs(QString const & crs) = 0;
74+
6975

7076
// TODO: Document this better.
7177
/** \brief Renders the layer as an image

src/gui/qgisapp.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -2055,12 +2055,14 @@ void QgisApp::addWmsLayer()
20552055
if (wmss->exec())
20562056
{
20572057

2058-
addRasterLayer(wmss->connInfo(),
2059-
wmss->connName(),
2058+
addRasterLayer(wmss->connInfo(),
2059+
wmss->connName(),
20602060
"wms",
20612061
wmss->selectedLayers(),
20622062
wmss->selectedStylesForSelectedLayers(),
2063-
wmss->selectedImageEncoding() );
2063+
wmss->selectedImageEncoding(),
2064+
wmss->selectedCrs()
2065+
);
20642066
}
20652067
}
20662068

@@ -5053,12 +5055,13 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
50535055
\note Copied from the equivalent addVectorLayer function in this file
50545056
TODO Make it work for rasters specifically.
50555057
*/
5056-
void QgisApp::addRasterLayer(QString const & rasterLayerPath,
5057-
QString const & baseName,
5058-
QString const & providerKey,
5058+
void QgisApp::addRasterLayer(QString const & rasterLayerPath,
5059+
QString const & baseName,
5060+
QString const & providerKey,
50595061
QStringList const & layers,
50605062
QStringList const & styles,
5061-
QString const & format)
5063+
QString const & format,
5064+
QString const & crs)
50625065
{
50635066

50645067
#ifdef QGISDEBUG
@@ -5083,11 +5086,12 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
50835086
" and layer list of " << layers.join(", ").toLocal8Bit().data() <<
50845087
" and style list of " << styles.join(", ").toLocal8Bit().data() <<
50855088
" and format of " << format.toLocal8Bit().data() <<
5086-
" and providerKey of " << providerKey.toLocal8Bit().data() << std::endl;
5089+
" and providerKey of " << providerKey.toLocal8Bit().data() <<
5090+
" and CRS of " << crs.toLocal8Bit().data() << std::endl;
50875091
#endif
50885092

50895093
// TODO: Remove the 0 when the raster layer becomes a full provider gateway.
5090-
layer = new QgsRasterLayer(0, rasterLayerPath, baseName, providerKey, layers, styles, format);
5094+
layer = new QgsRasterLayer(0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs);
50915095

50925096
#ifdef QGISDEBUG
50935097
std::cout << "QgisApp::addRasterLayer: Constructed new layer." << std::endl;

src/gui/qgisapp.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,19 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
111111
It's much better to try to just open one file at a time.
112112
*/
113113
bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);
114+
114115
/** Open a raster layer using the Raster Data Provider.
115116
* Note this is included to support WMS layers only at this stage,
116117
* GDAL layer support via a Provider is not yet implemented.
117-
*/
118-
void addRasterLayer(QString const & rasterLayerPath,
119-
QString const & baseName,
118+
*/
119+
void addRasterLayer(QString const & rasterLayerPath,
120+
QString const & baseName,
120121
QString const & providerKey,
121122
QStringList const & layers,
122123
QStringList const & styles,
123-
QString const & format);
124+
QString const & format,
125+
QString const & crs);
126+
124127
/** open a raster layer for the given file
125128
@returns false if unable to open a raster layer for rasterFile
126129
@note

src/gui/qgscoordinatetransform.h

+26-8
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,21 @@ class QgsCoordinateTransform: public QObject
5858
/*! Default constructor. Make sure you use initialised() manually if you use this one! */
5959
QgsCoordinateTransform() ;
6060

61-
/* Constructs a QgsCoordinateTransform using QgsSpatialRefSys objects.
62-
* @param theSource SRS of the layer's coordinate system
63-
* @param theDest SRS of the map canvas coordinate system
61+
/** Constructs a QgsCoordinateTransform using QgsSpatialRefSys objects.
62+
* @param theSource SRS, typically of the layer's coordinate system
63+
* @param theDest SRS, typically of the map canvas coordinate system
6464
*/
6565
QgsCoordinateTransform(const QgsSpatialRefSys& theSource,
6666
const QgsSpatialRefSys& theDest);
6767

6868
/*!
6969
* Constructs a QgsCoordinateTransform using the Well Known Text representation
7070
* of the layer and map canvas coordinate systems
71-
* @param theSourceWKT WKT of the layer's coordinate system
72-
* @param theSourceWKT WKT of the map canvas coordinate system
71+
* @param theSourceWKT WKT, typically of the layer's coordinate system
72+
* @param theDestWKT WKT, typically of the map canvas coordinate system
7373
*/
7474
QgsCoordinateTransform(QString theSourceWKT, QString theDestWKT );
75+
7576
/*!
7677
* Constructs a QgsCoordinateTransform using a Spatial Reference Id
7778
* of the layer and map canvas coordinate system as Wkt
@@ -82,34 +83,40 @@ class QgsCoordinateTransform: public QObject
8283
QgsCoordinateTransform(long theSourceSrid,
8384
QString theDestWKT,
8485
QgsSpatialRefSys::SRS_TYPE theSourceSRSType = QgsSpatialRefSys::POSTGIS_SRID );
86+
8587
//! destructor
8688
~QgsCoordinateTransform();
89+
8790
//! Enum used to indicate the direction (forward or inverse) of the transform
8891
enum TransformDirection{
89-
FORWARD,
90-
INVERSE
92+
FORWARD, /*!< Transform from source to destination SRS. */
93+
INVERSE /*!< Transform from destination to source SRS. */
9194
};
9295

9396
/*!
9497
* Set the source (layer) QgsSpatialRefSys
9598
* @param theSRS QgsSpatialRefSys representation of the layer's coordinate system
9699
*/
97100
void setSourceSRS(const QgsSpatialRefSys& theSRS);
101+
98102
/*!
99103
* Mutator for dest QgsSpatialRefSys
100104
* @param theSRS of the destination coordinate system
101105
*/
102-
void setDestSRS(const QgsSpatialRefSys& theSRS);
106+
void setDestSRS(const QgsSpatialRefSys& theSRS);
107+
103108
/*!
104109
* Get the QgsSpatialRefSys representation of the layer's coordinate system
105110
* @return QgsSpatialRefSys of the layer's coordinate system
106111
*/
107112
QgsSpatialRefSys& sourceSRS() { return mSourceSRS; }
113+
108114
/*!
109115
* Get the QgsSpatialRefSys representation of the map canvas coordinate system
110116
* @return QgsSpatialRefSys of the map canvas coordinate system
111117
*/
112118
QgsSpatialRefSys& destSRS() { return mDestSRS; }
119+
113120
/*! Transform the point from Source Coordinate System to Destination Coordinate System
114121
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
115122
* otherwise points are transformed from map canvas CS to layerCS.
@@ -118,6 +125,7 @@ class QgsCoordinateTransform: public QObject
118125
* @return QgsPoint in Destination Coordinate System
119126
*/
120127
QgsPoint transform(const QgsPoint p,TransformDirection direction=FORWARD);
128+
121129
/*! Transform the point specified by x,y from Source Coordinate System to Destination Coordinate System
122130
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
123131
* otherwise points are transformed from map canvas CS to layerCS.
@@ -166,15 +174,18 @@ class QgsCoordinateTransform: public QObject
166174
* @return QgsRect in Destination Coordinate System
167175
*/
168176
void transformCoords( const int &numPoint, double *x, double *y, double *z,TransformDirection direction=FORWARD);
177+
169178
/*!
170179
* Flag to indicate whether the coordinate systems have been initialised
171180
* @return true if initialised, otherwise false
172181
*/
173182
bool isInitialised() {return mInitialisedFlag;};
183+
174184
/*! See if the transform short circuits because src and dest are equivalent
175185
* @return bool True if it short circuits
176186
*/
177187
bool isShortCircuited() {return mShortCircuit;};
188+
178189
public slots:
179190
/*! Change the destination coordinate system by passing it a qgis srsid
180191
* A QGIS srsid is a unique key value to an entry on the tbl_srs in the
@@ -186,6 +197,7 @@ class QgsCoordinateTransform: public QObject
186197
* to check if short circuiting is needed or not etc.
187198
* @param theSRSID - A long representing the srsid of the srs to be used */
188199
void setDestSRSID (long theSRSID);
200+
189201
//!initialise is used to actually create the Transformer instance
190202
void initialise();
191203

@@ -194,6 +206,7 @@ class QgsCoordinateTransform: public QObject
194206
* @return bool True on success, False on failure
195207
*/
196208
bool readXML( QDomNode & theNode );
209+
197210
/*! Stores state to the given DOM node in the given document
198211
* @param theNode The node in which state will be restored
199212
* @param theDom The document in which state will be stored
@@ -212,22 +225,27 @@ class QgsCoordinateTransform: public QObject
212225
* equal and not transformation needs to be done
213226
*/
214227
bool mShortCircuit;
228+
215229
/*!
216230
* flag to show whether the transform is properly initialised or not
217231
*/
218232
bool mInitialisedFlag;
233+
219234
/*!
220235
* QgsSpatialRefSys of the source (layer) coordinate system
221236
*/
222237
QgsSpatialRefSys mSourceSRS;
238+
223239
/*!
224240
* QgsSpatialRefSys of the destination (map canvas) coordinate system
225241
*/
226242
QgsSpatialRefSys mDestSRS;
243+
227244
/*!
228245
* Proj4 data structure of the source projection (layer coordinate system)
229246
*/
230247
projPJ mSourceProjection;
248+
231249
/*!
232250
* Proj4 data structure of the destination projection (map canvas coordinate system)
233251
*/

src/gui/qgsspatialrefsys.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ void QgsSpatialRefSys::createFromId(const long theId, SRS_TYPE theType)
6969

7070
}
7171

72+
73+
bool QgsSpatialRefSys::createFromOgcWmsCrs(QString theCrs)
74+
{
75+
QStringList parts = theCrs.split(":");
76+
77+
if (parts.at(0) == "EPSG")
78+
{
79+
createFromEpsg( parts.at(1).toLong() );
80+
}
81+
else if (parts.at(0) == "CRS")
82+
{
83+
if (parts.at(1) == "84")
84+
{
85+
//! \todo - CRS:84 is hardcoded to EPSG:4326 - see if this is appropriate
86+
/**
87+
* See WMS 1.3 standard appendix B3 for details
88+
*/
89+
createFromEpsg( 4326 );
90+
}
91+
}
92+
else
93+
{
94+
return FALSE;
95+
}
96+
97+
return TRUE;
98+
}
99+
100+
72101
// Assignment operator
73102
QgsSpatialRefSys& QgsSpatialRefSys::operator=(const QgsSpatialRefSys& srs)
74103
{
@@ -306,7 +335,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
306335
bool QgsSpatialRefSys::createFromEpsg(long theEpsg)
307336
{
308337
#ifdef QGISDEBUG
309-
std::cout << " QgsSpatialRefSys::createFromEpsg" << std::endl;
338+
std::cout << "QgsSpatialRefSys::createFromEpsg with " << theEpsg << std::endl;
310339
#endif
311340
// Get the full path name to the sqlite3 spatial reference database.
312341
QString myDatabaseFileName = QgsApplication::srsDbFilePath();

src/gui/qgsspatialrefsys.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,27 @@ class QgsSpatialRefSys
7575

7676
// Misc helper functions -----------------------
7777

78-
void createFromId(const long theId, SRS_TYPE theType=POSTGIS_SRID);
79-
78+
void createFromId(const long theId, SRS_TYPE theType=POSTGIS_SRID);
79+
80+
/**
81+
* \brief Set up this SRS from the given OGC CRS
82+
*
83+
* Sets this SRS to the given OGC WMS-format Coordinate Reference Systems.
84+
*
85+
* \note This function only deals with EPSG labels only at this time.
86+
*
87+
* \retval FALSE if not given an EPSG label
88+
*/
89+
bool createFromOgcWmsCrs(QString theCrs);
90+
8091
/*! Set up this srs by fetching the appropriate information from the
8192
* sqlite backend. First the system level read only srs.db will be checked
8293
* and then the users ~/.qgis/qgis.db database will be checked for a match.
8394
* @note Any members will be overwritten during this process.
8495
* @param theSrid The postgis SRID for the desired spatial reference system.
8596
*/
8697
bool createFromSrid(const long theSrid);
98+
8799
/*! Set up this srs using a WKT spatial ref sys definition.
88100
* The wkt will be converted to a proj4 string using OGR helper
89101
* functions. After this the srs databasses will be searched for matches.
@@ -95,6 +107,7 @@ class QgsSpatialRefSys
95107
* @return bool TRUE if sucess else false
96108
*/
97109
bool createFromWkt(const QString theWkt);
110+
98111
/*! Set up this srs by fetching the appropriate information from the
99112
* sqlite backend. First the system level read only srs.db will be checked
100113
* and then the users ~/.qgis/qgis.db database will be checked for a match.
@@ -103,6 +116,7 @@ class QgsSpatialRefSys
103116
* @return bool TRUE if sucess else false
104117
*/
105118
bool createFromEpsg(const long theEpsg);
119+
106120
/*! Set up this srs by fetching the appropriate information from the
107121
* sqlite backend. If the srsid is < 100000, only the system srs.db
108122
* will be checked. If the srsid > 100000 the srs will be retrieved from

0 commit comments

Comments
 (0)