⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgsrasterlayer.h

📁 一个非常好的GIS开源新版本
💻 H
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************                        qgsrasterlayer.h  -  description                              -------------------	begin                : Fri Jun 28 2002	copyright            : (C) 2004 by T.Sutton, Gary E.Sherman, Steve Halasz	email                : tim@linfiniti.com***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//* $Id: qgsrasterlayer.h 8222 2008-03-14 14:09:18Z mhugent $ *//** \file qgsrasterlayer.h *  \brief This class provides qgis with the ability to render raster datasets *  onto the mapcanvas * *  The qgsrasterlayer class makes use of gdal for data io, and thus supports *  any gdal supported format. The constructor attemtps to infer what type of *  file (RASTER_LAYER_TYPE) is being opened - not in terms of the file format (tif, ascii grid etc.) *  but rather in terms of whether the image is a GRAYSCALE, PALETTED or MULTIBAND, * *  Within the three allowable raster layer types, there are 8 permutations of  *  how a layer can actually be rendered. These are defined in the DRAWING_STYLE enum *  and consist of: * *  SINGLE_BAND_GRAY -> a GRAYSCALE layer drawn as a range of gray colors (0-255) *  SINGLE_BAND_PSEUDO_COLOR -> a GRAYSCALE layer drawn using a pseudocolor algorithm *  PALETTED_SINGLE_BAND_GRAY -> a PALLETED layer drawn in gray scale (using only one of the color components) *  PALETTED_SINGLE_BAND_PSEUDO_COLOR -> a PALLETED layer having only one of its color components rendered as psuedo color *  PALETTED_MULTI_BAND_COLOR -> a PALLETED image where the bands contains 24bit color info and 8 bits is pulled out per color *  MULTI_BAND_SINGLE_BAND_GRAY -> a layer containing 2 or more bands, but using only one band to produce a grayscale image *  MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR -> a layer containing 2 or more bands, but using only one band to produce a pseudocolor image *  MULTI_BAND_COLOR -> a layer containing 2 or more bands, mapped to the three RGBcolors. In the case of a multiband with only two bands, one band will have to be mapped to more than one color * *  Each of the above mentioned drawing styles is implemented in its own draw* function. *  Some of the drawing styles listed above require statistics about the layer such  *  as the min / max / mean / stddev etc. Statics for a band can be gathered using the  *  getRasterBandStats function. Note that statistics gathering is a slow process and  *  evey effort should be made to call this function as few times as possible. For this *  reason, qgsraster has a vector class member to store stats for each band. The  *  constructor initialises this vector on startup, but only populates the band name and *  number fields. *   *  Note that where bands are of gdal 'undefined' type, their values may exceed the  *  renderable range of 0-255. Because of this a linear scaling histogram stretch is *  applied to undefined layers to normalise the data into the 0-255 range. * *  A qgsrasterlayer band can be referred to either by name or by number (base=1). It *  should be noted that band names as stored in datafiles may not be uniqe, and  *  so the rasterlayer class appends the band number in brackets behind each band name. *   *  Sample useage of the QgsRasterLayer class: * *     QString myFileNameQString = "/path/to/file"; *     QFileInfo myFileInfo(myFileNameQString); *     QString myBaseNameQString = myFileInfo.baseName(); *     QgsRasterLayer *myRasterLayer = new QgsRasterLayer(myFileNameQString, myBaseNameQString); * *  In order to automate redrawing of a raster layer, you should like it to a map canvas like this : *   *     QObject::connect( myRasterLayer, SIGNAL(repaintRequested()), mapCanvas, SLOT(refresh()) ); * *  A raster layer can also export its legend as a pixmap: * *     QPixmap myQPixmap = myRasterLayer->legendPixmap(); * * Once a layer has been created you can find out what type of layer it is (GRAY_OR_UNDEFINED, PALETTE or MULTIBAND): * *    if (rasterLayer->getRasterLayerType()==QgsRasterLayer::MULTIBAND) *    { *      //do something *    } *    else if (rasterLayer->getRasterLayerType()==QgsRasterLayer::PALETTE) *    { *      //do something *    } *    else // QgsRasterLayer::GRAY_OR_UNDEFINED *    { *      //do something. *    } * * You can combine layer type detection with the setDrawingStyle method to override the default drawing style assigned * when a layer is loaded.: * *    if (rasterLayer->getRasterLayerType()==QgsRasterLayer::MULTIBAND) *    { *       myRasterLayer->setDrawingStyle(QgsRasterLayer::MULTI_BAND_SINGLE_BAND_PSEUDO_COLOR); *    } *    else if (rasterLayer->getRasterLayerType()==QgsRasterLayer::PALETTE) *    { *      myRasterLayer->setDrawingStyle(QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR); *    } *    else // QgsRasterLayer::GRAY_OR_UNDEFINED *    { *      myRasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR); *    } *  *  Raster layers can also have an aribitary level of transparency defined, and have their *  colour palettes inverted using the setTransparency and setInvertHistogramFlag methods.  *  *  Pseudocolour images can have their output adjusted to a given number of standard *  deviations using the setStdDevsToPlot method. *  *  The final area of functionality you may be interested in is band mapping. Band mapping *  allows you to choose arbitary band -> colour mappings and is applicable only to PALETTE *  and MULTIBAND rasters, There are four mappings that can be made : red, green, blue and gray. *  Mappings are non exclusive. That is a given band can be assigned to no, some or all  *  colour mappings. The constructor sets sensible defaults for band mappings but these can be *  overridden at run time using the setRedBandName,setGreenBandName,setBlueBandName and setGrayBandName  *  methods. */  #ifndef QGSRASTERLAYER_H#define QGSRASTERLAYER_H//// Includes//  #include <QColor>#include <QDateTime>#include <QVector>#include <QList>#include "qgis.h"#include "qgspoint.h"#include "qgsmaplayer.h"#include "qgscontrastenhancement.h"#include "qgsrastertransparency.h"#include "qgsrastershader.h"#include "qgsrastershaderfunction.h"/* *  * New includes that will convert this class to a data provider interface * (B Morley) * */  #include "qgsrasterdataprovider.h"/* * END */#define CPL_SUPRESS_CPLUSPLUS#include <gdal.h>//// Forward declarations//class QgsColorTable;class QgsRect;class QgsRasterBandStats;class QgsRasterPyramid;class QgsRasterLayerProperties;struct QgsRasterViewPort;class QImage;class QPixmap;class QSlider;class QLibrary;    /*! \class QgsRasterLayer *  \brief This class provides qgis with the ability to render raster datasets *  onto the mapcanvas.. */class CORE_EXPORT QgsRasterLayer : public QgsMapLayer{    Q_OBJECTpublic:    // Static constant defining flag for XML    static const QString QSTRING_NOT_SET;    //    // Static methods:    //    static void buildSupportedRasterFileFilter(QString & fileFilters);    static bool isSupportedRasterDriver(const QString & driverName);    static void registerGdalDrivers();    /** This helper checks to see whether the filename appears to be a valid       raster file name */    static bool isValidRasterFileName(const QString & theFileNameQString);    //    // Non Static methods:    //    /** \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 The destuctor.  */    ~QgsRasterLayer();    /** \brief  A list containing one RasterBandStats struct per raster band in this raster layer.     * Note that while very 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<QgsRasterBandStats> RasterStatsList;    /** \brief  A list containing one RasterPyramid struct per raster band in this raster layer.     * POTENTIAL pyramid layer. How this works is we divide 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 stracuts     * 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<QgsRasterPyramid> RasterPyramidList;        /** \brief A list containing on ContrastEnhancement object per raster band in this raster layer. */    typedef QList<QgsContrastEnhancement> ContrastEnhancementList;    /** \brief This typedef is used when the showProgress function is passed to gdal as a function    pointer. */    //  typedef  int (QgsRasterLayer::*showTextProgress)( double theProgress,    //                                      const char *theMessageCharArray,    //                                      void *theData);    /** \brief Identify raster value(s) found on the point position      *     * \param point[in]  a coordinate in the CRS of this layer.     */    void identify(const QgsPoint & point, std::map<QString,QString>& results);    /** \brief Identify arbitrary details from the WMS server found on the point position     *     * \param point[in]  an image pixel coordinate in the last requested extent of layer.     *     * \return  A text document containing the return from the WMS server     *     * \note  The arbitraryness of the returned document is enforced by WMS standards     *        up to at least v1.3.0     */    QString identifyAsText(const QgsPoint & point);    /** \brief Query gdal to find out the WKT projection string for this layer. This implements the virtual method of the same name defined in QgsMapLayer*/    QString getProjectionWKT();    /** \brief Returns the number of raster units per each raster pixel. For rasters with world file, this is normally the first row (without the sign) in that file */    double rasterUnitsPerPixel();    /** \brief Draws a thumbnail of the rasterlayer into the supplied pixmap pointer */     void drawThumbnail(QPixmap * theQPixmap);    /** \brief Get an 8x8 pixmap of the colour palette. If the layer has no palette a white pixmap will be returned. */     QPixmap getPaletteAsPixmap();         /** \brief This is called when the view on the rasterlayer needs to be refreshed (redrawn).                    \param drawingToEditingCanvas  Are we drawing to an editable canvas?                                        currently not used, but retain to be similar to                                        the QgsVectorLayer interface      */    bool draw(QPainter * theQPainter,              QgsRect & theViewExtent,               QgsMapToPixel * theQgsMapToPixel,              QgsCoordinateTransform* ct,              bool drawingToEditingCanvas);    /** \brief This is an overloaded version of the above function that is called by both draw above and drawThumbnail */    void draw(QPainter * theQPainter, QgsRasterViewPort * myRasterViewPort,              QgsMapToPixel * theQgsMapToPixel = 0);        //    // Accessors for image height and width    //    /** \brief Accessor that returns the width of the (unclipped) raster  */    const int getRasterXDim() {return mRasterXDim;}    /** \brief Accessor that returns the height of the (unclipped) raster  */    const int getRasterYDim() {return mRasterYDim;}    //    // Accessor and mutator for no data double    //    /** \brief Is the NoDataValue Valid */    bool isNoDataValueValid() {return mValidNoDataValue;}        /** \brief Accessor that returns the NO_DATA entry for this raster. */    const double getNoDataValue(bool* isValid=0) { if(isValid) { *isValid = mValidNoDataValue;} return mNoDataValue;}    /** \brief Mutator that allows the  NO_DATA entry for this raster to be overridden. */    void setNoDataValue(double theNoData);    /** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */    void resetNoDataValue()    {      mNoDataValue = -9999;      if(mGdalDataset != NULL && GDALGetRasterCount(mGdalDataset) > 0)      {        int myRequestValid;        double myValue = GDALGetRasterNoDataValue(            GDALGetRasterBand( mGdalDataset, 1 ), &myRequestValid);        if(0 != myRequestValid)        {          setNoDataValue(myValue);        }        else        {          setNoDataValue(myValue);          mValidNoDataValue = false;        }      }    }    //    // Accessor and mutator for mInvertPixelsFlag    //    /** \brief Accessor to find out whether the histogram should be inverted.   */    bool getInvertHistogramFlag()    {        return mInvertPixelsFlag;    }    /** \brief Mutator to alter the state of the invert histogram flag.  */    void setInvertHistogramFlag(bool theFlag)    {        mInvertPixelsFlag=theFlag;    }    //    // Accessor and mutator for mStandardDeviations    //    /** \brief Accessor to find out how many standard deviations are being plotted.  */    double getStdDevsToPlot()    {        return mStandardDeviations;    }    /** \brief Mutator to alter the number of standard deviations that should be plotted.  */    void setStdDevsToPlot(double theStdDevsToPlot)    {        mStandardDeviations = theStdDevsToPlot;    }    /** \brief Get the number of bands in this layer  */    const unsigned int getBandCount();    /** \brief Get RasterBandStats for a band given its number (read only)  */    const  QgsRasterBandStats getRasterBandStats(int);    /** \brief  Check whether a given band number has stats associated with it */    const bool hasStats(int theBandNoInt);    /** \brief Overloaded method that also returns stats for a band, but uses the band colour name    *    Note this approach is not recommeneded because it is possible for two gdal raster    *    bands to have the same name!    */    const  QgsRasterBandStats getRasterBandStats(const QString &);    /** \brief Get the number of a band given its name. Note this will be 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! */    const  int getRasterBandNumber (const QString & theBandNameQString);    /** \brief Get the name of a band given its number.  */    const  QString getRasterBandName(int theBandNoInt);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -