2007-01-09 02:39:15 +00:00
/*! \class QgsRasterLayer
* \brief This class provides qgis with the ability to render raster datasets
* onto the mapcanvas..
*/
class QgsRasterLayer : QgsMapLayer
{
%TypeHeaderCode
#include <qgsrasterlayer.h>
%End
2012-09-24 02:28:15 +02:00
public:
/** \brief Default cumulative cut lower limit */
static const double CUMULATIVE_CUT_LOWER;
/** \brief Default cumulative cut upper limit */
static const double CUMULATIVE_CUT_UPPER;
/** \brief Default sample size (number of pixels) for estimated statistics/histogram calculation */
static const double SAMPLE_SIZE;
/** \brief Constructor. Provider is not set. */
QgsRasterLayer();
2007-01-09 02:39:15 +00:00
/** \brief This is the constructor for the RasterLayer class.
*
* The main tasks carried out by the constructor are:
*
2008-11-05 22:44:50 +00:00
* -Load the rasters default style (.qml) file if it exists
*
2007-01-09 02:39:15 +00:00
* -Populate the RasterStatsVector with initial values for each band.
*
* -Calculate the layer extents
*
* -Determine whether the layer is gray, paletted or multiband.
*
2008-11-05 22:44:50 +00:00
* -Assign sensible defaults for the red, green, blue and gray bands.
2007-01-09 02:39:15 +00:00
*
* -
* */
2012-09-24 02:28:15 +02:00
QgsRasterLayer( const QString & path,
2008-11-05 22:44:50 +00:00
const QString & baseName = QString::null,
bool loadDefaultStyleFlag = true );
/** \brief [ data provider interface ] Constructor in provider mode */
2012-06-14 11:40:07 +02:00
QgsRasterLayer( const QString & uri,
const QString & baseName,
const QString & providerKey,
bool loadDefaultStyleFlag = true );
2008-11-05 22:44:50 +00:00
/** \brief The destructor */
2007-01-09 02:39:15 +00:00
~QgsRasterLayer();
2008-11-05 22:44:50 +00:00
//
// Enums, structs and typedefs
//
/** \brief This enumerator describes the types of shading that can be used */
enum ColorShadingAlgorithm
{
2008-11-06 15:16:08 +00:00
UndefinedShader,
PseudoColorShader,
FreakOutShader,
ColorRampShader,
UserDefinedShader
2008-11-05 22:44:50 +00:00
};
/** \brief This enumerator describes the type of raster layer */
enum LayerType
{
GrayOrUndefined,
Palette,
2012-09-24 02:28:15 +02:00
Multiband,
ColorLayer
};
2008-11-05 22:44:50 +00:00
//
// Static methods:
//
/** 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.
2007-01-09 02:39:15 +00:00
*/
2008-11-05 22:44:50 +00:00
static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
static bool isValidRasterFileName( const QString & theFileNameQString );
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
/** Return time stamp for given file name */
static QDateTime lastModified( const QString & name );
2008-01-11 06:38:10 +00:00
2007-01-09 02:39:15 +00:00
//
2008-11-05 22:44:50 +00:00
// Non Static inline methods
2007-01-09 02:39:15 +00:00
//
2012-09-24 02:28:15 +02:00
/** [ data provider interface ] Set the data provider */
void setDataProvider( const QString & provider );
2008-11-05 22:44:50 +00:00
/** \brief Accessor for drawing style */
2013-05-15 17:58:44 +02:00
//DrawingStyle drawingStyle();
2008-11-05 22:44:50 +00:00
2013-04-19 21:10:38 +02:00
/** \brief Accessor that returns the width of the (unclipped) raster */
int width();
2008-11-05 22:44:50 +00:00
/** \brief Accessor that returns the height of the (unclipped) raster */
int height();
/** \brief Accessor for raster layer type (which is a read only property) */
LayerType rasterType();
/** \brief Mutator for drawing style */
2013-05-15 17:58:44 +02:00
//void setDrawingStyle( const DrawingStyle & theDrawingStyle );
2008-11-05 22:44:50 +00:00
2012-05-01 23:09:29 +02:00
/**Set raster renderer. Takes ownership of the renderer object*/
2012-09-24 02:28:15 +02:00
void setRenderer( QgsRasterRenderer* theRenderer /Transfer/ );
QgsRasterRenderer* renderer() const;
2012-05-01 23:09:29 +02:00
2012-09-24 02:28:15 +02:00
/**Set raster resample filter. Takes ownership of the resample filter object*/
2012-09-26 18:46:52 +02:00
//void setResampleFilter( QgsRasterResampleFilter* resampleFilter /Transfer/ );
2012-09-24 02:28:15 +02:00
QgsRasterResampleFilter * resampleFilter() const;
2013-09-09 09:47:05 +02:00
QgsBrightnessContrastFilter * brightnessFilter() const;
QgsHueSaturationFilter * hueSaturationFilter() const;
2012-09-24 02:28:15 +02:00
/** Get raster pipe */
2012-09-13 15:08:23 +02:00
QgsRasterPipe * pipe();
2007-01-09 02:39:15 +00:00
//
2008-11-05 22:44:50 +00:00
// Non Static methods
2007-01-09 02:39:15 +00:00
//
/** \brief Get the number of bands in this layer */
2012-09-24 02:28:15 +02:00
unsigned int bandCount() const;
2008-11-05 22:44:50 +00:00
/** \brief Get the name of a band given its number */
const QString bandName( int theBandNoInt );
/** Returns the data provider */
QgsRasterDataProvider* dataProvider();
/** Returns the data provider in a const-correct manner */
2012-09-24 22:40:15 +02:00
const QgsRasterDataProvider* constDataProvider() const;
%MethodCode
sipRes = sipCpp->dataProvider();
%End
2008-11-05 22:44:50 +00:00
2010-09-20 11:27:12 +00:00
/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();
2008-11-05 22:44:50 +00:00
/** \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 [ 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();
2012-09-24 02:28:15 +02:00
/**Returns a list with classification items (Text and color)
@note this method was added in version 1.8*/
QList< QPair< QString, QColor > > legendSymbologyItems() const;
2008-11-05 22:44:50 +00:00
/** \brief Obtain GDAL Metadata for this layer */
QString metadata();
/** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */
2012-09-24 02:28:15 +02:00
QPixmap paletteAsPixmap( int theBandNumber = 1 );
2008-11-05 22:44:50 +00:00
2012-09-12 23:15:45 +02:00
/** \brief [ data provider interface ] Which provider is being used for this Raster Layer?
2011-09-15 11:47:10 +02:00
* @note added in 2.0
*/
QString providerType() const;
2008-11-05 22:44:50 +00:00
/** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
2013-04-29 17:19:46 +02:00
double rasterUnitsPerPixelX();
double rasterUnitsPerPixelY();
2008-11-05 22:44:50 +00:00
2012-09-24 02:28:15 +02:00
/** \brief Mutator for contrast enhancement algorithm
* @param theAlgorithm Contrast enhancement algorithm
* @param theLimits Limits
* @param theExtent Extent used to calculate limits, if empty, use full layer extent
* @param theSampleSize Size of data sample to calculate limits, if 0, use full resolution
* @param theGenerateLookupTableFlag Generate llokup table. */
2008-11-05 22:44:50 +00:00
2013-04-29 17:19:46 +02:00
void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
2013-04-24 17:18:15 +02:00
QgsRaster::ContrastEnhancementLimits theLimits = QgsRaster::ContrastEnhancementMinMax,
2012-09-24 02:28:15 +02:00
QgsRectangle theExtent = QgsRectangle(),
int theSampleSize = QgsRasterLayer::SAMPLE_SIZE,
2008-11-05 22:44:50 +00:00
bool theGenerateLookupTableFlag = true );
2012-09-24 02:28:15 +02:00
/** \brief Set default contrast enhancement */
void setDefaultContrastEnhancement();
2008-11-05 22:44:50 +00:00
/** \brief Overloaded version of the above function for convenience when restoring from xml */
void setDrawingStyle( const QString & theDrawingStyleQString );
/** \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 */
2012-09-24 02:28:15 +02:00
virtual QStringList subLayers() const;
2008-11-05 22:44:50 +00:00
2012-10-04 01:43:54 -03:00
/** \brief Draws a preview of the rasterlayer into a pixmap */
QPixmap previewAsPixmap( QSize size, QColor bgColor = QColor( 255, 255, 255 ) );
2008-11-05 22:44:50 +00:00
/** \brief Emit a signal asking for a repaint. (inherited from maplayer) */
void triggerRepaint();
2007-01-09 02:39:15 +00:00
//
2012-09-24 02:28:15 +02:00
// Virtual methods
2007-01-09 02:39:15 +00:00
//
/**
* Reorders the *previously selected* sublayers of this layer from bottom to top
*
* (Useful for providers that manage their own layers, such as WMS)
*
*/
2012-09-24 02:28:15 +02:00
virtual void setLayerOrder( const QStringList &layers );
2008-11-05 22:44:50 +00:00
2007-01-09 02:39:15 +00:00
/**
* Set the visibility of the given sublayer name
*/
2012-09-24 02:28:15 +02:00
virtual void setSubLayerVisibility( QString name, bool vis );
2007-01-09 02:39:15 +00:00
2012-09-24 02:28:15 +02:00
/** Time stamp of data source in the moment when data/metadata were loaded by provider */
virtual QDateTime timestamp() const;
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
public slots:
void showStatusMessage( const QString & theMessage );
2008-01-11 06:38:10 +00:00
2008-11-05 22:44:50 +00:00
/** \brief Propagate progress updates from GDAL up to the parent app */
void updateProgress( int, int );
2008-01-11 06:38:10 +00:00
2012-09-24 02:28:15 +02:00
/** \brief receive progress signal from provider */
void onProgress( int, double, QString );
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
signals:
/** \brief Signal for notifying listeners of long running processes */
void progressUpdate( int theValue );
2007-01-09 02:39:15 +00:00
2012-09-24 02:28:15 +02:00
/**
* This is emitted whenever data or metadata (e.g. color table, extent) has changed
* @note added in 1.7
*/
void dataChanged();
2007-01-09 02:39:15 +00:00
2013-09-09 09:47:05 +02:00
/** Signal emitted when the symbology changes, through call to setRenderer() */
void rendererChanged();
2008-11-05 22:44:50 +00:00
protected:
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
/** \brief Read the symbology for the current layer from the Dom node supplied */
bool readSymbology( const QDomNode& node, QString& errorMessage );
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
/** \brief Reads layer specific state from project file Dom node */
2012-09-24 02:28:15 +02:00
bool readXml( const QDomNode& layer_node );
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
/** \brief Write the symbology for the layer into the docment provided */
2008-12-15 13:15:47 +00:00
bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
2007-01-09 02:39:15 +00:00
2008-11-05 22:44:50 +00:00
/** \brief Write layer specific state to project file Dom node */
bool writeXml( QDomNode & layer_node, QDomDocument & doc );
2007-01-09 02:39:15 +00:00
};