Skip to content
Permalink
Browse files
More improvements to WMS provider: Coordinate Reference Systems are n…
…ow 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
  • Loading branch information
morb_au committed Mar 4, 2006
1 parent 8ec87ff commit eef2433cfe5398875568d115a99cdbd023b1ac28
@@ -66,6 +66,12 @@ class QgsRasterDataProvider : public QgsDataProvider
* Set the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server
*/
virtual void setImageEncoding(QString const & mimeType) = 0;

/**
* Set the image projection (in WMS CRS format) used in the transfer from (e.g.) the WMS server
*/
virtual void setImageCrs(QString const & crs) = 0;


// TODO: Document this better.
/** \brief Renders the layer as an image
@@ -2055,12 +2055,14 @@ void QgisApp::addWmsLayer()
if (wmss->exec())
{

addRasterLayer(wmss->connInfo(),
wmss->connName(),
addRasterLayer(wmss->connInfo(),
wmss->connName(),
"wms",
wmss->selectedLayers(),
wmss->selectedStylesForSelectedLayers(),
wmss->selectedImageEncoding() );
wmss->selectedImageEncoding(),
wmss->selectedCrs()
);
}
}

@@ -5053,12 +5055,13 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
\note Copied from the equivalent addVectorLayer function in this file
TODO Make it work for rasters specifically.
*/
void QgisApp::addRasterLayer(QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
void QgisApp::addRasterLayer(QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format)
QString const & format,
QString const & crs)
{

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

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

#ifdef QGISDEBUG
std::cout << "QgisApp::addRasterLayer: Constructed new layer." << std::endl;
@@ -111,16 +111,19 @@ class QgisApp : public QMainWindow, public Ui::QgisAppBase
It's much better to try to just open one file at a time.
*/
bool addRasterLayer(QStringList const & theLayerQStringList, bool guiWarning=true);

/** Open a raster layer using the Raster Data Provider.
* Note this is included to support WMS layers only at this stage,
* GDAL layer support via a Provider is not yet implemented.
*/
void addRasterLayer(QString const & rasterLayerPath,
QString const & baseName,
*/
void addRasterLayer(QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format);
QString const & format,
QString const & crs);

/** open a raster layer for the given file
@returns false if unable to open a raster layer for rasterFile
@note
@@ -58,20 +58,21 @@ class QgsCoordinateTransform: public QObject
/*! Default constructor. Make sure you use initialised() manually if you use this one! */
QgsCoordinateTransform() ;

/* Constructs a QgsCoordinateTransform using QgsSpatialRefSys objects.
* @param theSource SRS of the layer's coordinate system
* @param theDest SRS of the map canvas coordinate system
/** Constructs a QgsCoordinateTransform using QgsSpatialRefSys objects.
* @param theSource SRS, typically of the layer's coordinate system
* @param theDest SRS, typically of the map canvas coordinate system
*/
QgsCoordinateTransform(const QgsSpatialRefSys& theSource,
const QgsSpatialRefSys& theDest);

/*!
* Constructs a QgsCoordinateTransform using the Well Known Text representation
* of the layer and map canvas coordinate systems
* @param theSourceWKT WKT of the layer's coordinate system
* @param theSourceWKT WKT of the map canvas coordinate system
* @param theSourceWKT WKT, typically of the layer's coordinate system
* @param theDestWKT WKT, typically of the map canvas coordinate system
*/
QgsCoordinateTransform(QString theSourceWKT, QString theDestWKT );

/*!
* Constructs a QgsCoordinateTransform using a Spatial Reference Id
* of the layer and map canvas coordinate system as Wkt
@@ -82,34 +83,40 @@ class QgsCoordinateTransform: public QObject
QgsCoordinateTransform(long theSourceSrid,
QString theDestWKT,
QgsSpatialRefSys::SRS_TYPE theSourceSRSType = QgsSpatialRefSys::POSTGIS_SRID );

//! destructor
~QgsCoordinateTransform();

//! Enum used to indicate the direction (forward or inverse) of the transform
enum TransformDirection{
FORWARD,
INVERSE
FORWARD, /*!< Transform from source to destination SRS. */
INVERSE /*!< Transform from destination to source SRS. */
};

/*!
* Set the source (layer) QgsSpatialRefSys
* @param theSRS QgsSpatialRefSys representation of the layer's coordinate system
*/
void setSourceSRS(const QgsSpatialRefSys& theSRS);

/*!
* Mutator for dest QgsSpatialRefSys
* @param theSRS of the destination coordinate system
*/
void setDestSRS(const QgsSpatialRefSys& theSRS);
void setDestSRS(const QgsSpatialRefSys& theSRS);

/*!
* Get the QgsSpatialRefSys representation of the layer's coordinate system
* @return QgsSpatialRefSys of the layer's coordinate system
*/
QgsSpatialRefSys& sourceSRS() { return mSourceSRS; }

/*!
* Get the QgsSpatialRefSys representation of the map canvas coordinate system
* @return QgsSpatialRefSys of the map canvas coordinate system
*/
QgsSpatialRefSys& destSRS() { return mDestSRS; }

/*! Transform the point from Source Coordinate System to Destination Coordinate System
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
@@ -118,6 +125,7 @@ class QgsCoordinateTransform: public QObject
* @return QgsPoint in Destination Coordinate System
*/
QgsPoint transform(const QgsPoint p,TransformDirection direction=FORWARD);

