Index: python/core/qgsrasterdataprovider.sip =================================================================== --- python/core/qgsrasterdataprovider.sip (revision 11421) +++ python/core/qgsrasterdataprovider.sip (working copy) @@ -1,135 +1,161 @@ - -/** Base class for raster data providers - * - * \note This class has been copied and pasted from - * QgsVectorDataProvider, and does not yet make - * sense for Raster layers. - */ - -class QgsRasterDataProvider : QgsDataProvider -{ -%TypeHeaderCode -#include -%End - -public: - - //! If you add to this, please also add to capabilitiesString() - enum Capability - { - NoCapabilities = 0, - Identify = 1 -// Capability2 = 1 << 1, etc - }; - - - QgsRasterDataProvider(); - - QgsRasterDataProvider( const QString & uri ); - - virtual ~QgsRasterDataProvider(); - - /** - * Add the list of WMS layer names to be rendered by this server - */ - virtual void addLayers(const QStringList & layers, - const QStringList & styles = QStringList()) = 0; - - //! get raster image encodings supported by (e.g.) the WMS Server, expressed as MIME types - virtual QStringList supportedImageEncodings() = 0; - - /** - * Get the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server - */ - virtual QString imageEncoding() const = 0; - - /** - * Set the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server - */ - virtual void setImageEncoding(const QString & mimeType) = 0; - - /** - * Set the image projection (in WMS CRS format) used in the transfer from (e.g.) the WMS server - */ - virtual void setImageCrs(const QString & crs) = 0; - - - // TODO: Document this better. - /** \brief Renders the layer as an image - */ - virtual QImage* draw(const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight) = 0; - - /** Returns a bitmask containing the supported capabilities - Note, some capabilities may change depending on whether - a spatial filter is active on this provider, so it may - be prudent to check this value per intended operation. - */ - virtual int capabilities() const; - - /** - * Returns the above in friendly format. - */ - QString capabilitiesString() const; - - - // TODO: Get the supported formats by this provider - - // TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box - - - /** - * Get metadata in a format suitable for feeding directly - * into a subset of the GUI raster properties "Metadata" tab. - */ - virtual QString metadata() = 0; - - /** - * \brief Identify details from a server (e.g. WMS) from the last screen update - * - * \param point[in] The pixel coordinate (as it was displayed locally on screen) - * - * \return A text document containing the return from the WMS server - * - * \note WMS Servers prefer to receive coordinates in image space, therefore - * this function expects coordinates in that format. - * - * \note The arbitraryness of the returned document is enforced by WMS standards - * up to at least v1.3.0 - */ - virtual QString identifyAsText(const QgsPoint& point) = 0; - - /** - * \brief Returns the caption error text for the last error in this provider - * - * If an operation returns 0 (e.g. draw()), this function - * returns the text of the error associated with the failure. - * Interactive users of this provider can then, for example, - * call a QMessageBox to display the contents. - * - */ - virtual QString lastErrorTitle() = 0; - - /** - * \brief Returns the verbose error text for the last error in this provider - * - * If an operation returns 0 (e.g. draw()), this function - * returns the text of the error associated with the failure. - * Interactive users of this provider can then, for example, - * call a QMessageBox to display the contents. - * - */ - virtual QString lastError() = 0; - - /**Returns the dpi of the output device. - @note: this method was added in version 1.2*/ - int dpi(); - - /**Sets the output device resolution. - @note: this method was added in version 1.2*/ - void setDpi(int dpi); - - -protected: - -}; - + +/** Base class for raster data providers + * + * \note This class has been copied and pasted from + * QgsVectorDataProvider, and does not yet make + * sense for Raster layers. + */ + +class QgsRasterDataProvider : QgsDataProvider +{ +%TypeHeaderCode +#include +%End + +public: + + //! If you add to this, please also add to capabilitiesString() + enum Capability + { + NoCapabilities = 0, + Identify = 1 +// Capability2 = 1 << 1, etc + }; + + + QgsRasterDataProvider(); + + QgsRasterDataProvider( const QString & uri ); + + virtual ~QgsRasterDataProvider(); + + /** + * Add the list of WMS layer names to be rendered by this server + */ + virtual void addLayers(const QStringList & layers, + const QStringList & styles = QStringList()) = 0; + + //! get raster image encodings supported by (e.g.) the WMS Server, expressed as MIME types + virtual QStringList supportedImageEncodings() = 0; + + /** + * Get the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server + */ + virtual QString imageEncoding() const = 0; + + /** + * Set the image encoding (as a MIME type) used in the transfer from (e.g.) the WMS server + */ + virtual void setImageEncoding(const QString & mimeType) = 0; + + /** + * Set the image projection (in WMS CRS format) used in the transfer from (e.g.) the WMS server + */ + virtual void setImageCrs(const QString & crs) = 0; + + + /** + * Set the url of sld document + * Added in qgis version 1.2 + */ + virtual void setSLDURL( const QString & sldURL ) = 0; + /** + * Retrieves the url of sld document + * Added in qgis version 1.2 + */ + virtual QString sldURL()=0; + /** + * Set the sld document body + * Added in qgis version 1.2 + */ + virtual void setSLDBody( const QString & sldBody ) = 0; + + /** + * Retrieves the sld document body + * Added in qgis version 1.2 + */ + virtual QString sldBody() = 0; + + // TODO: Document this better. + /** \brief Renders the layer as an image + */ + + // TODO: Document this better. + /** \brief Renders the layer as an image + */ + virtual QImage* draw(const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight) = 0; + + /** Returns a bitmask containing the supported capabilities + Note, some capabilities may change depending on whether + a spatial filter is active on this provider, so it may + be prudent to check this value per intended operation. + */ + virtual int capabilities() const; + + /** + * Returns the above in friendly format. + */ + QString capabilitiesString() const; + + + // TODO: Get the supported formats by this provider + + // TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box + + + /** + * Get metadata in a format suitable for feeding directly + * into a subset of the GUI raster properties "Metadata" tab. + */ + virtual QString metadata() = 0; + + /** + * \brief Identify details from a server (e.g. WMS) from the last screen update + * + * \param point[in] The pixel coordinate (as it was displayed locally on screen) + * + * \return A text document containing the return from the WMS server + * + * \note WMS Servers prefer to receive coordinates in image space, therefore + * this function expects coordinates in that format. + * + * \note The arbitraryness of the returned document is enforced by WMS standards + * up to at least v1.3.0 + */ + virtual QString identifyAsText(const QgsPoint& point) = 0; + + /** + * \brief Returns the caption error text for the last error in this provider + * + * If an operation returns 0 (e.g. draw()), this function + * returns the text of the error associated with the failure. + * Interactive users of this provider can then, for example, + * call a QMessageBox to display the contents. + * + */ + virtual QString lastErrorTitle() = 0; + + /** + * \brief Returns the verbose error text for the last error in this provider + * + * If an operation returns 0 (e.g. draw()), this function + * returns the text of the error associated with the failure. + * Interactive users of this provider can then, for example, + * call a QMessageBox to display the contents. + * + */ + virtual QString lastError() = 0; + + /**Returns the dpi of the output device. + @note: this method was added in version 1.2*/ + int dpi(); + + /**Sets the output device resolution. + @note: this method was added in version 1.2*/ + void setDpi(int dpi); + + +protected: + +}; + Index: python/core/qgsrasterlayer.sip =================================================================== --- python/core/qgsrasterlayer.sip (revision 11421) +++ python/core/qgsrasterlayer.sip (working copy) @@ -1,498 +1,506 @@ -/*! \class QgsRasterLayer - * \brief This class provides qgis with the ability to render raster datasets - * onto the mapcanvas.. - */ - -class QgsRasterLayer : QgsMapLayer -{ -%TypeHeaderCode -#include -#include -#include -#include -#include -%End - -public: - /** \brief This is the constructor for the RasterLayer class. - * - * The main tasks carried out by the constructor are: - * - * -Load the rasters default style (.qml) file if it exists - * - * -Populate the RasterStatsVector with initial values for each band. - * - * -Calculate the layer extents - * - * -Determine whether the layer is gray, paletted or multiband. - * - * -Assign sensible defaults for the red, green, blue and gray bands. - * - * - - * */ - QgsRasterLayer( const QString & path = QString::null, - const QString & baseName = QString::null, - bool loadDefaultStyleFlag = true ); - - /** \brief [ data provider interface ] Constructor in provider mode */ - QgsRasterLayer( int dummy, - const QString & baseName = QString(), - const QString & path = QString(), - const QString & providerLib = QString(), - const QStringList & layers = QStringList(), - const QStringList & styles = QStringList(), - const QString & format = QString(), - const QString & crs = QString()); - - - /** \brief The destructor */ - ~QgsRasterLayer(); - - - // - // Enums, structs and typedefs - // - /** \brief This enumerator describes the types of shading that can be used */ - enum ColorShadingAlgorithm - { - UndefinedShader, - PseudoColorShader, - FreakOutShader, - ColorRampShader, - UserDefinedShader - }; - - /** \brief This enumerator describes the different kinds of drawing we can do */ - enum DrawingStyle - { - UndefinedDrawingStyle, - SingleBandGray, // a single band image drawn as a range of gray colors - SingleBandPseudoColor, // a single band image drawn using a pseudocolor algorithm - PalettedColor, //a "Palette" image drawn using color table - PalettedSingleBandGray, // a "Palette" layer drawn in gray scale - PalettedSingleBandPseudoColor, // a "Palette" layerdrawn using a pseudocolor algorithm - PalettedMultiBandColor, // currently not supported - MultiBandSingleGandGray, // a layer containing 2 or more bands, but a single band drawn as a range of gray colors - MultiBandSingleBandPseudoColor, //a layer containing 2 or more bands, but a single band drawn using a pseudocolor algorithm - MultiBandColor //a layer containing 2 or more bands, mapped to RGB color space. - //In the case of a multiband with only two bands, one band will be mapped to more than one color. - }; - - /** \brief This enumerator describes the type of raster layer */ - enum LayerType - { - GrayOrUndefined, - Palette, - Multiband - } ; - - /** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */ - typedef QList ContrastEnhancementList; - - /** \brief A list containing one RasterPyramid struct per raster band in this raster layer. - * POTENTIAL pyramid layer. This works by dividing the height - * and width of the raster by an incrementing number. As soon as the result - * of the division is <=256 we stop allowing RasterPyramid structs - * to be added to the list. Each time a RasterPyramid is created - * we will check to see if a pyramid matching these dimensions already exists - * in the raster layer, and if so mark the exists flag as true */ - typedef QList RasterPyramidList; - - /** \brief A list containing one RasterBandStats struct per raster band in this raster layer. - * Note that while every RasterBandStats element will have the name and number of its associated - * band populated, any additional stats are calculated on a need to know basis.*/ - typedef QList RasterStatsList; - - - - - - // - // Static methods: - // - static void buildSupportedRasterFileFilter( QString & fileFilters ); - - /** This helper checks to see whether the file name appears to be a valid - * raster file name. If the file name looks like it could be valid, - * but some sort of error occurs in processing the file, the error is - * returned in retError. - */ - static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError ); - - static bool isValidRasterFileName( const QString & theFileNameQString ); - - /** Return time stamp for given file name */ - static QDateTime lastModified( const QString & name ); - - /** \brief ensures that GDAL drivers are registered, but only once */ - static void registerGdalDrivers(); - - - - - // - // Non Static inline methods - // - - /** \brief Accessor for blue band name mapping */ - QString blueBandName() const; - - /** \brief Accessor for color shader algorithm */ - QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const; - - /** \brief Accessor for contrast enhancement algorithm */ - QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm(); - - /** \brief Returns contrast enhancement algorithm as a string */ - QString contrastEnhancementAlgorithmAsString() const; - - /** \brief Accessor for drawing style */ - DrawingStyle drawingStyle(); - - /** \brief Accessor for gray band name mapping */ - QString grayBandName() const; - - /** \brief Accessor for green band name mapping */ - QString greenBandName() const; - - /** \brief Accessor for mHasPyramids (READ ONLY) */ - bool hasPyramids(); - - /** \brief Accessor for mUserDefinedGrayMinimumMaximum */ - bool hasUserDefinedGrayMinimumMaximum() const; - - /** \brief Accessor for mUserDefinedRGBMinimumMaximum */ - bool hasUserDefinedRGBMinimumMaximum() const; - - /** \brief Accessor that returns the height of the (unclipped) raster */ - int height(); - - /** \brief Accessor to find out whether the histogram should be inverted */ - bool invertHistogram() const; - - /** \brief Is the NoDataValue Valid */ - bool isNoDataValueValid() const; - - /** \brief Accessor for mGrayMinimumMaximumEstimated */ - bool isGrayMinimumMaximumEstimated() const; - - /** \brief Accessor for mRGBMinimumMaximumEstimated */ - bool isRGBMinimumMaximumEstimated() const; - - /** \brief Accessor that returns the NO_DATA entry for this raster */ - double noDataValue( bool* isValid = 0 ); - - /** \brief Returns a pointer to the transparency object */ - QgsRasterTransparency* rasterTransparency(); - - /** \brief Accessor for raster shader */ - QgsRasterShader* rasterShader(); - - /** \brief Accessor for raster layer type (which is a read only property) */ - LayerType rasterType(); - - /** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red color) */ - QString redBandName(); - - /** [ data provider interface ] Set the data provider */ - void setDataProvider( const QString & provider, - const QStringList & layers, - const QStringList & styles, - const QString & format, - const QString & crs ); - - /** \brief Mutator for drawing style */ - void setDrawingStyle( const DrawingStyle & theDrawingStyle ); - - /** \brief Mutator for mGrayMinimumMaximumEstimated */ - void setGrayMinimumMaximumEstimated( bool theBool ); - - /** \brief Mutator to alter the state of the invert histogram flag */ - void setInvertHistogram( bool theFlag ); - - /** \brief Mutator for mRGBMinimumMaximumEstimated */ - void setRGBMinimumMaximumEstimated( bool theBool ); - - /** \brief Mutator to alter the number of standard deviations that should be plotted */ - void setStandardDeviations( double theStdDevsToPlot ); - - /** \brief Mutator for mUserDefinedGrayMinimumMaximum */ - void setUserDefinedGrayMinimumMaximum( bool theBool ); - - /** \brief Mutator for mUserDefinedRGBMinimumMaximum */ - void setUserDefinedRGBMinimumMaximum( bool theBool ); - - /** \brief Accessor to find out how many standard deviations are being plotted */ - double standardDeviations() const; - - /** \brief Accessor for transparent band name mapping */ - QString transparentBandName() const; - - /** \brief [ data provider interface ] Does this layer use a provider for setting/retrieving data? */ - bool usesProvider(); - - /** \brief Accessor that returns the width of the (unclipped) raster */ - int width(); - - - - - - // - // Non Static methods - // - /** \brief Get the number of bands in this layer */ - unsigned int bandCount(); - - /** \brief Get the name of a band given its number */ - const QString bandName( int theBandNoInt ); - - /** \brief Get the number of a band given its name. The name is the rewritten name set - * up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal! - * If no matching band is found zero will be returned! */ - int bandNumber( const QString & theBandName ); - - /** \brief Get RasterBandStats for a band given its number (read only) */ - const QgsRasterBandStats bandStatistics( int ); - - /** \brief Get RasterBandStats for a band given its name (read only) */ - const QgsRasterBandStats bandStatistics( const QString & ); - - /** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the - * POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers - * ACTUALLY exists you need to look at the existsFlag member in each struct stored in the - * list. - */ - RasterPyramidList buildPyramidList(); - - /** \brief Accessor for color shader algorithm */ - QString colorShadingAlgorithmAsString() const; - - /** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */ - void computeMinimumMaximumEstimates( int theBand, double* theMinMax ); - - /** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */ - void computeMinimumMaximumEstimates( QString theBand, double* theMinMax ); - - /** \brief Get a pointer to the contrast enhancement for the selected band */ - QgsContrastEnhancement* contrastEnhancement( unsigned int theBand ); - - /**Copies the symbology settings from another layer. Returns true in case of success*/ - bool copySymbologySettings( const QgsMapLayer& theOther ); - - /** \brief Get a pointer to the color table */ -//QList* colorTable( int theBandNoInt ); - - /** Returns the data provider */ - QgsRasterDataProvider* dataProvider(); - - /** Returns the data provider in a const-correct manner */ - //const QgsRasterDataProvider* dataProvider() const; - - /** \brief This is called when the view on the raster layer needs to be redrawn */ - bool draw( QgsRenderContext& rendererContext ); - - /** \brief This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap */ - void draw( QPainter * theQPainter, - QgsRasterViewPort * myRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel = 0 ); - - /** \brief Returns a string representation of drawing style - * - * Implementaed mainly for serialisation / deserialisation of settings to xml. - * NOTE: May be deprecated in the future!. DrawingStyle drawingStyle() instead. - * */ - QString drawingStyleAsString() const; - - /** \brief Checks if symbology is the same as another layers */ - bool hasCompatibleSymbology( const QgsMapLayer& theOther ) const; - - /** \brief Check whether a given band number has stats associated with it */ - bool hasStatistics( int theBandNoInt ); - - /** \brief Identify raster value(s) found on the point position */ - bool identify( const QgsPoint & point, QMap& results /Out/ ); - - /** \brief Identify arbitrary details from the WMS server found on the point position */ - QString identifyAsText( const QgsPoint & point ); - - /** \brief Currently returns always false */ - bool isEditable() const; - - /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */ - QString lastError(); - - /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */ - QString lastErrorTitle(); - - /** \brief Get a legend image for this layer */ - QPixmap legendAsPixmap(); - - /** \brief Overloaded version of above function that can print layer name onto legend */ -//QPixmap legendAsPixmap( bool ); - - /** \brief Use this method when you want an annotated legend suitable for print output etc */ -//QPixmap legendAsPixmap( int theLabelCount ); - - /** \brief Accessor for maximum value user for contrast enhancement */ - double maximumValue( unsigned int theBand ); - - /** \brief Accessor for maximum value user for contrast enhancement */ - double maximumValue( QString theBand ); - - /** \brief Obtain GDAL Metadata for this layer */ - QString metadata(); - - /** \brief Accessor for minimum value user for contrast enhancement */ - double minimumValue( unsigned int theBand ); - - /** \brief Accessor for minimum value user for contrast enhancement */ - double minimumValue( QString theBand ); - - /** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */ - QPixmap paletteAsPixmap( int theBand = 1 ); - - /** \brief [ data provider interface ] Which provider is being used for this Raster Layer? */ - QString providerKey(); - - /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */ - double rasterUnitsPerPixel(); - - /** \brief Read color table from GDAL raster band */ -//bool readColorTable( int theBandNumber, QList* theList ); - - /** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */ - void resetNoDataValue(); - - /** \brief Mutator for blue band name mapping */ - void setBlueBandName( const QString & theBandName ); - - /** \brief Mutator for color shader algorithm */ - void setColorShadingAlgorithm( QgsRasterLayer::ColorShadingAlgorithm theShaderAlgorithm ); - - /** \brief Mutator for color shader algorithm */ - void setColorShadingAlgorithm( QString theShaderAlgorithm ); - - /** \brief Mutator for contrast enhancement algorithm */ - void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm, - bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for contrast enhancement algorithm */ - void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for contrast enhancement function */ - void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction ); - - /** \brief Overloaded version of the above function for convenience when restoring from xml */ - void setDrawingStyle( const QString & theDrawingStyleQString ); - - /** \brief Mutator for gray band name mapping */ - void setGrayBandName( const QString & theBandName ); - - /** \brief Mutator for green band name mapping */ - void setGreenBandName( const QString & theBandName ); - - /** \brief Mutator for setting the maximum value for contrast enhancement */ - void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for setting the maximum value for contrast enhancement */ - void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for setting the minimum value for contrast enhancement */ - void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for setting the minimum value for contrast enhancement */ - void setMinimumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */ - void setNoDataValue( double theNoData ); - - /** \brief Set the raster shader function to a user defined function */ - void setRasterShaderFunction( QgsRasterShaderFunction* theFunction ); - - /** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */ - void setRedBandName( const QString & theBandName ); - - /** \brief Mutator for transparent band name mapping */ - void setTransparentBandName( const QString & theBandName ); - - /** \brief [ data provider interface ] A wrapper function to emit a progress update signal */ - void showProgress( int theValue ); - - /** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */ - QStringList subLayers() const; - - /** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */ - void thumbnailAsPixmap( QPixmap * theQPixmap ); - - /** \brief Emit a signal asking for a repaint. (inherited from maplayer) */ - void triggerRepaint(); - - - - - - // - // Virtural methods - // - /** - * Reorders the *previously selected* sublayers of this layer from bottom to top - * - * (Useful for providers that manage their own layers, such as WMS) - * - */ - virtual void setLayerOrder( const QStringList & layers ); - - /** - * Set the visibility of the given sublayer name - */ - virtual void setSubLayerVisibility( const QString & name, bool vis ); - - - - - - public slots: - /** \brief Create GDAL pyramid overviews */ - QString buildPyramids( const RasterPyramidList &, - const QString & theResamplingMethod = "NEAREST", - bool theTryInternalFlag = false ); - - /** \brief Populate the histogram vector for a given band */ - void populateHistogram( int theBandNoInt, - int theBinCountInt = 256, - bool theIgnoreOutOfRangeFlag = true, - bool theThoroughBandScanFlag = false ); - - void showStatusMessage( const QString & theMessage ); - - /** \brief Propagate progress updates from GDAL up to the parent app */ - void updateProgress( int, int ); - - - - - - signals: - /** \brief Signal for notifying listeners of long running processes */ - void progressUpdate( int theValue ); - - - - - protected: - - /** \brief Read the symbology for the current layer from the Dom node supplied */ - bool readSymbology( const QDomNode& node, QString& errorMessage ); - - /** \brief Reads layer specific state from project file Dom node */ - bool readXml( QDomNode & layer_node ); - - /** \brief Write the symbology for the layer into the docment provided */ - bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const; - - /** \brief Write layer specific state to project file Dom node */ - bool writeXml( QDomNode & layer_node, QDomDocument & doc ); - -}; - +/*! \class QgsRasterLayer + * \brief This class provides qgis with the ability to render raster datasets + * onto the mapcanvas.. + */ + +class QgsRasterLayer : QgsMapLayer +{ +%TypeHeaderCode +#include +#include +#include +#include +#include +%End + +public: + /** \brief This is the constructor for the RasterLayer class. + * + * The main tasks carried out by the constructor are: + * + * -Load the rasters default style (.qml) file if it exists + * + * -Populate the RasterStatsVector with initial values for each band. + * + * -Calculate the layer extents + * + * -Determine whether the layer is gray, paletted or multiband. + * + * -Assign sensible defaults for the red, green, blue and gray bands. + * + * - + * */ + QgsRasterLayer( const QString & path = QString::null, + const QString & baseName = QString::null, + bool loadDefaultStyleFlag = true ); + + /** \brief [ data provider interface ] Constructor in provider mode */ + QgsRasterLayer( int dummy, + const QString & baseName = QString(), + const QString & path = QString(), + const QString & providerLib = QString(), + const QStringList & layers = QStringList(), + const QStringList & styles = QStringList(), + const QString & format = QString(), + const QString & crs = QString()); + + /** \brief [ data provider interface ] Constructor in provider mode to pass the parameters as a map */ + QgsRasterLayer( QString const & rasterLayerPath, + QString const & baseName, + QMap theWmsProperties); + + + + /** \brief The destructor */ + ~QgsRasterLayer(); + + + // + // Enums, structs and typedefs + // + /** \brief This enumerator describes the types of shading that can be used */ + enum ColorShadingAlgorithm + { + UndefinedShader, + PseudoColorShader, + FreakOutShader, + ColorRampShader, + UserDefinedShader + }; + + /** \brief This enumerator describes the different kinds of drawing we can do */ + enum DrawingStyle + { + UndefinedDrawingStyle, + SingleBandGray, // a single band image drawn as a range of gray colors + SingleBandPseudoColor, // a single band image drawn using a pseudocolor algorithm + PalettedColor, //a "Palette" image drawn using color table + PalettedSingleBandGray, // a "Palette" layer drawn in gray scale + PalettedSingleBandPseudoColor, // a "Palette" layerdrawn using a pseudocolor algorithm + PalettedMultiBandColor, // currently not supported + MultiBandSingleGandGray, // a layer containing 2 or more bands, but a single band drawn as a range of gray colors + MultiBandSingleBandPseudoColor, //a layer containing 2 or more bands, but a single band drawn using a pseudocolor algorithm + MultiBandColor //a layer containing 2 or more bands, mapped to RGB color space. + //In the case of a multiband with only two bands, one band will be mapped to more than one color. + }; + + /** \brief This enumerator describes the type of raster layer */ + enum LayerType + { + GrayOrUndefined, + Palette, + Multiband + } ; + + /** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */ + typedef QList ContrastEnhancementList; + + /** \brief A list containing one RasterPyramid struct per raster band in this raster layer. + * POTENTIAL pyramid layer. This works by dividing the height + * and width of the raster by an incrementing number. As soon as the result + * of the division is <=256 we stop allowing RasterPyramid structs + * to be added to the list. Each time a RasterPyramid is created + * we will check to see if a pyramid matching these dimensions already exists + * in the raster layer, and if so mark the exists flag as true */ + typedef QList RasterPyramidList; + + /** \brief A list containing one RasterBandStats struct per raster band in this raster layer. + * Note that while every RasterBandStats element will have the name and number of its associated + * band populated, any additional stats are calculated on a need to know basis.*/ + typedef QList RasterStatsList; + + + + + + // + // Static methods: + // + static void buildSupportedRasterFileFilter( QString & fileFilters ); + + /** This helper checks to see whether the file name appears to be a valid + * raster file name. If the file name looks like it could be valid, + * but some sort of error occurs in processing the file, the error is + * returned in retError. + */ + static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError ); + + static bool isValidRasterFileName( const QString & theFileNameQString ); + + /** Return time stamp for given file name */ + static QDateTime lastModified( const QString & name ); + + /** \brief ensures that GDAL drivers are registered, but only once */ + static void registerGdalDrivers(); + + + + + // + // Non Static inline methods + // + + /** \brief Accessor for blue band name mapping */ + QString blueBandName() const; + + /** \brief Accessor for color shader algorithm */ + QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const; + + /** \brief Accessor for contrast enhancement algorithm */ + QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm(); + + /** \brief Returns contrast enhancement algorithm as a string */ + QString contrastEnhancementAlgorithmAsString() const; + + /** \brief Accessor for drawing style */ + DrawingStyle drawingStyle(); + + /** \brief Accessor for gray band name mapping */ + QString grayBandName() const; + + /** \brief Accessor for green band name mapping */ + QString greenBandName() const; + + /** \brief Accessor for mHasPyramids (READ ONLY) */ + bool hasPyramids(); + + /** \brief Accessor for mUserDefinedGrayMinimumMaximum */ + bool hasUserDefinedGrayMinimumMaximum() const; + + /** \brief Accessor for mUserDefinedRGBMinimumMaximum */ + bool hasUserDefinedRGBMinimumMaximum() const; + + /** \brief Accessor that returns the height of the (unclipped) raster */ + int height(); + + /** \brief Accessor to find out whether the histogram should be inverted */ + bool invertHistogram() const; + + /** \brief Is the NoDataValue Valid */ + bool isNoDataValueValid() const; + + /** \brief Accessor for mGrayMinimumMaximumEstimated */ + bool isGrayMinimumMaximumEstimated() const; + + /** \brief Accessor for mRGBMinimumMaximumEstimated */ + bool isRGBMinimumMaximumEstimated() const; + + /** \brief Accessor that returns the NO_DATA entry for this raster */ + double noDataValue( bool* isValid = 0 ); + + /** \brief Returns a pointer to the transparency object */ + QgsRasterTransparency* rasterTransparency(); + + /** \brief Accessor for raster shader */ + QgsRasterShader* rasterShader(); + + /** \brief Accessor for raster layer type (which is a read only property) */ + LayerType rasterType(); + + /** \brief Accessor for red band name (allows alternate mappings e.g. map blue as red color) */ + QString redBandName(); + + /** [ data provider interface ] Set the data provider */ + void setDataProvider( const QString & provider, + const QStringList & layers, + const QStringList & styles, + const QString & format, + const QString & crs, + const QString &sldurl=QString(), + const QString &sldbody=QString()); + + /** \brief Mutator for drawing style */ + void setDrawingStyle( const DrawingStyle & theDrawingStyle ); + + /** \brief Mutator for mGrayMinimumMaximumEstimated */ + void setGrayMinimumMaximumEstimated( bool theBool ); + + /** \brief Mutator to alter the state of the invert histogram flag */ + void setInvertHistogram( bool theFlag ); + + /** \brief Mutator for mRGBMinimumMaximumEstimated */ + void setRGBMinimumMaximumEstimated( bool theBool ); + + /** \brief Mutator to alter the number of standard deviations that should be plotted */ + void setStandardDeviations( double theStdDevsToPlot ); + + /** \brief Mutator for mUserDefinedGrayMinimumMaximum */ + void setUserDefinedGrayMinimumMaximum( bool theBool ); + + /** \brief Mutator for mUserDefinedRGBMinimumMaximum */ + void setUserDefinedRGBMinimumMaximum( bool theBool ); + + /** \brief Accessor to find out how many standard deviations are being plotted */ + double standardDeviations() const; + + /** \brief Accessor for transparent band name mapping */ + QString transparentBandName() const; + + /** \brief [ data provider interface ] Does this layer use a provider for setting/retrieving data? */ + bool usesProvider(); + + /** \brief Accessor that returns the width of the (unclipped) raster */ + int width(); + + + + + + // + // Non Static methods + // + /** \brief Get the number of bands in this layer */ + unsigned int bandCount(); + + /** \brief Get the name of a band given its number */ + const QString bandName( int theBandNoInt ); + + /** \brief Get the number of a band given its name. The name is the rewritten name set + * up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal! + * If no matching band is found zero will be returned! */ + int bandNumber( const QString & theBandName ); + + /** \brief Get RasterBandStats for a band given its number (read only) */ + const QgsRasterBandStats bandStatistics( int ); + + /** \brief Get RasterBandStats for a band given its name (read only) */ + const QgsRasterBandStats bandStatistics( const QString & ); + + /** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the + * POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers + * ACTUALLY exists you need to look at the existsFlag member in each struct stored in the + * list. + */ + RasterPyramidList buildPyramidList(); + + /** \brief Accessor for color shader algorithm */ + QString colorShadingAlgorithmAsString() const; + + /** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */ + void computeMinimumMaximumEstimates( int theBand, double* theMinMax ); + + /** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */ + void computeMinimumMaximumEstimates( QString theBand, double* theMinMax ); + + /** \brief Get a pointer to the contrast enhancement for the selected band */ + QgsContrastEnhancement* contrastEnhancement( unsigned int theBand ); + + /**Copies the symbology settings from another layer. Returns true in case of success*/ + bool copySymbologySettings( const QgsMapLayer& theOther ); + + /** \brief Get a pointer to the color table */ +//QList* colorTable( int theBandNoInt ); + + /** Returns the data provider */ + QgsRasterDataProvider* dataProvider(); + + /** Returns the data provider in a const-correct manner */ + //const QgsRasterDataProvider* dataProvider() const; + + /** \brief This is called when the view on the raster layer needs to be redrawn */ + bool draw( QgsRenderContext& rendererContext ); + + /** \brief This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap */ + void draw( QPainter * theQPainter, + QgsRasterViewPort * myRasterViewPort, + const QgsMapToPixel* theQgsMapToPixel = 0 ); + + /** \brief Returns a string representation of drawing style + * + * Implementaed mainly for serialisation / deserialisation of settings to xml. + * NOTE: May be deprecated in the future!. DrawingStyle drawingStyle() instead. + * */ + QString drawingStyleAsString() const; + + /** \brief Checks if symbology is the same as another layers */ + bool hasCompatibleSymbology( const QgsMapLayer& theOther ) const; + + /** \brief Check whether a given band number has stats associated with it */ + bool hasStatistics( int theBandNoInt ); + + /** \brief Identify raster value(s) found on the point position */ + bool identify( const QgsPoint & point, QMap& results /Out/ ); + + /** \brief Identify arbitrary details from the WMS server found on the point position */ + QString identifyAsText( const QgsPoint & point ); + + /** \brief Currently returns always false */ + bool isEditable() const; + + /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */ + QString lastError(); + + /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */ + QString lastErrorTitle(); + + /** \brief Get a legend image for this layer */ + QPixmap legendAsPixmap(); + + /** \brief Overloaded version of above function that can print layer name onto legend */ +//QPixmap legendAsPixmap( bool ); + + /** \brief Use this method when you want an annotated legend suitable for print output etc */ +//QPixmap legendAsPixmap( int theLabelCount ); + + /** \brief Accessor for maximum value user for contrast enhancement */ + double maximumValue( unsigned int theBand ); + + /** \brief Accessor for maximum value user for contrast enhancement */ + double maximumValue( QString theBand ); + + /** \brief Obtain GDAL Metadata for this layer */ + QString metadata(); + + /** \brief Accessor for minimum value user for contrast enhancement */ + double minimumValue( unsigned int theBand ); + + /** \brief Accessor for minimum value user for contrast enhancement */ + double minimumValue( QString theBand ); + + /** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */ + QPixmap paletteAsPixmap( int theBand = 1 ); + + /** \brief [ data provider interface ] Which provider is being used for this Raster Layer? */ + QString providerKey(); + + /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */ + double rasterUnitsPerPixel(); + + /** \brief Read color table from GDAL raster band */ +//bool readColorTable( int theBandNumber, QList* theList ); + + /** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */ + void resetNoDataValue(); + + /** \brief Mutator for blue band name mapping */ + void setBlueBandName( const QString & theBandName ); + + /** \brief Mutator for color shader algorithm */ + void setColorShadingAlgorithm( QgsRasterLayer::ColorShadingAlgorithm theShaderAlgorithm ); + + /** \brief Mutator for color shader algorithm */ + void setColorShadingAlgorithm( QString theShaderAlgorithm ); + + /** \brief Mutator for contrast enhancement algorithm */ + void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm, + bool theGenerateLookupTableFlag = true ); + + /** \brief Mutator for contrast enhancement algorithm */ + void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true ); + + /** \brief Mutator for contrast enhancement function */ + void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction ); + + /** \brief Overloaded version of the above function for convenience when restoring from xml */ + void setDrawingStyle( const QString & theDrawingStyleQString ); + + /** \brief Mutator for gray band name mapping */ + void setGrayBandName( const QString & theBandName ); + + /** \brief Mutator for green band name mapping */ + void setGreenBandName( const QString & theBandName ); + + /** \brief Mutator for setting the maximum value for contrast enhancement */ + void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true ); + + /** \brief Mutator for setting the maximum value for contrast enhancement */ + void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true ); + + /** \brief Mutator for setting the minimum value for contrast enhancement */ + void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true ); + + /** \brief Mutator for setting the minimum value for contrast enhancement */ + void setMinimumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true ); + + /** \brief Mutator that allows the NO_DATA entry for this raster to be overridden */ + void setNoDataValue( double theNoData ); + + /** \brief Set the raster shader function to a user defined function */ + void setRasterShaderFunction( QgsRasterShaderFunction* theFunction ); + + /** \brief Mutator for red band name (allows alternate mappings e.g. map blue as red color) */ + void setRedBandName( const QString & theBandName ); + + /** \brief Mutator for transparent band name mapping */ + void setTransparentBandName( const QString & theBandName ); + + /** \brief [ data provider interface ] A wrapper function to emit a progress update signal */ + void showProgress( int theValue ); + + /** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */ + QStringList subLayers() const; + + /** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */ + void thumbnailAsPixmap( QPixmap * theQPixmap ); + + /** \brief Emit a signal asking for a repaint. (inherited from maplayer) */ + void triggerRepaint(); + + + + + + // + // Virtural methods + // + /** + * Reorders the *previously selected* sublayers of this layer from bottom to top + * + * (Useful for providers that manage their own layers, such as WMS) + * + */ + virtual void setLayerOrder( const QStringList & layers ); + + /** + * Set the visibility of the given sublayer name + */ + virtual void setSubLayerVisibility( const QString & name, bool vis ); + + + + + + public slots: + /** \brief Create GDAL pyramid overviews */ + QString buildPyramids( const RasterPyramidList &, + const QString & theResamplingMethod = "NEAREST", + bool theTryInternalFlag = false ); + + /** \brief Populate the histogram vector for a given band */ + void populateHistogram( int theBandNoInt, + int theBinCountInt = 256, + bool theIgnoreOutOfRangeFlag = true, + bool theThoroughBandScanFlag = false ); + + void showStatusMessage( const QString & theMessage ); + + /** \brief Propagate progress updates from GDAL up to the parent app */ + void updateProgress( int, int ); + + + + + + signals: + /** \brief Signal for notifying listeners of long running processes */ + void progressUpdate( int theValue ); + + + + + protected: + + /** \brief Read the symbology for the current layer from the Dom node supplied */ + bool readSymbology( const QDomNode& node, QString& errorMessage ); + + /** \brief Reads layer specific state from project file Dom node */ + bool readXml( QDomNode & layer_node ); + + /** \brief Write the symbology for the layer into the docment provided */ + bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const; + + /** \brief Write layer specific state to project file Dom node */ + bool writeXml( QDomNode & layer_node, QDomDocument & doc ); + +}; + Index: src/app/qgisapp.cpp =================================================================== --- src/app/qgisapp.cpp (revision 11421) +++ src/app/qgisapp.cpp (working copy) @@ -2751,14 +2751,34 @@ if ( wmss->exec() ) { + QMap parameters; + parameters.clear(); + parameters.insert("connection",wmss->connectionInfo()); + parameters.insert("basename",(wmss->selectedLayers().join( "/" ))); + parameters.insert("provider","wms"); + parameters.insert("layers",wmss->selectedLayers().join("/")); + parameters.insert("styles",wmss->selectedStylesForSelectedLayers().join("/")); + parameters.insert("format",wmss->selectedImageEncoding()); + parameters.insert("crs",wmss->selectedCrs()); + parameters.insert("sld",wmss->sldURL()); + parameters.insert("sld_body",wmss->sldBody()); + addRasterLayer(parameters); + + /*QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterLayerPath, + QString const & baseName, + QString const & providerKey, + QStringList const & layers, + QStringList const & styles, + QString const & format, + QString const & crs ) addRasterLayer( wmss->connectionInfo(), - /*wmss->connName()*/wmss->selectedLayers().join( "/" ), + wmss->selectedLayers().join( "/" ), "wms", wmss->selectedLayers(), wmss->selectedStylesForSelectedLayers(), wmss->selectedImageEncoding(), - wmss->selectedCrs() ); + wmss->selectedCrs() );*/ } } @@ -5907,8 +5927,53 @@ } // QgisApp::addRasterLayer +/*fred*/ +QgsRasterLayer* QgisApp::addRasterLayer( QMap theWmsLayerProperties) +{ + if ( mMapCanvas && mMapCanvas->isDrawing() ) + { + return 0; + } + mMapCanvas->freeze(); + + // create the layer + QgsRasterLayer *layer; + + /*QgsDebugMsg( "Creating new raster layer using " + rasterLayerPath + + " with baseName of " + baseName + + " and layer list of " + layers.join( ", " ) + + " and style list of " + styles.join( ", " ) + + " and format of " + format + + " and providerKey of " + providerKey + + " and CRS of " + crs );*/ + QString rasterLayerPath=theWmsLayerProperties.value("connection"); + QString baseName=theWmsLayerProperties.value("basename"); + layer = new QgsRasterLayer(rasterLayerPath,baseName,theWmsLayerProperties); + //layer = new QgsRasterLayer( 0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs ); + QgsDebugMsg( "Constructed new layer." ); + if ( layer && layer->isValid() ) + { + addRasterLayer( layer ); + + statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) ); + + } + else + { + QMessageBox::critical( this, tr( "Layer is not valid" ), + tr( "The layer is not a valid layer and can not be added to the map" ) ); + } + + // update UI + qApp->processEvents(); + // draw the map + mMapCanvas->freeze( false ); + mMapCanvas->refresh(); + return layer; +} +/*fred*/ /** Add a raster layer directly without prompting user for location The caller must provide information compatible with the provider plugin using the rasterLayerPath and baseName. The provider can use these Index: src/app/qgisapp.h =================================================================== --- src/app/qgisapp.h (revision 11421) +++ src/app/qgisapp.h (working copy) @@ -99,6 +99,11 @@ */ bool addRasterLayers( QStringList const & theLayerQStringList, bool guiWarning = true ); + /** Open a raster layer using the Raster Data Provider. + * This method use a map to pass all the neccesary wms properties + */ + QgsRasterLayer* addRasterLayer( QMap theWmsLayerProperties); + /** 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. Index: src/app/qgsrasterlayerproperties.cpp =================================================================== --- src/app/qgsrasterlayerproperties.cpp (revision 11421) +++ src/app/qgsrasterlayerproperties.cpp (working copy) @@ -57,6 +57,8 @@ mRasterLayer( dynamic_cast( lyr ) ) { + + ignoreSpinBoxEvent = false; //Short circuit signal loop between min max field and stdDev spin box mGrayMinimumMaximumEstimated = true; mRGBMinimumMaximumEstimated = true; @@ -75,6 +77,9 @@ } setupUi( this ); + // disable SLD tab + tabBar->setTabEnabled( tabBar->indexOf( tabSLD ), FALSE ); + connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) ); connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); @@ -163,11 +168,12 @@ int myBandCountInt = mRasterLayer->bandCount(); QgsDebugMsg( QString( "Looping though %1 image layers to get their names " ).arg( myBandCountInt ) ); - + for ( int myIteratorInt = 1; myIteratorInt <= myBandCountInt; ++myIteratorInt ) { + QString num; //find out the name of this band QString myRasterBandNameQString = mRasterLayer->bandName( myIteratorInt ) ; @@ -269,6 +275,7 @@ // Only do pyramids if dealing directly with GDAL. if ( mRasterLayerIsGdal ) { + QgsRasterLayer::RasterPyramidList myPyramidList = mRasterLayer->buildPyramidList(); QgsRasterLayer::RasterPyramidList::iterator myRasterPyramidIterator; @@ -297,6 +304,8 @@ // disable Histogram tab completely tabBar->setTabEnabled( tabBar->indexOf( tabPageHistogram ), FALSE ); + // enable SLD tab + tabBar->setTabEnabled( tabBar->indexOf( tabSLD ), TRUE ); } leSpatialRefSys->setText( mRasterLayer->srs().toProj4() ); @@ -315,6 +324,7 @@ .arg( pyramidSentence4 ).arg( pyramidSentence5 ) ); // update based on lyr's current state + sync(); } // QgsRasterLayerProperties ctor @@ -837,6 +847,17 @@ txtbMetadata->document()->setDefaultStyleSheet( myStyle ); txtbMetadata->setHtml( mRasterLayer->metadata() ); + + QgsDebugMsg( "populate sld tab" ); + /* + * SLD Tab + */ + if ( mRasterLayerIsWms ){ + sldURLEdit->setText(mRasterLayer->dataProvider()->sldURL()); + sldBodyText->clear(); + sldBodyText->appendPlainText(mRasterLayer->dataProvider()->sldBody()); + } + } // QgsRasterLayerProperties::sync() void QgsRasterLayerProperties::syncColormapTab() @@ -1413,6 +1434,13 @@ QgsDebugMsg( "color ramp was NOT set because RasterShaderFunction was NULL" ); } } +/*fred*/ + QgsDebugMsg( "processing sld tab" ); + if ( mRasterLayerIsWms ){ + mRasterLayer->dataProvider()->setSLDURL(sldURLEdit->text()); + mRasterLayer->dataProvider()->setSLDBody(sldBodyText->toPlainText()); + } + /*fred*/ QgsDebugMsg( "processing general tab" ); /* Index: src/app/qgsserversourceselect.cpp =================================================================== --- src/app/qgsserversourceselect.cpp (revision 11421) +++ src/app/qgsserversourceselect.cpp (working copy) @@ -656,6 +656,16 @@ } } +QString QgsServerSourceSelect::sldURL() +{ + return sldUrlText->text(); +} + +QString QgsServerSourceSelect::sldBody() +{ + return sldBodyEdit->toPlainText(); +} + void QgsServerSourceSelect::serverChanged() { // Remember which server was selected. Index: src/app/qgsserversourceselect.h =================================================================== --- src/app/qgsserversourceselect.h (revision 11421) +++ src/app/qgsserversourceselect.h (working copy) @@ -81,7 +81,12 @@ //! String containing the selected WMS-format CRS QString selectedCrs(); + + //! String containing a url pointing to external sld document + QString sldURL(); + //! String containing an SLD document + QString sldBody(); //! Stores which server is now selected. void serverChanged(); Index: src/core/qgsrasterdataprovider.h =================================================================== --- src/core/qgsrasterdataprovider.h (revision 11421) +++ src/core/qgsrasterdataprovider.h (working copy) @@ -82,7 +82,27 @@ */ virtual void setImageCrs( QString const & crs ) = 0; + /** + * Set the url of sld document + * Added in qgis version 1.2 + */ + virtual void setSLDURL( QString const & sldURL ) = 0; + /** + * Retrieves the url of sld document + * Added in qgis version 1.2 + */ + virtual QString sldURL()=0; + /** + * Set the sld document body + * Added in qgis version 1.2 + */ + virtual void setSLDBody( QString const & sldBody ) = 0; + /** + * Retrieves the sld document body + * Added in qgis version 1.2 + */ + virtual QString sldBody() = 0; // TODO: Document this better. /** \brief Renders the layer as an image */ Index: src/core/raster/qgsrasterlayer.cpp =================================================================== --- src/core/raster/qgsrasterlayer.cpp (revision 11421) +++ src/core/raster/qgsrasterlayer.cpp (working copy) @@ -61,6 +61,7 @@ #include #include #include +#include #include "qgslogger.h" // workaround for MSVC compiler which already has defined macro max // that interferes with calling std::numeric_limits::max @@ -194,7 +195,7 @@ // if we're given a provider type, try to create and bind one to this layer if ( ! providerKey.isEmpty() ) { - setDataProvider( providerKey, layers, styles, format, crs ); + setDataProvider( providerKey, layers, styles, format, crs); } // Default for the popup menu @@ -221,6 +222,58 @@ emit statusChanged( tr( "QgsRasterLayer created" ) ); } // QgsRasterLayer ctor +//fred +QgsRasterLayer::QgsRasterLayer( QString const & rasterLayerPath, + QString const & baseName, + QMap theWmsProperties) + : QgsMapLayer( RasterLayer, baseName, rasterLayerPath ), + mStandardDeviations( 0 ), + mDataProvider( 0 ), + mEditable( false ), + mWidth( std::numeric_limits::max() ), + mHeight( std::numeric_limits::max() ), + mInvertColor( false ), + mModified( false ), + mProviderKey( "wms" ) +{ + /*QgsDebugMsg( "(8 arguments) starting. with layer list of " + + layers.join( ", " ) + " and style list of " + styles.join( ", " ) + " and format of " + + format + " and CRS of " + crs );*/ + mBandCount = 0; + mRasterShader = new QgsRasterShader(); + + // Initialise the affine transform matrix + mGeoTransform[0] = 0; + mGeoTransform[1] = 1; + mGeoTransform[2] = 0; + mGeoTransform[3] = 0; + mGeoTransform[4] = 0; + mGeoTransform[5] = -1; + + QStringList layers=theWmsProperties.value("layers").split("/"); + QStringList styles=theWmsProperties.value("styles").split("/"); + QString format=theWmsProperties.value("format"); + QString crs=theWmsProperties.value("crs"); + QString sld=theWmsProperties.value("sld"); + QString sldbody=theWmsProperties.value("sld_body"); + setDataProvider( "wms", + layers, + styles, + format, + crs, + sld, + sldbody); + + connect( + mDataProvider, SIGNAL( statusChanged( QString ) ), + this, SLOT( showStatusMessage( QString ) ) + ); + + + emit statusChanged( tr( "QgsRasterLayer created" ) ); +} // QgsRasterLayer ctor +//fred + QgsRasterLayer::~QgsRasterLayer() { @@ -3103,7 +3156,9 @@ QStringList const & layers, QStringList const & styles, QString const & format, - QString const & crs ) + QString const & crs, + QString const &sldurl, + QString const &sldbody) { // XXX should I check for and possibly delete any pre-existing providers? // XXX How often will that scenario occur? @@ -3170,6 +3225,10 @@ mDataProvider->addLayers( layers, styles ); mDataProvider->setImageEncoding( format ); mDataProvider->setImageCrs( crs ); + + //fred + mDataProvider->setSLDURL(sldurl); + mDataProvider->setSLDBody(sldbody); // get the extent QgsRectangle mbr = mDataProvider->extent(); @@ -3211,6 +3270,7 @@ } // QgsRasterLayer::setDataProvider + void QgsRasterLayer::setColorShadingAlgorithm( ColorShadingAlgorithm theShadingAlgorithm ) { QgsDebugMsg( "called with [" + QString::number( theShadingAlgorithm ) + "]" ); @@ -3827,8 +3887,18 @@ // Collect CRS QString crs = QString( "EPSG:%1" ).arg( srs().epsg() ); + //fix here to save and load slds in project + + // Collect SLDURL + QString mySLDUrl = rpNode.namedItem( "wmsSLDURL" ).toElement().text(); - setDataProvider( mProviderKey, layers, styles, format, crs ); + + // Collect + QString mySLDBody = rpNode.namedItem( "wmsSLDBody" ).toElement().text(); + QUrl myUrl; + myUrl.addEncodedQueryItem("sld_body",mySLDBody.toLocal8Bit()); + QString sldBody(myUrl.queryItemValue("sld_body")); + setDataProvider( mProviderKey, layers, styles, format, crs, mySLDUrl, sldBody ); } else { @@ -3907,6 +3977,24 @@ formatElement.appendChild( formatText ); rasterPropertiesElement.appendChild( formatElement ); + //sld-url + QDomElement sldURLElement = document.createElement( "wmsSLDURL" ); + QDomText sldURLText = + document.createTextNode( mDataProvider->sldURL() ); + sldURLElement.appendChild( sldURLText ); + rasterPropertiesElement.appendChild( sldURLElement ); + + //sld-body + QString mySLDBody=mDataProvider->sldBody().trimmed(); + QUrl myUrl; + myUrl.addQueryItem("sld_body",mySLDBody); + QString mySLD_Body(myUrl.encodedQueryItemValue("sld_body")); + QDomElement sldBodyElement = document.createElement( "wmsSLDBody" ); + QDomText sldBodyText = + document.createTextNode( mySLD_Body ); + sldBodyElement.appendChild( sldBodyText ); + rasterPropertiesElement.appendChild( sldBodyElement ); + } // Index: src/core/raster/qgsrasterlayer.h =================================================================== --- src/core/raster/qgsrasterlayer.h (revision 11421) +++ src/core/raster/qgsrasterlayer.h (working copy) @@ -208,9 +208,13 @@ const QStringList & layers = QStringList(), const QStringList & styles = QStringList(), const QString & format = QString(), - const QString & crs = QString() ); + const QString & crs = QString()); + QgsRasterLayer( QString const & rasterLayerPath, + QString const & baseName, + QMap theWmsProperties); + /** \brief The destructor */ ~QgsRasterLayer(); @@ -365,7 +369,10 @@ const QStringList & layers, const QStringList & styles, const QString & format, - const QString & crs ); + const QString & crs, + const QString &sldurl=QString(), + const QString &sldbody=QString()); + /** \brief Mutator for drawing style */ void setDrawingStyle( const DrawingStyle & theDrawingStyle ) { mDrawingStyle = theDrawingStyle; } Index: src/providers/wms/qgswmsprovider.cpp =================================================================== --- src/providers/wms/qgswmsprovider.cpp (revision 11421) +++ src/providers/wms/qgswmsprovider.cpp (working copy) @@ -70,7 +70,8 @@ mUserName = ""; mPassword = ""; setAuthentication( httpuri ); - + mSLDURL=""; + mSLDBody=""; QgsDebugMsg( "QgsWmsProvider: constructing with uri '" + httpuri + "'." ); // assume this is a valid layer until we determine otherwise @@ -288,7 +289,35 @@ return imageMimeType; } +void QgsWmsProvider::setSLDURL( QString const & sldURL ) +{ + mSLDURL=sldURL; +} +QString QgsWmsProvider::sldURL() +{ + return mSLDURL; +} + +void QgsWmsProvider::setSLDBody( QString const & sldBody ) +{ + mSLDBody=sldBody.trimmed(); + //encode the url + QUrl myUrl; + myUrl.addQueryItem("sld_body",mSLDBody); + QString mySLD_Body(myUrl.encodedQueryItemValue("sld_body")); + mSLDBody=mySLD_Body; +} + +QString QgsWmsProvider::sldBody() +{ + QUrl myUrl; + myUrl.addEncodedQueryItem("sld_body",mSLDBody.toLocal8Bit()); + QString mySLD_Body(myUrl.queryItemValue("sld_body")); + return mySLD_Body; +} + + void QgsWmsProvider::setImageEncoding( QString const & mimeType ) { QgsDebugMsg( "Setting image encoding to " + mimeType + "." ); @@ -454,6 +483,19 @@ url += "&"; url += "FORMAT=" + imageMimeType; + //set SLD parameter + if((!mSLDURL.isEmpty())&&(!mSLDURL.isNull())) + { + url += "&"; + url += "SLD=" + mSLDURL; + } + + //set SLD Body + if((!mSLDBody.isEmpty())&&(!mSLDBody.isNull())) + { + url += "&"; + url += "SLD_BODY=" + mSLDBody; + } //DPI parameter is accepted by QGIS mapserver (and ignored by the other WMS servers) if(mDpi != -1) { @@ -505,6 +547,10 @@ } QByteArray imagesource; + //QUrl myUrl(url); + //QString encodedUrl(myUrl.toEncoded()); + + QgsDebugMsg( "Retrieving image with url : "+url); imagesource = retrieveUrl( url ); if ( imagesource.isEmpty() ) Index: src/providers/wms/qgswmsprovider.h =================================================================== --- src/providers/wms/qgswmsprovider.h (revision 11421) +++ src/providers/wms/qgswmsprovider.h (working copy) @@ -416,6 +416,31 @@ void setImageEncoding( QString const & mimeType ); /** + * Set the url for sld document + * added in qgis 1.2 + */ + void setSLDURL( QString const & sldURL ); + + /** + * Retrieves the sld url + * added in qgis 1.2 + */ + QString sldURL(); + + /** + * Set the sld body + * added in qgis 1.2 + */ + + void setSLDBody( QString const & sldBody ); + + /** + * Retrieves the sld body + * added in qgis 1.2 + */ + QString sldBody(); + + /** * Set the image projection (in WMS CRS format) used in the transfer from the WMS server * * \note an empty crs value will result in the previous CRS being retained. @@ -849,6 +874,12 @@ //! Password for basic http authentication QString mPassword; + //! Url pointing to remote sld document + QString mSLDURL; + + //! Inline SLD + QString mSLDBody; + }; #endif Index: src/ui/qgsrasterlayerpropertiesbase.ui =================================================================== --- src/ui/qgsrasterlayerpropertiesbase.ui (revision 11421) +++ src/ui/qgsrasterlayerpropertiesbase.ui (working copy) @@ -27,7 +27,7 @@ - 0 + 7 @@ -1472,10 +1472,10 @@ - + Specify the coordinate reference system of the layer's geometry. - + Specify the coordinate reference system of the layer's geometry. @@ -1676,8 +1676,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';"></p></body></html> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;"></p></body></html> @@ -1903,6 +1903,37 @@ + + + SLD + + + + + + + + Style Layer Descriptor URL : + + + + + + + + + + Style Layer Descriptor Body : + + + + + + + + + + Index: src/ui/qgsserversourceselectbase.ui =================================================================== --- src/ui/qgsserversourceselectbase.ui (revision 11421) +++ src/ui/qgsserversourceselectbase.ui (working copy) @@ -6,7 +6,7 @@ 0 0 600 - 481 + 630 @@ -23,7 +23,7 @@ true - + @@ -254,6 +254,65 @@ + + + + 581 + 141 + + + + Style Layer Descriptor + + + + + 60 + 20 + 511 + 20 + + + + + + + 60 + 50 + 511 + 81 + + + + + + + 10 + 20 + 46 + 14 + + + + URL : + + + + + + 10 + 50 + 46 + 14 + + + + Body : + + + + + @@ -272,7 +331,7 @@ - + Coordinate Reference System @@ -314,7 +373,7 @@ - + true @@ -330,7 +389,7 @@ - + Qt::Horizontal @@ -346,7 +405,7 @@ - + false @@ -365,7 +424,7 @@ - + C&lose @@ -378,7 +437,7 @@ - +