/*! Transform the point specified by x,y from Source Coordinate System to Destination Coordinate System
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
@@ -166,15 +174,18 @@ class QgsCoordinateTransform: public QObject
* @return QgsRect in Destination Coordinate System
*/
void transformCoords( const int &numPoint, double *x, double *y, double *z,TransformDirection direction=FORWARD);

/*!
* Flag to indicate whether the coordinate systems have been initialised
* @return true if initialised, otherwise false
*/
bool isInitialised() {return mInitialisedFlag;};

/*! See if the transform short circuits because src and dest are equivalent
* @return bool True if it short circuits
*/
bool isShortCircuited() {return mShortCircuit;};

public slots:
/*! Change the destination coordinate system by passing it a qgis srsid
* 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
* to check if short circuiting is needed or not etc.
* @param theSRSID - A long representing the srsid of the srs to be used */
void setDestSRSID (long theSRSID);

//!initialise is used to actually create the Transformer instance
void initialise();

@@ -194,6 +206,7 @@ class QgsCoordinateTransform: public QObject
* @return bool True on success, False on failure
*/
bool readXML( QDomNode & theNode );

/*! Stores state to the given DOM node in the given document
* @param theNode The node in which state will be restored
* @param theDom The document in which state will be stored
@@ -212,22 +225,27 @@ class QgsCoordinateTransform: public QObject
* equal and not transformation needs to be done
*/
bool mShortCircuit;

/*!
* flag to show whether the transform is properly initialised or not
*/
bool mInitialisedFlag;

/*!
* QgsSpatialRefSys of the source (layer) coordinate system
*/
QgsSpatialRefSys mSourceSRS;

/*!
* QgsSpatialRefSys of the destination (map canvas) coordinate system
*/
QgsSpatialRefSys mDestSRS;

/*!
* Proj4 data structure of the source projection (layer coordinate system)
*/
projPJ mSourceProjection;

/*!
* Proj4 data structure of the destination projection (map canvas coordinate system)
*/
@@ -69,6 +69,35 @@ void QgsSpatialRefSys::createFromId(const long theId, SRS_TYPE theType)

}


bool QgsSpatialRefSys::createFromOgcWmsCrs(QString theCrs)
{
QStringList parts = theCrs.split(":");

if (parts.at(0) == "EPSG")
{
createFromEpsg( parts.at(1).toLong() );
}
else if (parts.at(0) == "CRS")
{
if (parts.at(1) == "84")
{
//! \todo - CRS:84 is hardcoded to EPSG:4326 - see if this is appropriate
/**
* See WMS 1.3 standard appendix B3 for details
*/
createFromEpsg( 4326 );
}
}
else
{
return FALSE;
}

return TRUE;
}


// Assignment operator
QgsSpatialRefSys& QgsSpatialRefSys::operator=(const QgsSpatialRefSys& srs)
{
@@ -306,7 +335,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
bool QgsSpatialRefSys::createFromEpsg(long theEpsg)
{
#ifdef QGISDEBUG
std::cout << " QgsSpatialRefSys::createFromEpsg" << std::endl;
std::cout << "QgsSpatialRefSys::createFromEpsg with " << theEpsg << std::endl;
#endif
// Get the full path name to the sqlite3 spatial reference database.
QString myDatabaseFileName = QgsApplication::srsDbFilePath();
@@ -75,15 +75,27 @@ class QgsSpatialRefSys

// Misc helper functions -----------------------

void createFromId(const long theId, SRS_TYPE theType=POSTGIS_SRID);

void createFromId(const long theId, SRS_TYPE theType=POSTGIS_SRID);

/**
* \brief Set up this SRS from the given OGC CRS
*
* Sets this SRS to the given OGC WMS-format Coordinate Reference Systems.
*
* \note This function only deals with EPSG labels only at this time.
*
* \retval FALSE if not given an EPSG label
*/
bool createFromOgcWmsCrs(QString theCrs);

/*! Set up this srs by fetching the appropriate information from the
* sqlite backend. First the system level read only srs.db will be checked
* and then the users ~/.qgis/qgis.db database will be checked for a match.
* @note Any members will be overwritten during this process.
* @param theSrid The postgis SRID for the desired spatial reference system.
*/
bool createFromSrid(const long theSrid);

/*! Set up this srs using a WKT spatial ref sys definition.
* The wkt will be converted to a proj4 string using OGR helper
* functions. After this the srs databasses will be searched for matches.
@@ -95,6 +107,7 @@ class QgsSpatialRefSys
* @return bool TRUE if sucess else false
*/
bool createFromWkt(const QString theWkt);

/*! Set up this srs by fetching the appropriate information from the
* sqlite backend. First the system level read only srs.db will be checked
* and then the users ~/.qgis/qgis.db database will be checked for a match.
@@ -103,6 +116,7 @@ class QgsSpatialRefSys
* @return bool TRUE if sucess else false
*/
bool createFromEpsg(const long theEpsg);

/*! Set up this srs by fetching the appropriate information from the
* sqlite backend. If the srsid is < 100000, only the system srs.db
* will be checked. If the srsid > 100000 the srs will be retrieved from

0 comments on commit eef2433

Please sign in to comment.