mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
fix a few warnings and indentation
git-svn-id: http://svn.osgeo.org/qgis/trunk@15393 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
3109508503
commit
4dc5e26d5a
@ -516,7 +516,7 @@ void QgsRasterLayerProperties::sync()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) == QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
delete tabPageSymbology;
|
delete tabPageSymbology;
|
||||||
delete tabPageColormap;
|
delete tabPageColormap;
|
||||||
@ -525,12 +525,12 @@ void QgsRasterLayerProperties::sync()
|
|||||||
tabBar->setCurrentWidget( tabPageMetadata );
|
tabBar->setCurrentWidget( tabPageMetadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! ( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::BuildPyramids ) )
|
if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::BuildPyramids ) )
|
||||||
{
|
{
|
||||||
delete tabPagePyramids;
|
delete tabPagePyramids;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! ( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Histogram ) )
|
if ( !( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Histogram ) )
|
||||||
{
|
{
|
||||||
delete tabPageHistogram;
|
delete tabPageHistogram;
|
||||||
}
|
}
|
||||||
@ -562,8 +562,8 @@ void QgsRasterLayerProperties::sync()
|
|||||||
//
|
//
|
||||||
// Populate the various controls on the form
|
// Populate the various controls on the form
|
||||||
//
|
//
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) != QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "colorShadingAlgorithm = " + QString::number( mRasterLayer->colorShadingAlgorithm() ) );
|
QgsDebugMsg( "colorShadingAlgorithm = " + QString::number( mRasterLayer->colorShadingAlgorithm() ) );
|
||||||
if ( mRasterLayer->drawingStyle() == QgsRasterLayer::SingleBandPseudoColor ||
|
if ( mRasterLayer->drawingStyle() == QgsRasterLayer::SingleBandPseudoColor ||
|
||||||
mRasterLayer->drawingStyle() == QgsRasterLayer::PalettedColor ||
|
mRasterLayer->drawingStyle() == QgsRasterLayer::PalettedColor ||
|
||||||
@ -593,7 +593,7 @@ void QgsRasterLayerProperties::sync()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) != QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
if ( rbtnThreeBand->isChecked() )
|
if ( rbtnThreeBand->isChecked() )
|
||||||
{
|
{
|
||||||
@ -782,7 +782,7 @@ void QgsRasterLayerProperties::sync()
|
|||||||
|
|
||||||
//display the raster dimensions and no data value
|
//display the raster dimensions and no data value
|
||||||
if ( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size )
|
if ( mRasterLayer->dataProvider()->capabilities() & QgsRasterDataProvider::Size )
|
||||||
{
|
{
|
||||||
lblColumns->setText( tr( "Columns: %1" ).arg( mRasterLayer->width() ) );
|
lblColumns->setText( tr( "Columns: %1" ).arg( mRasterLayer->width() ) );
|
||||||
lblRows->setText( tr( "Rows: %1" ).arg( mRasterLayer->height() ) );
|
lblRows->setText( tr( "Rows: %1" ).arg( mRasterLayer->height() ) );
|
||||||
}
|
}
|
||||||
@ -793,8 +793,8 @@ void QgsRasterLayerProperties::sync()
|
|||||||
lblRows->setText( tr( "Rows: " ) + tr( "n/a" ) );
|
lblRows->setText( tr( "Rows: " ) + tr( "n/a" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) == QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
lblNoData->setText( tr( "No-Data Value: " ) + tr( "n/a" ) );
|
lblNoData->setText( tr( "No-Data Value: " ) + tr( "n/a" ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -843,7 +843,7 @@ void QgsRasterLayerProperties::syncColormapTab()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) == QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -935,7 +935,7 @@ bool QgsRasterLayerProperties::validUserDefinedMinMax()
|
|||||||
*/
|
*/
|
||||||
void QgsRasterLayerProperties::apply()
|
void QgsRasterLayerProperties::apply()
|
||||||
{
|
{
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) != QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "apply processing symbology tab" );
|
QgsDebugMsg( "apply processing symbology tab" );
|
||||||
/*
|
/*
|
||||||
@ -1425,7 +1425,7 @@ void QgsRasterLayerProperties::apply()
|
|||||||
mRasterLayer->triggerRepaint();
|
mRasterLayer->triggerRepaint();
|
||||||
|
|
||||||
//Because Min Max values can be set during the redraw if a strech is requested we need to resync after apply
|
//Because Min Max values can be set during the redraw if a strech is requested we need to resync after apply
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) != QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) != QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
if ( QgsContrastEnhancement::NoEnhancement != mRasterLayer->contrastEnhancementAlgorithm() )
|
if ( QgsContrastEnhancement::NoEnhancement != mRasterLayer->contrastEnhancementAlgorithm() )
|
||||||
{
|
{
|
||||||
@ -1668,7 +1668,7 @@ void QgsRasterLayerProperties::on_pbnChangeSpatialRefSys_clicked()
|
|||||||
|
|
||||||
void QgsRasterLayerProperties::on_cboxColorMap_currentIndexChanged( const QString& theText )
|
void QgsRasterLayerProperties::on_cboxColorMap_currentIndexChanged( const QString& theText )
|
||||||
{
|
{
|
||||||
if ( mRasterLayer->dataProvider()->dataType(1) == QgsRasterDataProvider::ARGBDataType )
|
if ( mRasterLayer->dataProvider()->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2586,9 +2586,9 @@ void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked()
|
|||||||
|
|
||||||
void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
|
void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
|
||||||
{
|
{
|
||||||
if ( mRasterLayer->drawingStyle() == QgsRasterLayer::SingleBandGray
|
if ( mRasterLayer->drawingStyle() == QgsRasterLayer::SingleBandGray
|
||||||
|| mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray
|
|| mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray
|
||||||
|| mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandColor )
|
|| mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandColor )
|
||||||
{
|
{
|
||||||
QgsRasterBandStats myRasterBandStats;
|
QgsRasterBandStats myRasterBandStats;
|
||||||
double myMinimumMaximum[2];
|
double myMinimumMaximum[2];
|
||||||
|
@ -23,12 +23,13 @@
|
|||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data )
|
void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data )
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Entered");
|
QgsDebugMsg( "Entered" );
|
||||||
QgsDebugMsg( "viewExtent = " + viewExtent.toString() );
|
QgsDebugMsg( "viewExtent = " + viewExtent.toString() );
|
||||||
|
|
||||||
if ( ! theSrcCRS.isValid() || ! theDestCRS.isValid() ) {
|
if ( ! theSrcCRS.isValid() || ! theDestCRS.isValid() )
|
||||||
|
{
|
||||||
readBlock( bandNo, viewExtent, width, height, data );
|
readBlock( bandNo, viewExtent, width, height, data );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -38,21 +39,21 @@ void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & viewExt
|
|||||||
|
|
||||||
double mMaxSrcXRes = 0;
|
double mMaxSrcXRes = 0;
|
||||||
double mMaxSrcYRes = 0;
|
double mMaxSrcYRes = 0;
|
||||||
|
|
||||||
if ( capabilities() & QgsRasterDataProvider::ExactResolution )
|
if ( capabilities() & QgsRasterDataProvider::ExactResolution )
|
||||||
{
|
{
|
||||||
mMaxSrcXRes = extent().width()/xSize();
|
mMaxSrcXRes = extent().width() / xSize();
|
||||||
mMaxSrcYRes = extent().height()/ySize();
|
mMaxSrcYRes = extent().height() / ySize();
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRasterProjector myProjector = QgsRasterProjector ( theSrcCRS, theDestCRS, viewExtent, height, width, mMaxSrcXRes, mMaxSrcYRes );
|
QgsRasterProjector myProjector = QgsRasterProjector( theSrcCRS, theDestCRS, viewExtent, height, width, mMaxSrcXRes, mMaxSrcYRes );
|
||||||
|
|
||||||
QgsDebugMsg( QString( "create projector time (ms): %1" ).arg( time.elapsed() ) );
|
QgsDebugMsg( QString( "create projector time (ms): %1" ).arg( time.elapsed() ) );
|
||||||
|
|
||||||
// TODO: init data by nulls
|
// TODO: init data by nulls
|
||||||
|
|
||||||
// Allocate memory for not projected source data
|
// Allocate memory for not projected source data
|
||||||
int mySize = dataTypeSize(bandNo)/8;
|
int mySize = dataTypeSize( bandNo ) / 8;
|
||||||
void *mySrcData = malloc( mySize * myProjector.srcRows() * myProjector.srcCols() );
|
void *mySrcData = malloc( mySize * myProjector.srcRows() * myProjector.srcCols() );
|
||||||
|
|
||||||
time.restart();
|
time.restart();
|
||||||
@ -67,13 +68,15 @@ void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & viewExt
|
|||||||
int mySrcCol;
|
int mySrcCol;
|
||||||
int mySrcOffset;
|
int mySrcOffset;
|
||||||
int myDestOffset;
|
int myDestOffset;
|
||||||
for ( int r = 0; r < height; r++) {
|
for ( int r = 0; r < height; r++ )
|
||||||
for ( int c = 0; c < width; c++) {
|
{
|
||||||
myProjector.srcRowCol ( r, c, &mySrcRow, &mySrcCol );
|
for ( int c = 0; c < width; c++ )
|
||||||
|
{
|
||||||
|
myProjector.srcRowCol( r, c, &mySrcRow, &mySrcCol );
|
||||||
mySrcOffset = mySize * ( mySrcRow * myProjector.srcCols() + mySrcCol );
|
mySrcOffset = mySize * ( mySrcRow * myProjector.srcCols() + mySrcCol );
|
||||||
myDestOffset = mySize * ( r * width + c );
|
myDestOffset = mySize * ( r * width + c );
|
||||||
// retype to char is just to avoid g++ warning
|
// retype to char is just to avoid g++ warning
|
||||||
memcpy( (char*) data + myDestOffset, (char*)mySrcData + mySrcOffset, mySize );
|
memcpy(( char* ) data + myDestOffset, ( char* )mySrcData + mySrcOffset, mySize );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QgsDebugMsg( QString( "reproject block time (ms): %1" ).arg( time.elapsed() ) );
|
QgsDebugMsg( QString( "reproject block time (ms): %1" ).arg( time.elapsed() ) );
|
||||||
|
@ -81,29 +81,29 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
|
|||||||
/*! Complex Float64 */ CFloat64 = 11,
|
/*! Complex Float64 */ CFloat64 = 11,
|
||||||
/*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
|
/*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
|
||||||
TypeCount = 13 /* maximum type # + 1 */
|
TypeCount = 13 /* maximum type # + 1 */
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is modified copy of GDALColorInterp
|
// This is modified copy of GDALColorInterp
|
||||||
enum ColorInterpretation
|
enum ColorInterpretation
|
||||||
{
|
{
|
||||||
UndefinedColorInterpretation=0,
|
UndefinedColorInterpretation = 0,
|
||||||
/*! Greyscale */ GrayIndex=1,
|
/*! Greyscale */ GrayIndex = 1,
|
||||||
/*! Paletted (see associated color table) */ PaletteIndex=2,
|
/*! Paletted (see associated color table) */ PaletteIndex = 2,
|
||||||
/*! Red band of RGBA image */ RedBand=3,
|
/*! Red band of RGBA image */ RedBand = 3,
|
||||||
/*! Green band of RGBA image */ GreenBand=4,
|
/*! Green band of RGBA image */ GreenBand = 4,
|
||||||
/*! Blue band of RGBA image */ BlueBand=5,
|
/*! Blue band of RGBA image */ BlueBand = 5,
|
||||||
/*! Alpha (0=transparent, 255=opaque) */ AlphaBand=6,
|
/*! Alpha (0=transparent, 255=opaque) */ AlphaBand = 6,
|
||||||
/*! Hue band of HLS image */ HueBand=7,
|
/*! Hue band of HLS image */ HueBand = 7,
|
||||||
/*! Saturation band of HLS image */ SaturationBand=8,
|
/*! Saturation band of HLS image */ SaturationBand = 8,
|
||||||
/*! Lightness band of HLS image */ LightnessBand=9,
|
/*! Lightness band of HLS image */ LightnessBand = 9,
|
||||||
/*! Cyan band of CMYK image */ CyanBand=10,
|
/*! Cyan band of CMYK image */ CyanBand = 10,
|
||||||
/*! Magenta band of CMYK image */ MagentaBand=11,
|
/*! Magenta band of CMYK image */ MagentaBand = 11,
|
||||||
/*! Yellow band of CMYK image */ YellowBand=12,
|
/*! Yellow band of CMYK image */ YellowBand = 12,
|
||||||
/*! Black band of CMLY image */ BlackBand=13,
|
/*! Black band of CMLY image */ BlackBand = 13,
|
||||||
/*! Y Luminance */ YCbCr_YBand=14,
|
/*! Y Luminance */ YCbCr_YBand = 14,
|
||||||
/*! Cb Chroma */ YCbCr_CbBand=15,
|
/*! Cb Chroma */ YCbCr_CbBand = 15,
|
||||||
/*! Cr Chroma */ YCbCr_CrBand=16,
|
/*! Cr Chroma */ YCbCr_CrBand = 16,
|
||||||
/*! Max current value */ ColorInterpretationMax=16
|
/*! Max current value */ ColorInterpretationMax = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
QgsRasterDataProvider();
|
QgsRasterDataProvider();
|
||||||
@ -164,23 +164,23 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
|
|||||||
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
|
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
|
||||||
|
|
||||||
/** Returns data type for the band specified by number */
|
/** Returns data type for the band specified by number */
|
||||||
virtual int dataType ( int bandNo ) const
|
virtual int dataType( int bandNo ) const
|
||||||
{
|
{
|
||||||
return srcDataType ( bandNo );
|
return srcDataType( bandNo );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns source data type for the band specified by number,
|
/** Returns source data type for the band specified by number,
|
||||||
* source data type may be shorter than dataType
|
* source data type may be shorter than dataType
|
||||||
*/
|
*/
|
||||||
virtual int srcDataType ( int bandNo ) const
|
virtual int srcDataType( int bandNo ) const
|
||||||
{
|
{
|
||||||
return QgsRasterDataProvider::UnknownDataType;
|
return QgsRasterDataProvider::UnknownDataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
int typeSize ( int dataType ) const
|
int typeSize( int dataType ) const
|
||||||
{
|
{
|
||||||
// modified copy from GDAL
|
// modified copy from GDAL
|
||||||
switch( dataType )
|
switch ( dataType )
|
||||||
{
|
{
|
||||||
case Byte:
|
case Byte:
|
||||||
return 8;
|
return 8;
|
||||||
@ -210,24 +210,27 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int dataTypeSize ( int bandNo ) const
|
int dataTypeSize( int bandNo ) const
|
||||||
{
|
{
|
||||||
return typeSize ( dataType ( bandNo ) );
|
return typeSize( dataType( bandNo ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get numbur of bands */
|
/** Get numbur of bands */
|
||||||
virtual int bandCount() const {
|
virtual int bandCount() const
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns data type for the band specified by number */
|
/** Returns data type for the band specified by number */
|
||||||
virtual int colorInterpretation ( int theBandNo ) const {
|
virtual int colorInterpretation( int theBandNo ) const
|
||||||
|
{
|
||||||
return QgsRasterDataProvider::UndefinedColorInterpretation;
|
return QgsRasterDataProvider::UndefinedColorInterpretation;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString colorName ( int colorInterpretation ) const {
|
QString colorName( int colorInterpretation ) const
|
||||||
|
{
|
||||||
// Modified copy from GDAL
|
// Modified copy from GDAL
|
||||||
switch( colorInterpretation )
|
switch ( colorInterpretation )
|
||||||
{
|
{
|
||||||
case UndefinedColorInterpretation:
|
case UndefinedColorInterpretation:
|
||||||
return "Undefined";
|
return "Undefined";
|
||||||
@ -285,23 +288,24 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Reload data (data could change) */
|
/** Reload data (data could change) */
|
||||||
virtual bool reload ( ) { return true; }
|
virtual bool reload( ) { return true; }
|
||||||
|
|
||||||
virtual QString colorInterpretationName ( int theBandNo ) const {
|
virtual QString colorInterpretationName( int theBandNo ) const
|
||||||
return colorName ( colorInterpretation ( theBandNo ) );
|
{
|
||||||
|
return colorName( colorInterpretation( theBandNo ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get block size */
|
/** Get block size */
|
||||||
virtual int xBlockSize() const { return 0; }
|
virtual int xBlockSize() const { return 0; }
|
||||||
virtual int yBlockSize() const { return 0; }
|
virtual int yBlockSize() const { return 0; }
|
||||||
|
|
||||||
/** Get raster size */
|
/** Get raster size */
|
||||||
virtual int xSize() const { return 0; }
|
virtual int xSize() const { return 0; }
|
||||||
virtual int ySize() const { return 0; }
|
virtual int ySize() const { return 0; }
|
||||||
|
|
||||||
/** read block of data */
|
/** read block of data */
|
||||||
// TODO clarify what happens on the last block (the part outside raster)
|
// TODO clarify what happens on the last block (the part outside raster)
|
||||||
virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data ){}
|
virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data ) {}
|
||||||
|
|
||||||
/** read block of data using give extent and size */
|
/** read block of data using give extent and size */
|
||||||
virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data ) {};
|
virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data ) {};
|
||||||
@ -312,30 +316,31 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
|
|||||||
/** value representing null data */
|
/** value representing null data */
|
||||||
virtual double noDataValue() const { return 0; }
|
virtual double noDataValue() const { return 0; }
|
||||||
|
|
||||||
virtual double minimumValue(int bandNo)const { return 0; }
|
virtual double minimumValue( int bandNo )const { return 0; }
|
||||||
virtual double maximumValue(int bandNo)const { return 0; }
|
virtual double maximumValue( int bandNo )const { return 0; }
|
||||||
|
|
||||||
virtual QList<QgsColorRampShader::ColorRampItem> colorTable(int bandNo)const { return QList<QgsColorRampShader::ColorRampItem>(); }
|
virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const { return QList<QgsColorRampShader::ColorRampItem>(); }
|
||||||
|
|
||||||
// Defined in parent
|
// Defined in parent
|
||||||
/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
|
/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
|
||||||
virtual QStringList subLayers() const {
|
virtual QStringList subLayers() const
|
||||||
|
{
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Populate the histogram vector for a given band */
|
/** \brief Populate the histogram vector for a given band */
|
||||||
|
|
||||||
virtual void populateHistogram( int theBandNoInt,
|
virtual void populateHistogram( int theBandNoInt,
|
||||||
QgsRasterBandStats & theBandStats,
|
QgsRasterBandStats & theBandStats,
|
||||||
int theBinCountInt = 256,
|
int theBinCountInt = 256,
|
||||||
bool theIgnoreOutOfRangeFlag = true,
|
bool theIgnoreOutOfRangeFlag = true,
|
||||||
bool theThoroughBandScanFlag = false
|
bool theThoroughBandScanFlag = false
|
||||||
) {};
|
) {};
|
||||||
|
|
||||||
/** \brief Create pyramid overviews */
|
/** \brief Create pyramid overviews */
|
||||||
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
|
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
|
||||||
const QString & theResamplingMethod = "NEAREST",
|
const QString & theResamplingMethod = "NEAREST",
|
||||||
bool theTryInternalFlag = false ) { return "FAILED_NOT_SUPPORTED"; };
|
bool theTryInternalFlag = false ) { return "FAILED_NOT_SUPPORTED"; };
|
||||||
|
|
||||||
/** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the
|
/** \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
|
* POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers
|
||||||
@ -346,7 +351,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
|
|||||||
|
|
||||||
|
|
||||||
/** \brief helper function to create zero padded band names */
|
/** \brief helper function to create zero padded band names */
|
||||||
QString generateBandName( int theBandNumber )
|
QString generateBandName( int theBandNumber )
|
||||||
{
|
{
|
||||||
return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
|
return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
|
||||||
}
|
}
|
||||||
|
@ -22,73 +22,78 @@
|
|||||||
#include "qgsrasterprojector.h"
|
#include "qgsrasterprojector.h"
|
||||||
#include "qgscoordinatetransform.h"
|
#include "qgscoordinatetransform.h"
|
||||||
|
|
||||||
QgsRasterProjector::QgsRasterProjector (
|
QgsRasterProjector::QgsRasterProjector(
|
||||||
QgsCoordinateReferenceSystem theSrcCRS,
|
QgsCoordinateReferenceSystem theSrcCRS,
|
||||||
QgsCoordinateReferenceSystem theDestCRS,
|
QgsCoordinateReferenceSystem theDestCRS,
|
||||||
QgsRectangle theDestExtent,
|
QgsRectangle theDestExtent,
|
||||||
int theDestRows, int theDestCols,
|
int theDestRows, int theDestCols,
|
||||||
double theMaxSrcXRes, double theMaxSrcYRes )
|
double theMaxSrcXRes, double theMaxSrcYRes )
|
||||||
: mSrcCRS ( theSrcCRS )
|
: mSrcCRS( theSrcCRS )
|
||||||
, mDestCRS ( theDestCRS )
|
, mDestCRS( theDestCRS )
|
||||||
, mDestExtent ( theDestExtent )
|
, mDestExtent( theDestExtent )
|
||||||
, mDestRows ( theDestRows ), mDestCols ( theDestCols )
|
, mDestRows( theDestRows ), mDestCols( theDestCols )
|
||||||
, mMaxSrcXRes ( theMaxSrcXRes), mMaxSrcYRes ( theMaxSrcYRes )
|
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Entered");
|
QgsDebugMsg( "Entered" );
|
||||||
QgsDebugMsg("theDestExtent = " + theDestExtent.toString() );
|
QgsDebugMsg( "theDestExtent = " + theDestExtent.toString() );
|
||||||
|
|
||||||
// reverse transformation
|
// reverse transformation
|
||||||
mCoordinateTransform = new QgsCoordinateTransform( theDestCRS, theSrcCRS );
|
mCoordinateTransform = new QgsCoordinateTransform( theDestCRS, theSrcCRS );
|
||||||
|
|
||||||
mDestXRes = mDestExtent.width() / (mDestCols);
|
mDestXRes = mDestExtent.width() / ( mDestCols );
|
||||||
mDestYRes = mDestExtent.height() / (mDestRows);
|
mDestYRes = mDestExtent.height() / ( mDestRows );
|
||||||
|
|
||||||
// Calculate tolerance
|
// Calculate tolerance
|
||||||
// TODO: Think it over better
|
// TODO: Think it over better
|
||||||
// Note: we are checking on matrix each even point, that means taht the real error
|
// Note: we are checking on matrix each even point, that means taht the real error
|
||||||
// in that moment is approximately half size
|
// in that moment is approximately half size
|
||||||
double myDestRes = mDestXRes < mDestYRes ? mDestXRes : mDestYRes;
|
double myDestRes = mDestXRes < mDestYRes ? mDestXRes : mDestYRes;
|
||||||
mSqrTolerance = myDestRes * myDestRes;
|
mSqrTolerance = myDestRes * myDestRes;
|
||||||
|
|
||||||
// Initialize the matrix by corners and middle points
|
// Initialize the matrix by corners and middle points
|
||||||
mCPCols = mCPRows = 3;
|
mCPCols = mCPRows = 3;
|
||||||
for ( int i = 0; i < mCPRows; i++) {
|
for ( int i = 0; i < mCPRows; i++ )
|
||||||
|
{
|
||||||
QList<QgsPoint> myRow;
|
QList<QgsPoint> myRow;
|
||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
mCPMatrix.insert(i, myRow );
|
mCPMatrix.insert( i, myRow );
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < mCPRows; i++) {
|
for ( int i = 0; i < mCPRows; i++ )
|
||||||
|
{
|
||||||
calcRow( i );
|
calcRow( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true)
|
while ( true )
|
||||||
{
|
{
|
||||||
bool myColsOK = checkCols();
|
bool myColsOK = checkCols();
|
||||||
if ( !myColsOK ) {
|
if ( !myColsOK )
|
||||||
|
{
|
||||||
insertRows();
|
insertRows();
|
||||||
}
|
}
|
||||||
bool myRowsOK = checkRows();
|
bool myRowsOK = checkRows();
|
||||||
if ( !myRowsOK ) {
|
if ( !myRowsOK )
|
||||||
|
{
|
||||||
insertCols();
|
insertCols();
|
||||||
}
|
}
|
||||||
if ( myColsOK && myRowsOK ) {
|
if ( myColsOK && myRowsOK )
|
||||||
QgsDebugMsg("CP matrix within tolerance");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// What is the maximum reasonable size of transformatio matrix?
|
|
||||||
// TODO: consider better when to break - ratio
|
|
||||||
if ( mCPRows * mCPCols > 0.25 * mDestRows * mDestCols )
|
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Too large CP matrix");
|
QgsDebugMsg( "CP matrix within tolerance" );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// What is the maximum reasonable size of transformatio matrix?
|
||||||
|
// TODO: consider better when to break - ratio
|
||||||
|
if ( mCPRows * mCPCols > 0.25 * mDestRows * mDestCols )
|
||||||
|
{
|
||||||
|
QgsDebugMsg( "Too large CP matrix" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
QgsDebugMsg( QString("CPMatrix size: mCPRows = %1 mCPCols = %2").arg(mCPRows).arg(mCPCols) );
|
QgsDebugMsg( QString( "CPMatrix size: mCPRows = %1 mCPCols = %2" ).arg( mCPRows ).arg( mCPCols ) );
|
||||||
mDestRowsPerMatrixRow = (float)mDestRows / (mCPRows - 1);
|
mDestRowsPerMatrixRow = ( float )mDestRows / ( mCPRows - 1 );
|
||||||
mDestColsPerMatrixCol = (float)mDestCols / (mCPCols - 1);
|
mDestColsPerMatrixCol = ( float )mDestCols / ( mCPCols - 1 );
|
||||||
|
|
||||||
QgsDebugMsg( "CPMatrix:\n" + cpToString() );
|
QgsDebugMsg( "CPMatrix:\n" + cpToString() );
|
||||||
|
|
||||||
@ -98,47 +103,51 @@ QgsRasterProjector::QgsRasterProjector (
|
|||||||
mSrcXRes = mSrcExtent.height() / mSrcRows;
|
mSrcXRes = mSrcExtent.height() / mSrcRows;
|
||||||
mSrcYRes = mSrcExtent.width() / mSrcCols;
|
mSrcYRes = mSrcExtent.width() / mSrcCols;
|
||||||
|
|
||||||
// init helper points
|
// init helper points
|
||||||
pHelperTop = new QgsPoint[mDestCols];
|
pHelperTop = new QgsPoint[mDestCols];
|
||||||
pHelperBottom = new QgsPoint[mDestCols];
|
pHelperBottom = new QgsPoint[mDestCols];
|
||||||
calcHelper ( 0, pHelperTop );
|
calcHelper( 0, pHelperTop );
|
||||||
calcHelper ( 1, pHelperBottom );
|
calcHelper( 1, pHelperBottom );
|
||||||
mHelperTopRow = 0;
|
mHelperTopRow = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRasterProjector::~QgsRasterProjector ()
|
QgsRasterProjector::~QgsRasterProjector()
|
||||||
{
|
{
|
||||||
delete mCoordinateTransform;
|
delete mCoordinateTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::calcSrcExtent ()
|
void QgsRasterProjector::calcSrcExtent()
|
||||||
{
|
{
|
||||||
/* Run around the mCPMatrix and find source extent */
|
/* Run around the mCPMatrix and find source extent */
|
||||||
QgsPoint myPoint = mCPMatrix[0][0];
|
QgsPoint myPoint = mCPMatrix[0][0];
|
||||||
mSrcExtent = QgsRectangle ( myPoint.x(), myPoint.y(), myPoint.x(), myPoint.y() );
|
mSrcExtent = QgsRectangle( myPoint.x(), myPoint.y(), myPoint.x(), myPoint.y() );
|
||||||
for ( int i = 0; i < mCPRows; i++) {
|
for ( int i = 0; i < mCPRows; i++ )
|
||||||
|
{
|
||||||
myPoint = mCPMatrix[i][0];
|
myPoint = mCPMatrix[i][0];
|
||||||
mSrcExtent.combineExtentWith ( myPoint.x(), myPoint.y() );
|
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
|
||||||
myPoint = mCPMatrix[i][mCPCols-1];
|
myPoint = mCPMatrix[i][mCPCols-1];
|
||||||
mSrcExtent.combineExtentWith ( myPoint.x(), myPoint.y() );
|
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
|
||||||
}
|
}
|
||||||
for ( int i = 1; i < mCPCols-1; i++) {
|
for ( int i = 1; i < mCPCols - 1; i++ )
|
||||||
|
{
|
||||||
myPoint = mCPMatrix[0][i];
|
myPoint = mCPMatrix[0][i];
|
||||||
mSrcExtent.combineExtentWith ( myPoint.x(), myPoint.y() );
|
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
|
||||||
myPoint = mCPMatrix[mCPRows-1][i];
|
myPoint = mCPMatrix[mCPRows-1][i];
|
||||||
mSrcExtent.combineExtentWith ( myPoint.x(), myPoint.y() );
|
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
|
||||||
}
|
}
|
||||||
// Expand a bit to avoid possible approx coords falling out because of representation error
|
// Expand a bit to avoid possible approx coords falling out because of representation error
|
||||||
|
|
||||||
QgsDebugMsg( "mSrcExtent = " + mSrcExtent.toString() );
|
QgsDebugMsg( "mSrcExtent = " + mSrcExtent.toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsRasterProjector::cpToString()
|
QString QgsRasterProjector::cpToString()
|
||||||
{
|
{
|
||||||
QString myString;
|
QString myString;
|
||||||
for ( int i = 0; i < mCPRows; i++) {
|
for ( int i = 0; i < mCPRows; i++ )
|
||||||
|
{
|
||||||
if ( i > 0 ) myString += "\n";
|
if ( i > 0 ) myString += "\n";
|
||||||
for ( int j = 0; j < mCPCols; j++) {
|
for ( int j = 0; j < mCPCols; j++ )
|
||||||
|
{
|
||||||
if ( j > 0 ) myString += " ";
|
if ( j > 0 ) myString += " ";
|
||||||
QgsPoint myPoint = mCPMatrix[i][j];
|
QgsPoint myPoint = mCPMatrix[i][j];
|
||||||
myString += myPoint.toString();
|
myString += myPoint.toString();
|
||||||
@ -147,114 +156,118 @@ QString QgsRasterProjector::cpToString()
|
|||||||
return myString;
|
return myString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::calcSrcRowsCols ()
|
void QgsRasterProjector::calcSrcRowsCols()
|
||||||
{
|
{
|
||||||
// Wee need to calculate minimum cell size in the source
|
// Wee need to calculate minimum cell size in the source
|
||||||
// TODO: Think it over better, what is the right source resolution?
|
// TODO: Think it over better, what is the right source resolution?
|
||||||
// Taking distances between cell centers projected to source along source
|
// Taking distances between cell centers projected to source along source
|
||||||
// axis would result in very high resolution
|
// axis would result in very high resolution
|
||||||
// TODO: different resolution for rows and cols ?
|
// TODO: different resolution for rows and cols ?
|
||||||
|
|
||||||
// For now, we take cell sizes projected to source but not to source axes
|
// For now, we take cell sizes projected to source but not to source axes
|
||||||
double myDestColsPerMatrixCell = mDestCols / mCPCols;
|
double myDestColsPerMatrixCell = mDestCols / mCPCols;
|
||||||
double myDestRowsPerMatrixCell = mDestRows / mCPRows;
|
double myDestRowsPerMatrixCell = mDestRows / mCPRows;
|
||||||
QgsDebugMsg( QString("myDestColsPerMatrixCell = %1 myDestRowsPerMatrixCell = %2" ).arg ( myDestColsPerMatrixCell ).arg( myDestRowsPerMatrixCell ) );
|
QgsDebugMsg( QString( "myDestColsPerMatrixCell = %1 myDestRowsPerMatrixCell = %2" ).arg( myDestColsPerMatrixCell ).arg( myDestRowsPerMatrixCell ) );
|
||||||
|
|
||||||
double myMinSize = DBL_MAX;
|
double myMinSize = DBL_MAX;
|
||||||
|
|
||||||
for ( int i = 0; i < mCPRows-1; i++) {
|
for ( int i = 0; i < mCPRows - 1; i++ )
|
||||||
for ( int j = 0; j < mCPCols-1; j++) {
|
{
|
||||||
|
for ( int j = 0; j < mCPCols - 1; j++ )
|
||||||
|
{
|
||||||
QgsPoint myPointA = mCPMatrix[i][j];
|
QgsPoint myPointA = mCPMatrix[i][j];
|
||||||
QgsPoint myPointB = mCPMatrix[i][j+1];
|
QgsPoint myPointB = mCPMatrix[i][j+1];
|
||||||
QgsPoint myPointC = mCPMatrix[i+1][j];
|
QgsPoint myPointC = mCPMatrix[i+1][j];
|
||||||
double mySize = sqrt(myPointA.sqrDist( myPointB )) / myDestColsPerMatrixCell;
|
double mySize = sqrt( myPointA.sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
|
||||||
if ( mySize < myMinSize ) { myMinSize = mySize; }
|
if ( mySize < myMinSize ) { myMinSize = mySize; }
|
||||||
|
|
||||||
mySize = sqrt(myPointA.sqrDist( myPointC )) / myDestRowsPerMatrixCell;
|
mySize = sqrt( myPointA.sqrDist( myPointC ) ) / myDestRowsPerMatrixCell;
|
||||||
if ( mySize < myMinSize ) { myMinSize = mySize; }
|
if ( mySize < myMinSize ) { myMinSize = mySize; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make it a bit higher resolution
|
|
||||||
// TODO: find the best coefficient, attention, increasing resolution for WMS
|
|
||||||
// is changing WMS content
|
|
||||||
myMinSize *= 0.75;
|
|
||||||
|
|
||||||
QgsDebugMsg( QString("mMaxSrcXRes = %1 mMaxSrcYRes = %2" ).arg ( mMaxSrcXRes ).arg( mMaxSrcYRes ) );
|
// Make it a bit higher resolution
|
||||||
|
// TODO: find the best coefficient, attention, increasing resolution for WMS
|
||||||
|
// is changing WMS content
|
||||||
|
myMinSize *= 0.75;
|
||||||
|
|
||||||
|
QgsDebugMsg( QString( "mMaxSrcXRes = %1 mMaxSrcYRes = %2" ).arg( mMaxSrcXRes ).arg( mMaxSrcYRes ) );
|
||||||
// mMaxSrcXRes, mMaxSrcYRes may be 0 - no limit (WMS)
|
// mMaxSrcXRes, mMaxSrcYRes may be 0 - no limit (WMS)
|
||||||
double myMinXSize = mMaxSrcXRes > myMinSize ? mMaxSrcXRes : myMinSize;
|
double myMinXSize = mMaxSrcXRes > myMinSize ? mMaxSrcXRes : myMinSize;
|
||||||
double myMinYSize = mMaxSrcYRes > myMinSize ? mMaxSrcYRes : myMinSize;
|
double myMinYSize = mMaxSrcYRes > myMinSize ? mMaxSrcYRes : myMinSize;
|
||||||
QgsDebugMsg( QString("myMinXSize = %1 myMinYSize = %2" ).arg ( myMinXSize ).arg( myMinYSize ) );
|
QgsDebugMsg( QString( "myMinXSize = %1 myMinYSize = %2" ).arg( myMinXSize ).arg( myMinYSize ) );
|
||||||
QgsDebugMsg( QString("mSrcExtent.width = %1 mSrcExtent.height = %2" ).arg ( mSrcExtent.width() ).arg( mSrcExtent.height() ) );
|
QgsDebugMsg( QString( "mSrcExtent.width = %1 mSrcExtent.height = %2" ).arg( mSrcExtent.width() ).arg( mSrcExtent.height() ) );
|
||||||
mSrcRows = (int) ceil ( mSrcExtent.height() / myMinYSize );
|
mSrcRows = ( int ) ceil( mSrcExtent.height() / myMinYSize );
|
||||||
mSrcCols = (int) ceil ( mSrcExtent.width() / myMinXSize );
|
mSrcCols = ( int ) ceil( mSrcExtent.width() / myMinXSize );
|
||||||
|
|
||||||
QgsDebugMsg( QString("mSrcRows = %1 mSrcCols = %2").arg(mSrcRows).arg(mSrcCols) );
|
QgsDebugMsg( QString( "mSrcRows = %1 mSrcCols = %2" ).arg( mSrcRows ).arg( mSrcCols ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void QgsRasterProjector::destPointOnCPMatrix ( int theRow, int theCol, double *theX, double *theY )
|
inline void QgsRasterProjector::destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY )
|
||||||
{
|
{
|
||||||
*theX = mDestExtent.xMinimum() + theCol * mDestExtent.width() / (mCPCols-1);
|
*theX = mDestExtent.xMinimum() + theCol * mDestExtent.width() / ( mCPCols - 1 );
|
||||||
*theY = mDestExtent.yMaximum() - theRow * mDestExtent.height() / (mCPRows-1);
|
*theY = mDestExtent.yMaximum() - theRow * mDestExtent.height() / ( mCPRows - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int QgsRasterProjector::matrixRow ( int theDestRow )
|
inline int QgsRasterProjector::matrixRow( int theDestRow )
|
||||||
{
|
{
|
||||||
return (int) ( floor ( (theDestRow + 0.5) / mDestRowsPerMatrixRow ) );
|
return ( int )( floor(( theDestRow + 0.5 ) / mDestRowsPerMatrixRow ) );
|
||||||
}
|
}
|
||||||
inline int QgsRasterProjector::matrixCol ( int theDestCol )
|
inline int QgsRasterProjector::matrixCol( int theDestCol )
|
||||||
{
|
{
|
||||||
return (int) ( floor ( (theDestCol + 0.5) / mDestColsPerMatrixCol ) );
|
return ( int )( floor(( theDestCol + 0.5 ) / mDestColsPerMatrixCol ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsPoint QgsRasterProjector::srcPoint ( int theDestRow, int theCol )
|
QgsPoint QgsRasterProjector::srcPoint( int theDestRow, int theCol )
|
||||||
{
|
{
|
||||||
return QgsPoint();
|
return QgsPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::calcHelper ( int theMatrixRow, QgsPoint *thePoints )
|
void QgsRasterProjector::calcHelper( int theMatrixRow, QgsPoint *thePoints )
|
||||||
{
|
{
|
||||||
// TODO?: should we also precalc dest cell center coordinates for x and y?
|
// TODO?: should we also precalc dest cell center coordinates for x and y?
|
||||||
for ( int myDestCol = 0; myDestCol < mDestCols; myDestCol++) {
|
for ( int myDestCol = 0; myDestCol < mDestCols; myDestCol++ )
|
||||||
|
{
|
||||||
double myDestX = mDestExtent.xMinimum() + ( myDestCol + 0.5 ) * mDestXRes;
|
double myDestX = mDestExtent.xMinimum() + ( myDestCol + 0.5 ) * mDestXRes;
|
||||||
|
|
||||||
int myMatrixCol = matrixCol ( myDestCol );
|
int myMatrixCol = matrixCol( myDestCol );
|
||||||
|
|
||||||
double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
|
double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
|
||||||
|
|
||||||
destPointOnCPMatrix ( theMatrixRow, myMatrixCol, &myDestXMin, &myDestYMin );
|
destPointOnCPMatrix( theMatrixRow, myMatrixCol, &myDestXMin, &myDestYMin );
|
||||||
destPointOnCPMatrix ( theMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax );
|
destPointOnCPMatrix( theMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax );
|
||||||
|
|
||||||
double xfrac = ( myDestX - myDestXMin ) / ( myDestXMax - myDestXMin );
|
double xfrac = ( myDestX - myDestXMin ) / ( myDestXMax - myDestXMin );
|
||||||
|
|
||||||
QgsPoint &mySrcPoint0 = mCPMatrix[theMatrixRow][myMatrixCol];
|
QgsPoint &mySrcPoint0 = mCPMatrix[theMatrixRow][myMatrixCol];
|
||||||
QgsPoint &mySrcPoint1 = mCPMatrix[theMatrixRow][myMatrixCol+1];
|
QgsPoint &mySrcPoint1 = mCPMatrix[theMatrixRow][myMatrixCol+1];
|
||||||
double s = mySrcPoint0.x() + ( mySrcPoint1.x() - mySrcPoint0.x() ) * xfrac;
|
double s = mySrcPoint0.x() + ( mySrcPoint1.x() - mySrcPoint0.x() ) * xfrac;
|
||||||
double t = mySrcPoint0.y() + ( mySrcPoint1.y() - mySrcPoint0.y() ) * xfrac;
|
double t = mySrcPoint0.y() + ( mySrcPoint1.y() - mySrcPoint0.y() ) * xfrac;
|
||||||
|
|
||||||
thePoints[myDestCol].setX ( s );
|
thePoints[myDestCol].setX( s );
|
||||||
thePoints[myDestCol].setY ( t );
|
thePoints[myDestCol].setY( t );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void QgsRasterProjector::nextHelper ()
|
void QgsRasterProjector::nextHelper()
|
||||||
{
|
{
|
||||||
QgsPoint *tmp;
|
QgsPoint *tmp;
|
||||||
tmp = pHelperTop;
|
tmp = pHelperTop;
|
||||||
pHelperTop = pHelperBottom;
|
pHelperTop = pHelperBottom;
|
||||||
pHelperBottom = tmp;
|
pHelperBottom = tmp;
|
||||||
calcHelper ( mHelperTopRow+2, pHelperBottom );
|
calcHelper( mHelperTopRow + 2, pHelperBottom );
|
||||||
mHelperTopRow++;
|
mHelperTopRow++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::srcRowCol ( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
|
void QgsRasterProjector::srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
|
||||||
{
|
{
|
||||||
int myMatrixRow = matrixRow ( theDestRow );
|
int myMatrixRow = matrixRow( theDestRow );
|
||||||
int myMatrixCol = matrixCol ( theDestCol );
|
int myMatrixCol = matrixCol( theDestCol );
|
||||||
|
|
||||||
if ( myMatrixRow > mHelperTopRow ) {
|
if ( myMatrixRow > mHelperTopRow )
|
||||||
|
{
|
||||||
// TODO: make it more robust (for random, not sequential reading)
|
// TODO: make it more robust (for random, not sequential reading)
|
||||||
nextHelper ();
|
nextHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
double myDestY = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes;
|
double myDestY = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes;
|
||||||
@ -263,11 +276,11 @@ void QgsRasterProjector::srcRowCol ( int theDestRow, int theDestCol, int *theSrc
|
|||||||
// TODO: use some kind of cache of values which can be reused
|
// TODO: use some kind of cache of values which can be reused
|
||||||
double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
|
double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
|
||||||
|
|
||||||
destPointOnCPMatrix ( myMatrixRow + 1, myMatrixCol, &myDestXMin, &myDestYMin );
|
destPointOnCPMatrix( myMatrixRow + 1, myMatrixCol, &myDestXMin, &myDestYMin );
|
||||||
destPointOnCPMatrix ( myMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax );
|
destPointOnCPMatrix( myMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax );
|
||||||
|
|
||||||
double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin );
|
double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin );
|
||||||
|
|
||||||
QgsPoint &myTop = pHelperTop[theDestCol];
|
QgsPoint &myTop = pHelperTop[theDestCol];
|
||||||
QgsPoint &myBot = pHelperBottom[theDestCol];
|
QgsPoint &myBot = pHelperBottom[theDestCol];
|
||||||
|
|
||||||
@ -279,87 +292,101 @@ void QgsRasterProjector::srcRowCol ( int theDestRow, int theDestCol, int *theSrc
|
|||||||
double ty = myTop.y();
|
double ty = myTop.y();
|
||||||
double bx = myBot.x();
|
double bx = myBot.x();
|
||||||
double by = myBot.y();
|
double by = myBot.y();
|
||||||
double mySrcX = bx + (tx - bx) * yfrac;
|
double mySrcX = bx + ( tx - bx ) * yfrac;
|
||||||
double mySrcY = by + (ty - by) * yfrac;
|
double mySrcY = by + ( ty - by ) * yfrac;
|
||||||
|
|
||||||
// TODO: check again cell selection (coor is in the middle)
|
// TODO: check again cell selection (coor is in the middle)
|
||||||
|
|
||||||
*theSrcRow = (int) floor ( ( mSrcExtent.yMaximum() - mySrcY ) / mSrcXRes );
|
*theSrcRow = ( int ) floor(( mSrcExtent.yMaximum() - mySrcY ) / mSrcXRes );
|
||||||
*theSrcCol = (int) floor ( ( mySrcX - mSrcExtent.xMinimum() ) / mSrcYRes );
|
*theSrcCol = ( int ) floor(( mySrcX - mSrcExtent.xMinimum() ) / mSrcYRes );
|
||||||
|
|
||||||
assert ( *theSrcRow < mSrcRows );
|
assert( *theSrcRow < mSrcRows );
|
||||||
assert ( *theSrcCol < mSrcCols );
|
assert( *theSrcCol < mSrcCols );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::insertRows()
|
void QgsRasterProjector::insertRows()
|
||||||
{
|
{
|
||||||
for ( int r = 0; r < mCPRows-1; r++) {
|
for ( int r = 0; r < mCPRows - 1; r++ )
|
||||||
|
{
|
||||||
QList<QgsPoint> myRow;
|
QList<QgsPoint> myRow;
|
||||||
for ( int c = 0; c < mCPCols; c++) {
|
for ( int c = 0; c < mCPCols; c++ )
|
||||||
|
{
|
||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
}
|
}
|
||||||
QgsDebugMsg( QString("insert new row at %1" ).arg(1+r*2) );
|
QgsDebugMsg( QString( "insert new row at %1" ).arg( 1 + r*2 ) );
|
||||||
mCPMatrix.insert( 1+r*2, myRow );
|
mCPMatrix.insert( 1 + r*2, myRow );
|
||||||
}
|
}
|
||||||
mCPRows += mCPRows-1;
|
mCPRows += mCPRows - 1;
|
||||||
for ( int r = 1; r < mCPRows-1; r += 2) {
|
for ( int r = 1; r < mCPRows - 1; r += 2 )
|
||||||
|
{
|
||||||
calcRow( r );
|
calcRow( r );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::insertCols()
|
void QgsRasterProjector::insertCols()
|
||||||
{
|
{
|
||||||
for ( int r = 0; r < mCPRows; r++) {
|
for ( int r = 0; r < mCPRows; r++ )
|
||||||
|
{
|
||||||
QList<QgsPoint> myRow;
|
QList<QgsPoint> myRow;
|
||||||
for ( int c = 0; c < mCPCols-1; c++) {
|
for ( int c = 0; c < mCPCols - 1; c++ )
|
||||||
mCPMatrix[r].insert( 1+c*2, QgsPoint() );
|
{
|
||||||
|
mCPMatrix[r].insert( 1 + c*2, QgsPoint() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCPCols += mCPCols-1;
|
mCPCols += mCPCols - 1;
|
||||||
for ( int c = 1; c < mCPCols-1; c += 2) {
|
for ( int c = 1; c < mCPCols - 1; c += 2 )
|
||||||
|
{
|
||||||
calcCol( c );
|
calcCol( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsRasterProjector::calcCP ( int theRow, int theCol )
|
void QgsRasterProjector::calcCP( int theRow, int theCol )
|
||||||
{
|
{
|
||||||
double myDestX, myDestY;
|
double myDestX, myDestY;
|
||||||
destPointOnCPMatrix ( theRow, theCol, &myDestX, &myDestY );
|
destPointOnCPMatrix( theRow, theCol, &myDestX, &myDestY );
|
||||||
QgsPoint myDestPoint ( myDestX, myDestY );
|
QgsPoint myDestPoint( myDestX, myDestY );
|
||||||
|
|
||||||
mCPMatrix[theRow][theCol] = mCoordinateTransform->transform( myDestPoint );
|
mCPMatrix[theRow][theCol] = mCoordinateTransform->transform( myDestPoint );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsRasterProjector::calcRow( int theRow )
|
bool QgsRasterProjector::calcRow( int theRow )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString("theRow = %1").arg(theRow) );
|
QgsDebugMsg( QString( "theRow = %1" ).arg( theRow ) );
|
||||||
for ( int i = 0; i < mCPCols; i++) {
|
for ( int i = 0; i < mCPCols; i++ )
|
||||||
calcCP ( theRow, i );
|
{
|
||||||
|
calcCP( theRow, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsRasterProjector::calcCol( int theCol )
|
bool QgsRasterProjector::calcCol( int theCol )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString("theCol = %1").arg(theCol) );
|
QgsDebugMsg( QString( "theCol = %1" ).arg( theCol ) );
|
||||||
for ( int i = 0; i < mCPRows; i++) {
|
for ( int i = 0; i < mCPRows; i++ )
|
||||||
calcCP ( i, theCol );
|
{
|
||||||
|
calcCP( i, theCol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsRasterProjector::checkCols()
|
bool QgsRasterProjector::checkCols()
|
||||||
{
|
{
|
||||||
for ( int c = 0; c < mCPCols; c++) {
|
for ( int c = 0; c < mCPCols; c++ )
|
||||||
for ( int r = 1; r < mCPRows-1; r += 2 ) {
|
{
|
||||||
|
for ( int r = 1; r < mCPRows - 1; r += 2 )
|
||||||
|
{
|
||||||
double myDestX, myDestY;
|
double myDestX, myDestY;
|
||||||
destPointOnCPMatrix ( r, c, &myDestX, &myDestY );
|
destPointOnCPMatrix( r, c, &myDestX, &myDestY );
|
||||||
QgsPoint myDestPoint ( myDestX, myDestY );
|
QgsPoint myDestPoint( myDestX, myDestY );
|
||||||
|
|
||||||
QgsPoint mySrcPoint1 = mCPMatrix[r-1][c];
|
QgsPoint mySrcPoint1 = mCPMatrix[r-1][c];
|
||||||
QgsPoint mySrcPoint2 = mCPMatrix[r][c];
|
QgsPoint mySrcPoint2 = mCPMatrix[r][c];
|
||||||
QgsPoint mySrcPoint3 = mCPMatrix[r+1][c];
|
QgsPoint mySrcPoint3 = mCPMatrix[r+1][c];
|
||||||
|
|
||||||
QgsPoint mySrcApprox( ( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, (mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
||||||
QgsPoint myDestApprox = mCoordinateTransform->transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
QgsPoint myDestApprox = mCoordinateTransform->transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
||||||
double mySqrDist = myDestApprox.sqrDist( myDestPoint );
|
double mySqrDist = myDestApprox.sqrDist( myDestPoint );
|
||||||
if ( mySqrDist > mSqrTolerance ) { return false; }
|
if ( mySqrDist > mSqrTolerance ) { return false; }
|
||||||
@ -370,17 +397,19 @@ bool QgsRasterProjector::checkCols()
|
|||||||
|
|
||||||
bool QgsRasterProjector::checkRows()
|
bool QgsRasterProjector::checkRows()
|
||||||
{
|
{
|
||||||
for ( int r = 0; r < mCPRows; r++) {
|
for ( int r = 0; r < mCPRows; r++ )
|
||||||
for ( int c = 1; c < mCPCols-1; c += 2 ) {
|
{
|
||||||
|
for ( int c = 1; c < mCPCols - 1; c += 2 )
|
||||||
|
{
|
||||||
double myDestX, myDestY;
|
double myDestX, myDestY;
|
||||||
destPointOnCPMatrix ( r, c, &myDestX, &myDestY );
|
destPointOnCPMatrix( r, c, &myDestX, &myDestY );
|
||||||
|
|
||||||
QgsPoint myDestPoint ( myDestX, myDestY );
|
QgsPoint myDestPoint( myDestX, myDestY );
|
||||||
QgsPoint mySrcPoint1 = mCPMatrix[r][c-1];
|
QgsPoint mySrcPoint1 = mCPMatrix[r][c-1];
|
||||||
QgsPoint mySrcPoint2 = mCPMatrix[r][c];
|
QgsPoint mySrcPoint2 = mCPMatrix[r][c];
|
||||||
QgsPoint mySrcPoint3 = mCPMatrix[r][c+1];
|
QgsPoint mySrcPoint3 = mCPMatrix[r][c+1];
|
||||||
|
|
||||||
QgsPoint mySrcApprox( ( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, (mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
||||||
QgsPoint myDestApprox = mCoordinateTransform->transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
QgsPoint myDestApprox = mCoordinateTransform->transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
||||||
double mySqrDist = myDestApprox.sqrDist( myDestPoint );
|
double mySqrDist = myDestApprox.sqrDist( myDestPoint );
|
||||||
if ( mySqrDist > mSqrTolerance ) { return false; }
|
if ( mySqrDist > mSqrTolerance ) { return false; }
|
||||||
|
@ -37,19 +37,19 @@
|
|||||||
//class QgsRectangle;
|
//class QgsRectangle;
|
||||||
class QgsPoint;
|
class QgsPoint;
|
||||||
|
|
||||||
//class CORE_EXPORT QgsRasterProjector
|
//class CORE_EXPORT QgsRasterProjector
|
||||||
class QgsRasterProjector
|
class QgsRasterProjector
|
||||||
{
|
{
|
||||||
// Q_OBJECT
|
// Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/** \brief QgsRasterProjector implements approximate projection support for
|
/** \brief QgsRasterProjector implements approximate projection support for
|
||||||
* it calculates grid of points in source CRS for target CRS + extent
|
* it calculates grid of points in source CRS for target CRS + extent
|
||||||
* which are used to calculate affine transformation matrices.
|
* which are used to calculate affine transformation matrices.
|
||||||
* */
|
* */
|
||||||
QgsRasterProjector(
|
QgsRasterProjector(
|
||||||
QgsCoordinateReferenceSystem theSrcCRS,
|
QgsCoordinateReferenceSystem theSrcCRS,
|
||||||
QgsCoordinateReferenceSystem theDestCRS,
|
QgsCoordinateReferenceSystem theDestCRS,
|
||||||
QgsRectangle theDestExtent,
|
QgsRectangle theDestExtent,
|
||||||
int theDestRows, int theDestCols,
|
int theDestRows, int theDestCols,
|
||||||
double theMaxSrcXRes, double theMaxSrcYRes
|
double theMaxSrcXRes, double theMaxSrcYRes
|
||||||
);
|
);
|
||||||
@ -59,17 +59,17 @@ class QgsRasterProjector
|
|||||||
|
|
||||||
|
|
||||||
/** \brief get destination point for _current_ destination position */
|
/** \brief get destination point for _current_ destination position */
|
||||||
void destPointOnCPMatrix ( int theRow, int theCol, double *theX, double *theY );
|
void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
|
||||||
|
|
||||||
/** \brief Get matrix upper left row/col indexes for destination row/col */
|
/** \brief Get matrix upper left row/col indexes for destination row/col */
|
||||||
int matrixRow ( int theDestRow );
|
int matrixRow( int theDestRow );
|
||||||
int matrixCol ( int theDestCol );
|
int matrixCol( int theDestCol );
|
||||||
|
|
||||||
/** \brief get destination point for _current_ matrix position */
|
/** \brief get destination point for _current_ matrix position */
|
||||||
QgsPoint srcPoint ( int theRow, int theCol );
|
QgsPoint srcPoint( int theRow, int theCol );
|
||||||
|
|
||||||
/** \brief Get source row and column indexes for current source extent and resolution */
|
/** \brief Get source row and column indexes for current source extent and resolution */
|
||||||
void srcRowCol ( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
|
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
|
||||||
|
|
||||||
/** \brief insert rows to matrix */
|
/** \brief insert rows to matrix */
|
||||||
void insertRows();
|
void insertRows();
|
||||||
@ -78,7 +78,7 @@ class QgsRasterProjector
|
|||||||
void insertCols();
|
void insertCols();
|
||||||
|
|
||||||
/* calculate single control point in current matrix */
|
/* calculate single control point in current matrix */
|
||||||
void calcCP ( int theRow, int theCol );
|
void calcCP( int theRow, int theCol );
|
||||||
|
|
||||||
/** \brief calculate matrix row */
|
/** \brief calculate matrix row */
|
||||||
bool calcRow( int theRow );
|
bool calcRow( int theRow );
|
||||||
@ -90,25 +90,25 @@ class QgsRasterProjector
|
|||||||
void calcSrcExtent();
|
void calcSrcExtent();
|
||||||
|
|
||||||
/** \brief calculate minimum source width and height */
|
/** \brief calculate minimum source width and height */
|
||||||
void calcSrcRowsCols ();
|
void calcSrcRowsCols();
|
||||||
|
|
||||||
/** \brief check error along columns
|
/** \brief check error along columns
|
||||||
* returns true if within threshold */
|
* returns true if within threshold */
|
||||||
bool checkCols ();
|
bool checkCols();
|
||||||
|
|
||||||
/** \brief check error along rows
|
/** \brief check error along rows
|
||||||
* returns true if within threshold */
|
* returns true if within threshold */
|
||||||
bool checkRows ();
|
bool checkRows();
|
||||||
|
|
||||||
/** Calculate array of src helper points */
|
/** Calculate array of src helper points */
|
||||||
//void calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints );
|
//void calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints );
|
||||||
void calcHelper ( int theMatrixRow, QgsPoint *thePoints );
|
void calcHelper( int theMatrixRow, QgsPoint *thePoints );
|
||||||
|
|
||||||
/** Calc / switch helper */
|
/** Calc / switch helper */
|
||||||
void nextHelper();
|
void nextHelper();
|
||||||
|
|
||||||
/** get source extent */
|
/** get source extent */
|
||||||
QgsRectangle srcExtent() { return mSrcExtent; }
|
QgsRectangle srcExtent() { return mSrcExtent; }
|
||||||
|
|
||||||
/** get/set source width/height */
|
/** get/set source width/height */
|
||||||
int srcRows() { return mSrcRows; }
|
int srcRows() { return mSrcRows; }
|
||||||
|
@ -6,7 +6,7 @@ copyright : (C) 2003 by Tim Sutton, Steve Halasz and Gary E.Sherman
|
|||||||
email : tim at linfiniti.com
|
email : tim at linfiniti.com
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
/* **************************************************************************
|
/***************************************************************************
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* 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 *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -96,7 +96,7 @@ QgsRasterLayer::QgsRasterLayer(
|
|||||||
, mHeight( std::numeric_limits<int>::max() )
|
, mHeight( std::numeric_limits<int>::max() )
|
||||||
, mInvertColor( false )
|
, mInvertColor( false )
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Entered");
|
QgsDebugMsg( "Entered" );
|
||||||
|
|
||||||
// TODO, call constructor with provider key for now
|
// TODO, call constructor with provider key for now
|
||||||
init();
|
init();
|
||||||
@ -136,7 +136,7 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
|
|||||||
init();
|
init();
|
||||||
// if we're given a provider type, try to create and bind one to this layer
|
// if we're given a provider type, try to create and bind one to this layer
|
||||||
bool loadDefaultStyleFlag = false ; // ???
|
bool loadDefaultStyleFlag = false ; // ???
|
||||||
setDataProvider( providerKey, layers, styles, format, crs, loadDefaultStyleFlag);
|
setDataProvider( providerKey, layers, styles, format, crs, loadDefaultStyleFlag );
|
||||||
|
|
||||||
// Default for the popup menu
|
// Default for the popup menu
|
||||||
// TODO: popMenu = 0;
|
// TODO: popMenu = 0;
|
||||||
@ -178,7 +178,7 @@ QgsRasterLayer::~QgsRasterLayer()
|
|||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
/**
|
/**
|
||||||
Builds the list of file filter strings to later be used by
|
Builds the list of file filter strings to later be used by
|
||||||
QgisApp::addRasterLayer()
|
QgisApp::addRasterLayer()
|
||||||
We query GDAL for a list of supported raster formats; we then build
|
We query GDAL for a list of supported raster formats; we then build
|
||||||
a list of file filter strings from that list. We return a string
|
a list of file filter strings from that list. We return a string
|
||||||
that contains this list that is suitable for use in a
|
that contains this list that is suitable for use in a
|
||||||
@ -188,17 +188,18 @@ void QgsRasterLayer::buildSupportedRasterFileFilter( QString & theFileFiltersStr
|
|||||||
{
|
{
|
||||||
QgsDebugMsg( "Entered" );
|
QgsDebugMsg( "Entered" );
|
||||||
QLibrary* myLib = QgsRasterLayer::loadProviderLibrary( "gdal" );
|
QLibrary* myLib = QgsRasterLayer::loadProviderLibrary( "gdal" );
|
||||||
if ( !myLib )
|
if ( !myLib )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Could not load gdal provider library" );
|
QgsDebugMsg( "Could not load gdal provider library" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
buildsupportedrasterfilefilter_t *pBuild = ( buildsupportedrasterfilefilter_t * ) cast_to_fptr( myLib->resolve( "buildSupportedRasterFileFilter" ) );
|
buildsupportedrasterfilefilter_t *pBuild = ( buildsupportedrasterfilefilter_t * ) cast_to_fptr( myLib->resolve( "buildSupportedRasterFileFilter" ) );
|
||||||
if ( ! pBuild ) {
|
if ( ! pBuild )
|
||||||
QgsDebugMsg( "Could not resolve buildSupportedRasterFileFilter in gdal provider library");
|
{
|
||||||
|
QgsDebugMsg( "Could not resolve buildSupportedRasterFileFilter in gdal provider library" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuild( theFileFiltersString );
|
pBuild( theFileFiltersString );
|
||||||
delete myLib;
|
delete myLib;
|
||||||
}
|
}
|
||||||
@ -208,20 +209,21 @@ void QgsRasterLayer::buildSupportedRasterFileFilter( QString & theFileFiltersStr
|
|||||||
*/
|
*/
|
||||||
bool QgsRasterLayer::isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg )
|
bool QgsRasterLayer::isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg )
|
||||||
{
|
{
|
||||||
|
|
||||||
QLibrary* myLib = QgsRasterLayer::loadProviderLibrary( "gdal");
|
QLibrary* myLib = QgsRasterLayer::loadProviderLibrary( "gdal" );
|
||||||
if ( !myLib )
|
if ( !myLib )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Could not load gdal provider library" );
|
QgsDebugMsg( "Could not load gdal provider library" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
isvalidrasterfilename_t *pValid = ( isvalidrasterfilename_t * ) cast_to_fptr( myLib->resolve( "isValidRasterFileName" ) );
|
isvalidrasterfilename_t *pValid = ( isvalidrasterfilename_t * ) cast_to_fptr( myLib->resolve( "isValidRasterFileName" ) );
|
||||||
if ( ! pValid ) {
|
if ( ! pValid )
|
||||||
QgsDebugMsg( "Could not resolve isValidRasterFileName in gdal provider library");
|
{
|
||||||
|
QgsDebugMsg( "Could not resolve isValidRasterFileName in gdal provider library" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool myIsValid = pValid( theFileNameQString, retErrMsg );
|
bool myIsValid = pValid( theFileNameQString, retErrMsg );
|
||||||
delete myLib;
|
delete myLib;
|
||||||
return myIsValid;
|
return myIsValid;
|
||||||
}
|
}
|
||||||
@ -267,7 +269,7 @@ const QString QgsRasterLayer::bandName( int theBandNo )
|
|||||||
{
|
{
|
||||||
if ( theBandNo <= mRasterStatsList.size() && theBandNo > 0 )
|
if ( theBandNo <= mRasterStatsList.size() && theBandNo > 0 )
|
||||||
{
|
{
|
||||||
//vector starts at base 0, band counts at base1 !
|
//vector starts at base 0, band counts at base1!
|
||||||
return mRasterStatsList[theBandNo - 1].bandName;
|
return mRasterStatsList[theBandNo - 1].bandName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -319,8 +321,8 @@ int QgsRasterLayer::bandNumber( QString const & theBandName )
|
|||||||
*/
|
*/
|
||||||
const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo )
|
const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "theBandNo = " + QString::number(theBandNo) );
|
QgsDebugMsg( "theBandNo = " + QString::number( theBandNo ) );
|
||||||
QgsDebugMsg( "mRasterType = " + QString::number(mRasterType) );
|
QgsDebugMsg( "mRasterType = " + QString::number( mRasterType ) );
|
||||||
if ( mRasterType == ColorLayer )
|
if ( mRasterType == ColorLayer )
|
||||||
{
|
{
|
||||||
// Statistics have no sense for ColorLayer
|
// Statistics have no sense for ColorLayer
|
||||||
@ -369,7 +371,7 @@ const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo )
|
|||||||
//reset the main app progress bar
|
//reset the main app progress bar
|
||||||
emit drawingProgress( 0, 0 );
|
emit drawingProgress( 0, 0 );
|
||||||
|
|
||||||
int myDataType = mDataProvider->dataType ( theBandNo );
|
int myDataType = mDataProvider->dataType( theBandNo );
|
||||||
|
|
||||||
int myNXBlocks, myNYBlocks, myXBlockSize, myYBlockSize;
|
int myNXBlocks, myNYBlocks, myXBlockSize, myYBlockSize;
|
||||||
myXBlockSize = mDataProvider->xBlockSize();
|
myXBlockSize = mDataProvider->xBlockSize();
|
||||||
@ -378,7 +380,7 @@ const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo )
|
|||||||
myNXBlocks = ( mDataProvider->xSize() + myXBlockSize - 1 ) / myXBlockSize;
|
myNXBlocks = ( mDataProvider->xSize() + myXBlockSize - 1 ) / myXBlockSize;
|
||||||
myNYBlocks = ( mDataProvider->ySize() + myYBlockSize - 1 ) / myYBlockSize;
|
myNYBlocks = ( mDataProvider->ySize() + myYBlockSize - 1 ) / myYBlockSize;
|
||||||
|
|
||||||
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( mDataProvider->dataTypeSize(theBandNo ) / 8 ) );
|
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( mDataProvider->dataTypeSize( theBandNo ) / 8 ) );
|
||||||
|
|
||||||
// unfortunately we need to make two passes through the data to calculate stddev
|
// unfortunately we need to make two passes through the data to calculate stddev
|
||||||
bool myFirstIterationFlag = true;
|
bool myFirstIterationFlag = true;
|
||||||
@ -544,7 +546,7 @@ const QgsRasterBandStats QgsRasterLayer::bandStatistics( QString const & theBand
|
|||||||
QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyramidList,
|
QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyramidList,
|
||||||
QString const & theResamplingMethod, bool theTryInternalFlag )
|
QString const & theResamplingMethod, bool theTryInternalFlag )
|
||||||
{
|
{
|
||||||
return mDataProvider->buildPyramids( theRasterPyramidList, theResamplingMethod, theTryInternalFlag );
|
return mDataProvider->buildPyramids( theRasterPyramidList, theResamplingMethod, theTryInternalFlag );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -586,8 +588,8 @@ void QgsRasterLayer::computeMinimumMaximumEstimates( int theBand, double* theMin
|
|||||||
|
|
||||||
if ( 0 < theBand && theBand <= ( int ) bandCount() )
|
if ( 0 < theBand && theBand <= ( int ) bandCount() )
|
||||||
{
|
{
|
||||||
theMinMax[0] = mDataProvider->minimumValue(theBand);
|
theMinMax[0] = mDataProvider->minimumValue( theBand );
|
||||||
theMinMax[1] = mDataProvider->maximumValue(theBand);
|
theMinMax[1] = mDataProvider->maximumValue( theBand );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,17 +770,17 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
|
|||||||
|
|
||||||
const QgsMapToPixel& theQgsMapToPixel = rendererContext.mapToPixel();
|
const QgsMapToPixel& theQgsMapToPixel = rendererContext.mapToPixel();
|
||||||
const QgsRectangle& theViewExtent = rendererContext.extent();
|
const QgsRectangle& theViewExtent = rendererContext.extent();
|
||||||
|
|
||||||
QgsRectangle myProjectedViewExtent;
|
QgsRectangle myProjectedViewExtent;
|
||||||
QgsRectangle myProjectedLayerExtent;
|
QgsRectangle myProjectedLayerExtent;
|
||||||
|
|
||||||
if ( rendererContext.coordinateTransform() )
|
if ( rendererContext.coordinateTransform() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "coordinateTransform set -> project extents." );
|
QgsDebugMsg( "coordinateTransform set -> project extents." );
|
||||||
myProjectedViewExtent = rendererContext.coordinateTransform()->transformBoundingBox (
|
myProjectedViewExtent = rendererContext.coordinateTransform()->transformBoundingBox(
|
||||||
rendererContext.extent() );
|
rendererContext.extent() );
|
||||||
myProjectedLayerExtent = rendererContext.coordinateTransform()->transformBoundingBox (
|
myProjectedLayerExtent = rendererContext.coordinateTransform()->transformBoundingBox(
|
||||||
mLayerExtent );
|
mLayerExtent );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -819,11 +821,13 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
|
|||||||
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
|
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
|
||||||
|
|
||||||
myRasterViewPort->mDrawnExtent = myRasterExtent;
|
myRasterViewPort->mDrawnExtent = myRasterExtent;
|
||||||
if ( rendererContext.coordinateTransform() )
|
if ( rendererContext.coordinateTransform() )
|
||||||
{
|
{
|
||||||
myRasterViewPort->mSrcCRS = crs();
|
myRasterViewPort->mSrcCRS = crs();
|
||||||
myRasterViewPort->mDestCRS = rendererContext.coordinateTransform()->destCRS();
|
myRasterViewPort->mDestCRS = rendererContext.coordinateTransform()->destCRS();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
||||||
myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
||||||
}
|
}
|
||||||
@ -835,38 +839,39 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
|
|||||||
// align to output device grid, i.e. floor/ceil to integers
|
// align to output device grid, i.e. floor/ceil to integers
|
||||||
// TODO: this should only be done if paint device is raster - screen, image
|
// TODO: this should only be done if paint device is raster - screen, image
|
||||||
// for other devices (pdf) it can have floating point origin
|
// for other devices (pdf) it can have floating point origin
|
||||||
// we could use floating point for raster devices as well, but respecting the
|
// we could use floating point for raster devices as well, but respecting the
|
||||||
// output device grid should make it more effective as the resampling is done in
|
// output device grid should make it more effective as the resampling is done in
|
||||||
// the provider anyway
|
// the provider anyway
|
||||||
if ( true )
|
if ( true )
|
||||||
{
|
{
|
||||||
myRasterViewPort->topLeftPoint.setX( floor( myRasterViewPort->topLeftPoint.x() ) );
|
myRasterViewPort->topLeftPoint.setX( floor( myRasterViewPort->topLeftPoint.x() ) );
|
||||||
myRasterViewPort->topLeftPoint.setY( floor( myRasterViewPort->topLeftPoint.y() ) );
|
myRasterViewPort->topLeftPoint.setY( floor( myRasterViewPort->topLeftPoint.y() ) );
|
||||||
myRasterViewPort->bottomRightPoint.setX( ceil( myRasterViewPort->bottomRightPoint.x() ) );
|
myRasterViewPort->bottomRightPoint.setX( ceil( myRasterViewPort->bottomRightPoint.x() ) );
|
||||||
myRasterViewPort->bottomRightPoint.setY( ceil( myRasterViewPort->bottomRightPoint.y() ) );
|
myRasterViewPort->bottomRightPoint.setY( ceil( myRasterViewPort->bottomRightPoint.y() ) );
|
||||||
// recalc myRasterExtent to aligned values
|
// recalc myRasterExtent to aligned values
|
||||||
myRasterExtent.set (
|
myRasterExtent.set(
|
||||||
theQgsMapToPixel.toMapCoordinatesF ( myRasterViewPort->topLeftPoint.x(),
|
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->topLeftPoint.x(),
|
||||||
myRasterViewPort->bottomRightPoint.y() ),
|
myRasterViewPort->bottomRightPoint.y() ),
|
||||||
theQgsMapToPixel.toMapCoordinatesF ( myRasterViewPort->bottomRightPoint.x(),
|
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->bottomRightPoint.x(),
|
||||||
myRasterViewPort->topLeftPoint.y() )
|
myRasterViewPort->topLeftPoint.y() )
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ));
|
myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
|
||||||
myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ));
|
myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
|
||||||
|
|
||||||
//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
|
//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
|
||||||
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,
|
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,
|
||||||
//so we will just get the pixel data and then render these special cases differently in paintImageToCanvas()
|
//so we will just get the pixel data and then render these special cases differently in paintImageToCanvas()
|
||||||
/*
|
#if 0
|
||||||
if ( 2 >= myRasterViewPort->clippedWidth && 2 >= myRasterViewPort->clippedHeight )
|
if ( 2 >= myRasterViewPort->clippedWidth && 2 >= myRasterViewPort->clippedHeight )
|
||||||
{
|
{
|
||||||
myRasterViewPort->drawableAreaXDim = myRasterViewPort->clippedWidth;
|
myRasterViewPort->drawableAreaXDim = myRasterViewPort->clippedWidth;
|
||||||
myRasterViewPort->drawableAreaYDim = myRasterViewPort->clippedHeight;
|
myRasterViewPort->drawableAreaYDim = myRasterViewPort->clippedHeight;
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
QgsDebugMsgLevel( QString( "mapUnitsPerPixel = %1" ).arg( theQgsMapToPixel.mapUnitsPerPixel() ), 3 );
|
QgsDebugMsgLevel( QString( "mapUnitsPerPixel = %1" ).arg( theQgsMapToPixel.mapUnitsPerPixel() ), 3 );
|
||||||
QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( mWidth ), 3 );
|
QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( mWidth ), 3 );
|
||||||
QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( mHeight ), 3 );
|
QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( mHeight ), 3 );
|
||||||
@ -882,7 +887,7 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
|
|||||||
|
|
||||||
QgsDebugMsgLevel( QString( "drawableAreaXDim = %1" ).arg( myRasterViewPort->drawableAreaXDim ), 3 );
|
QgsDebugMsgLevel( QString( "drawableAreaXDim = %1" ).arg( myRasterViewPort->drawableAreaXDim ), 3 );
|
||||||
QgsDebugMsgLevel( QString( "drawableAreaYDim = %1" ).arg( myRasterViewPort->drawableAreaYDim ), 3 );
|
QgsDebugMsgLevel( QString( "drawableAreaYDim = %1" ).arg( myRasterViewPort->drawableAreaYDim ), 3 );
|
||||||
|
|
||||||
QgsDebugMsgLevel( "ReadXml: gray band name : " + mGrayBandName, 3 );
|
QgsDebugMsgLevel( "ReadXml: gray band name : " + mGrayBandName, 3 );
|
||||||
QgsDebugMsgLevel( "ReadXml: red band name : " + mRedBandName, 3 );
|
QgsDebugMsgLevel( "ReadXml: red band name : " + mRedBandName, 3 );
|
||||||
QgsDebugMsgLevel( "ReadXml: green band name : " + mGreenBandName, 3 );
|
QgsDebugMsgLevel( "ReadXml: green band name : " + mGreenBandName, 3 );
|
||||||
@ -917,7 +922,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
|
|||||||
// procedure to use :
|
// procedure to use :
|
||||||
//
|
//
|
||||||
|
|
||||||
QgsDebugMsg( "mDrawingStyle = " + QString::number(mDrawingStyle) );
|
QgsDebugMsg( "mDrawingStyle = " + QString::number( mDrawingStyle ) );
|
||||||
switch ( mDrawingStyle )
|
switch ( mDrawingStyle )
|
||||||
{
|
{
|
||||||
// a "Gray" or "Undefined" layer drawn as a range of gray colors
|
// a "Gray" or "Undefined" layer drawn as a range of gray colors
|
||||||
@ -1055,7 +1060,7 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
drawSingleBandColorData( theQPainter, theRasterViewPort,
|
drawSingleBandColorData( theQPainter, theRasterViewPort,
|
||||||
theQgsMapToPixel, bandNumber( mGrayBandName ) );
|
theQgsMapToPixel, bandNumber( mGrayBandName ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1109,7 +1114,7 @@ QString QgsRasterLayer::drawingStyleAsString() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @note Note implemented yet
|
* @note Not implemented yet
|
||||||
* @return always returns false
|
* @return always returns false
|
||||||
*/
|
*/
|
||||||
bool QgsRasterLayer::hasCompatibleSymbology( const QgsMapLayer& theOther ) const
|
bool QgsRasterLayer::hasCompatibleSymbology( const QgsMapLayer& theOther ) const
|
||||||
@ -1130,7 +1135,7 @@ bool QgsRasterLayer::hasStatistics( int theBandNo )
|
|||||||
{
|
{
|
||||||
if ( theBandNo <= mRasterStatsList.size() && theBandNo > 0 )
|
if ( theBandNo <= mRasterStatsList.size() && theBandNo > 0 )
|
||||||
{
|
{
|
||||||
//vector starts at base 0, band counts at base1 !
|
//vector starts at base 0, band counts at base1!
|
||||||
return mRasterStatsList[theBandNo - 1].statsGathered;
|
return mRasterStatsList[theBandNo - 1].statsGathered;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1150,7 +1155,7 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&
|
|||||||
|
|
||||||
QgsDebugMsg( "identify provider : " + mProviderKey ) ;
|
QgsDebugMsg( "identify provider : " + mProviderKey ) ;
|
||||||
return ( mDataProvider->identify( thePoint, theResults ) );
|
return ( mDataProvider->identify( thePoint, theResults ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0
|
* @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0
|
||||||
@ -1249,7 +1254,7 @@ QPixmap QgsRasterLayer::legendAsPixmap( bool theWithNameFlag )
|
|||||||
//
|
//
|
||||||
// Get the adjusted matrix stats
|
// Get the adjusted matrix stats
|
||||||
//
|
//
|
||||||
QString myColorerpretation = mDataProvider->colorInterpretationName ( 1 );
|
QString myColorerpretation = mDataProvider->colorInterpretationName( 1 );
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create the legend pixmap - note it is generated on the preadjusted stats
|
// Create the legend pixmap - note it is generated on the preadjusted stats
|
||||||
@ -1502,7 +1507,7 @@ QPixmap QgsRasterLayer::legendAsPixmap( int theLabelCount )
|
|||||||
//
|
//
|
||||||
// Get the adjusted matrix stats
|
// Get the adjusted matrix stats
|
||||||
//
|
//
|
||||||
QString myColorerpretation = mDataProvider->colorInterpretationName ( 1 );
|
QString myColorerpretation = mDataProvider->colorInterpretationName( 1 );
|
||||||
QPixmap myLegendQPixmap; //will be initialised once we know what drawing style is active
|
QPixmap myLegendQPixmap; //will be initialised once we know what drawing style is active
|
||||||
QPainter myQPainter;
|
QPainter myQPainter;
|
||||||
//
|
//
|
||||||
@ -1995,7 +2000,7 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber )
|
|||||||
//QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = myShader.colorRampItemList();
|
//QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = myShader.colorRampItemList();
|
||||||
|
|
||||||
//if ( readColorTable( 1, &myColorRampItemList ) )
|
//if ( readColorTable( 1, &myColorRampItemList ) )
|
||||||
QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->colorTable ( 1 );
|
QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->colorTable( 1 );
|
||||||
// TODO: add CT capability? It can depends on band (?)
|
// TODO: add CT capability? It can depends on band (?)
|
||||||
if ( myColorRampItemList.size() > 0 )
|
if ( myColorRampItemList.size() > 0 )
|
||||||
{
|
{
|
||||||
@ -2047,7 +2052,7 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber )
|
|||||||
*/
|
*/
|
||||||
void QgsRasterLayer::populateHistogram( int theBandNo, int theBinCount, bool theIgnoreOutOfRangeFlag, bool theHistogramEstimatedFlag )
|
void QgsRasterLayer::populateHistogram( int theBandNo, int theBinCount, bool theIgnoreOutOfRangeFlag, bool theHistogramEstimatedFlag )
|
||||||
{
|
{
|
||||||
QgsRasterBandStats myRasterBandStats = bandStatistics( theBandNo );
|
QgsRasterBandStats myRasterBandStats = bandStatistics( theBandNo );
|
||||||
mDataProvider->populateHistogram( theBandNo, myRasterBandStats, theBinCount, theIgnoreOutOfRangeFlag, theHistogramEstimatedFlag );
|
mDataProvider->populateHistogram( theBandNo, myRasterBandStats, theBinCount, theIgnoreOutOfRangeFlag, theHistogramEstimatedFlag );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2089,10 +2094,9 @@ void QgsRasterLayer::resetNoDataValue()
|
|||||||
mValidNoDataValue = false;
|
mValidNoDataValue = false;
|
||||||
if ( mDataProvider != NULL && mDataProvider->bandCount() > 0 )
|
if ( mDataProvider != NULL && mDataProvider->bandCount() > 0 )
|
||||||
{
|
{
|
||||||
int myRequestValid;
|
|
||||||
|
|
||||||
// TODO: add 'has null value' to capabilities
|
// TODO: add 'has null value' to capabilities
|
||||||
/*
|
#if 0
|
||||||
|
int myRequestValid;
|
||||||
myRequestValid = 1;
|
myRequestValid = 1;
|
||||||
double myValue = mDataProvider->noDataValue();
|
double myValue = mDataProvider->noDataValue();
|
||||||
|
|
||||||
@ -2104,11 +2108,11 @@ void QgsRasterLayer::resetNoDataValue()
|
|||||||
{
|
{
|
||||||
setNoDataValue( -9999.0 );
|
setNoDataValue( -9999.0 );
|
||||||
mValidNoDataValue = false;
|
mValidNoDataValue = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
setNoDataValue ( mDataProvider->noDataValue() );
|
setNoDataValue( mDataProvider->noDataValue() );
|
||||||
mValidNoDataValue = mDataProvider->isNoDataValueValid();
|
mValidNoDataValue = mDataProvider->isNoDataValueValid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2120,7 +2124,7 @@ void QgsRasterLayer::setBlueBandName( QString const & theBandName )
|
|||||||
|
|
||||||
void QgsRasterLayer::init()
|
void QgsRasterLayer::init()
|
||||||
{
|
{
|
||||||
// keep this until mGeoTransform occurences are removed !
|
// keep this until mGeoTransform occurences are removed!
|
||||||
mGeoTransform[0] = 0;
|
mGeoTransform[0] = 0;
|
||||||
mGeoTransform[1] = 1;
|
mGeoTransform[1] = 1;
|
||||||
mGeoTransform[2] = 0;
|
mGeoTransform[2] = 0;
|
||||||
@ -2158,7 +2162,7 @@ void QgsRasterLayer::init()
|
|||||||
mLastViewPort.drawableAreaYDim = 0;
|
mLastViewPort.drawableAreaYDim = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLibrary* QgsRasterLayer::loadProviderLibrary( QString theProviderKey )
|
QLibrary* QgsRasterLayer::loadProviderLibrary( QString theProviderKey )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "theProviderKey = " + theProviderKey );
|
QgsDebugMsg( "theProviderKey = " + theProviderKey );
|
||||||
// load the plugin
|
// load the plugin
|
||||||
@ -2185,7 +2189,7 @@ QLibrary* QgsRasterLayer::loadProviderLibrary( QString theProviderKey )
|
|||||||
|
|
||||||
// load the data provider
|
// load the data provider
|
||||||
QLibrary* myLib = new QLibrary( myLibPath );
|
QLibrary* myLib = new QLibrary( myLibPath );
|
||||||
|
|
||||||
QgsDebugMsg( "Library name is " + myLib->fileName() );
|
QgsDebugMsg( "Library name is " + myLib->fileName() );
|
||||||
bool loaded = myLib->load();
|
bool loaded = myLib->load();
|
||||||
|
|
||||||
@ -2199,7 +2203,7 @@ QLibrary* QgsRasterLayer::loadProviderLibrary( QString theProviderKey )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This code should be shared also by vector layer -> move it to QgsMapLayer
|
// This code should be shared also by vector layer -> move it to QgsMapLayer
|
||||||
QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QString theDataSource )
|
QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QString theDataSource )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Entered" );
|
QgsDebugMsg( "Entered" );
|
||||||
QLibrary* myLib = QgsRasterLayer::loadProviderLibrary( theProviderKey );
|
QLibrary* myLib = QgsRasterLayer::loadProviderLibrary( theProviderKey );
|
||||||
@ -2215,8 +2219,8 @@ QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QSt
|
|||||||
|
|
||||||
if ( !classFactory )
|
if ( !classFactory )
|
||||||
{
|
{
|
||||||
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Cannot resolve the classFactory function" );
|
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Cannot resolve the classFactory function" );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
QgsDebugMsg( "Getting pointer to a mDataProvider object from the library" );
|
QgsDebugMsg( "Getting pointer to a mDataProvider object from the library" );
|
||||||
//XXX - This was a dynamic cast but that kills the Windows
|
//XXX - This was a dynamic cast but that kills the Windows
|
||||||
@ -2240,8 +2244,9 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
QStringList const & layers,
|
QStringList const & layers,
|
||||||
QStringList const & styles,
|
QStringList const & styles,
|
||||||
QString const & format,
|
QString const & format,
|
||||||
QString const & crs) {
|
QString const & crs )
|
||||||
setDataProvider ( provider, layers, styles, format, crs, false );
|
{
|
||||||
|
setDataProvider( provider, layers, styles, format, crs, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Copied from QgsVectorLayer::setDataProvider
|
/** Copied from QgsVectorLayer::setDataProvider
|
||||||
@ -2257,7 +2262,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
// XXX should I check for and possibly delete any pre-existing providers?
|
// XXX should I check for and possibly delete any pre-existing providers?
|
||||||
// XXX How often will that scenario occur?
|
// XXX How often will that scenario occur?
|
||||||
|
|
||||||
mProviderKey = provider;
|
mProviderKey = provider;
|
||||||
mValid = false; // assume the layer is invalid until we determine otherwise
|
mValid = false; // assume the layer is invalid until we determine otherwise
|
||||||
|
|
||||||
// set the layer name (uppercase first character)
|
// set the layer name (uppercase first character)
|
||||||
@ -2270,17 +2275,17 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
mBandCount = 0;
|
mBandCount = 0;
|
||||||
mRasterShader = new QgsRasterShader();
|
mRasterShader = new QgsRasterShader();
|
||||||
|
|
||||||
mDataProvider = QgsRasterLayer::loadProvider ( mProviderKey, mDataSource );
|
mDataProvider = QgsRasterLayer::loadProvider( mProviderKey, mDataSource );
|
||||||
if ( !mDataProvider )
|
if ( !mDataProvider )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QgsDebugMsg( "Instantiated the data provider plugin"
|
QgsDebugMsg( "Instantiated the data provider plugin"
|
||||||
+ QString( " with layer list of " ) + layers.join( ", " )
|
+ QString( " with layer list of " ) + layers.join( ", " )
|
||||||
+ " and style list of " + styles.join( ", " )
|
+ " and style list of " + styles.join( ", " )
|
||||||
+ " and format of " + format + " and CRS of " + crs );
|
+ " and format of " + format + " and CRS of " + crs );
|
||||||
if ( ! mDataProvider->isValid() )
|
if ( ! mDataProvider->isValid() )
|
||||||
{
|
{
|
||||||
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Data provider is invalid." );
|
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Data provider is invalid." );
|
||||||
@ -2307,7 +2312,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
|
|
||||||
mWidth = mDataProvider->xSize();
|
mWidth = mDataProvider->xSize();
|
||||||
mHeight = mDataProvider->ySize();
|
mHeight = mDataProvider->ySize();
|
||||||
|
|
||||||
|
|
||||||
// upper case the first letter of the layer name
|
// upper case the first letter of the layer name
|
||||||
QgsDebugMsg( "mLayerName: " + name() );
|
QgsDebugMsg( "mLayerName: " + name() );
|
||||||
@ -2347,7 +2352,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
//Store the default color table
|
//Store the default color table
|
||||||
//readColorTable( i, &myRasterBandStats.colorTable );
|
//readColorTable( i, &myRasterBandStats.colorTable );
|
||||||
QList<QgsColorRampShader::ColorRampItem> ct;
|
QList<QgsColorRampShader::ColorRampItem> ct;
|
||||||
ct = mDataProvider->colorTable(i);
|
ct = mDataProvider->colorTable( i );
|
||||||
myRasterBandStats.colorTable = ct;
|
myRasterBandStats.colorTable = ct;
|
||||||
|
|
||||||
mRasterStatsList.push_back( myRasterBandStats );
|
mRasterStatsList.push_back( myRasterBandStats );
|
||||||
@ -2366,8 +2371,8 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
|
|
||||||
//decide what type of layer this is...
|
//decide what type of layer this is...
|
||||||
//TODO Change this to look at the color interp and palette interp to decide which type of layer it is
|
//TODO Change this to look at the color interp and palette interp to decide which type of layer it is
|
||||||
QgsDebugMsg("bandCount = " + QString::number( mDataProvider->bandCount()));
|
QgsDebugMsg( "bandCount = " + QString::number( mDataProvider->bandCount() ) );
|
||||||
QgsDebugMsg("dataType = " + QString::number( mDataProvider->dataType( 1 )));
|
QgsDebugMsg( "dataType = " + QString::number( mDataProvider->dataType( 1 ) ) );
|
||||||
if (( mDataProvider->bandCount() > 1 ) )
|
if (( mDataProvider->bandCount() > 1 ) )
|
||||||
{
|
{
|
||||||
mRasterType = Multiband;
|
mRasterType = Multiband;
|
||||||
@ -2375,13 +2380,13 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
|
else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
|
||||||
{
|
{
|
||||||
mRasterType = ColorLayer;
|
mRasterType = ColorLayer;
|
||||||
}
|
}
|
||||||
//TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int)
|
//TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int)
|
||||||
//else if ( hasBand( "Palette" ) ) //don't tr() this its a gdal word!
|
//else if ( hasBand( "Palette" ) ) //don't tr() this its a gdal word!
|
||||||
// not sure if is worth to add colorTable capability - CT can be empty in any case
|
// not sure if is worth to add colorTable capability - CT can be empty in any case
|
||||||
// Calc bandStatistics is very slow!!!
|
// Calc bandStatistics is very slow!!!
|
||||||
//else if ( bandStatistics(1).colorTable.count() > 0 )
|
//else if ( bandStatistics(1).colorTable.count() > 0 )
|
||||||
else if ( mDataProvider->colorInterpretation(1) == QgsRasterDataProvider::PaletteIndex )
|
else if ( mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::PaletteIndex )
|
||||||
{
|
{
|
||||||
mRasterType = Palette;
|
mRasterType = Palette;
|
||||||
}
|
}
|
||||||
@ -2390,10 +2395,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
mRasterType = GrayOrUndefined;
|
mRasterType = GrayOrUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDebugMsg("mRasterType = " + QString::number(mRasterType));
|
QgsDebugMsg( "mRasterType = " + QString::number( mRasterType ) );
|
||||||
if ( mRasterType == ColorLayer )
|
if ( mRasterType == ColorLayer )
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number ( SingleBandColorDataStyle ) );
|
QgsDebugMsg( "Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number( SingleBandColorDataStyle ) );
|
||||||
mDrawingStyle = SingleBandColorDataStyle;
|
mDrawingStyle = SingleBandColorDataStyle;
|
||||||
mGrayBandName = bandName( 1 ); //sensible default
|
mGrayBandName = bandName( 1 ); //sensible default
|
||||||
}
|
}
|
||||||
@ -2486,12 +2491,12 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
|
|||||||
// TODO ???
|
// TODO ???
|
||||||
//if ( loadDefaultStyleFlag )
|
//if ( loadDefaultStyleFlag )
|
||||||
//{
|
//{
|
||||||
//bool defaultLoadedFlag = false;
|
//bool defaultLoadedFlag = false;
|
||||||
//loadDefaultStyle( defaultLoadedFlag );
|
//loadDefaultStyle( defaultLoadedFlag );
|
||||||
//if ( defaultLoadedFlag )
|
//if ( defaultLoadedFlag )
|
||||||
//{
|
//{
|
||||||
//return;
|
//return;
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
QgsDebugMsg( "exiting." );
|
QgsDebugMsg( "exiting." );
|
||||||
@ -2648,11 +2653,11 @@ void QgsRasterLayer::setDrawingStyle( QString const & theDrawingStyleQString )
|
|||||||
}
|
}
|
||||||
else if ( theDrawingStyleQString == "SingleBandColorDataStyle" )//no need to tr() this its not shown in ui
|
else if ( theDrawingStyleQString == "SingleBandColorDataStyle" )//no need to tr() this its not shown in ui
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number ( SingleBandColorDataStyle ) );
|
QgsDebugMsg( "Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number( SingleBandColorDataStyle ) );
|
||||||
mDrawingStyle = SingleBandColorDataStyle;
|
mDrawingStyle = SingleBandColorDataStyle;
|
||||||
QgsDebugMsg("Setted mDrawingStyle to " + QString::number ( mDrawingStyle ) );
|
QgsDebugMsg( "Setted mDrawingStyle to " + QString::number( mDrawingStyle ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mDrawingStyle = UndefinedDrawingStyle;
|
mDrawingStyle = UndefinedDrawingStyle;
|
||||||
}
|
}
|
||||||
@ -2682,7 +2687,7 @@ void QgsRasterLayer::setLayerOrder( QStringList const & layers )
|
|||||||
|
|
||||||
void QgsRasterLayer::setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
|
void QgsRasterLayer::setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "setMaximumValue theValue = " + QString::number(theValue) );
|
QgsDebugMsg( "setMaximumValue theValue = " + QString::number( theValue ) );
|
||||||
if ( 0 < theBand && theBand <= bandCount() )
|
if ( 0 < theBand && theBand <= bandCount() )
|
||||||
{
|
{
|
||||||
mContrastEnhancementList[theBand - 1].setMaximumValue( theValue, theGenerateLookupTableFlag );
|
mContrastEnhancementList[theBand - 1].setMaximumValue( theValue, theGenerateLookupTableFlag );
|
||||||
@ -2728,7 +2733,7 @@ void QgsRasterLayer::setMinimumMaximumUsingLastExtent()
|
|||||||
|
|
||||||
void QgsRasterLayer::setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
|
void QgsRasterLayer::setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "setMinimumValue theValue = " + QString::number(theValue) );
|
QgsDebugMsg( "setMinimumValue theValue = " + QString::number( theValue ) );
|
||||||
if ( 0 < theBand && theBand <= bandCount() )
|
if ( 0 < theBand && theBand <= bandCount() )
|
||||||
{
|
{
|
||||||
mContrastEnhancementList[theBand - 1].setMinimumValue( theValue, theGenerateLookupTableFlag );
|
mContrastEnhancementList[theBand - 1].setMinimumValue( theValue, theGenerateLookupTableFlag );
|
||||||
@ -2823,23 +2828,23 @@ void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
|
|||||||
//TODO: This should be depreciated and a new function written that just returns a new QPixmap, it will be safer
|
//TODO: This should be depreciated and a new function written that just returns a new QPixmap, it will be safer
|
||||||
if ( 0 == theQPixmap ) { return; }
|
if ( 0 == theQPixmap ) { return; }
|
||||||
|
|
||||||
theQPixmap->fill ( ); //defaults to white
|
theQPixmap->fill( ); //defaults to white
|
||||||
|
|
||||||
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
|
QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort();
|
||||||
|
|
||||||
double myMapUnitsPerPixel;
|
double myMapUnitsPerPixel;
|
||||||
double myX = 0.0;
|
double myX = 0.0;
|
||||||
double myY = 0.0;
|
double myY = 0.0;
|
||||||
QgsRectangle myExtent = mDataProvider->extent();
|
QgsRectangle myExtent = mDataProvider->extent();
|
||||||
if ( myExtent.width()/myExtent.height() >= theQPixmap->width() / theQPixmap->height() )
|
if ( myExtent.width() / myExtent.height() >= theQPixmap->width() / theQPixmap->height() )
|
||||||
{
|
{
|
||||||
myMapUnitsPerPixel = myExtent.width() / theQPixmap->width();
|
myMapUnitsPerPixel = myExtent.width() / theQPixmap->width();
|
||||||
myY = (theQPixmap->height() - myExtent.height() / myMapUnitsPerPixel ) / 2;
|
myY = ( theQPixmap->height() - myExtent.height() / myMapUnitsPerPixel ) / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myMapUnitsPerPixel = myExtent.height() / theQPixmap->height();
|
myMapUnitsPerPixel = myExtent.height() / theQPixmap->height();
|
||||||
myX = (theQPixmap->width() - myExtent.width() / myMapUnitsPerPixel ) / 2;
|
myX = ( theQPixmap->width() - myExtent.width() / myMapUnitsPerPixel ) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
double myPixelWidth = myExtent.width() / myMapUnitsPerPixel;
|
double myPixelWidth = myExtent.width() / myMapUnitsPerPixel;
|
||||||
@ -2849,7 +2854,7 @@ void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
|
|||||||
myRasterViewPort->topLeftPoint = QgsPoint( myX, myY );
|
myRasterViewPort->topLeftPoint = QgsPoint( myX, myY );
|
||||||
|
|
||||||
//myRasterViewPort->bottomRightPoint = QgsPoint( theQPixmap->width(), theQPixmap->height() );
|
//myRasterViewPort->bottomRightPoint = QgsPoint( theQPixmap->width(), theQPixmap->height() );
|
||||||
|
|
||||||
myRasterViewPort->bottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
|
myRasterViewPort->bottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
|
||||||
myRasterViewPort->drawableAreaXDim = theQPixmap->width();
|
myRasterViewPort->drawableAreaXDim = theQPixmap->width();
|
||||||
myRasterViewPort->drawableAreaYDim = theQPixmap->height();
|
myRasterViewPort->drawableAreaYDim = theQPixmap->height();
|
||||||
@ -2860,7 +2865,7 @@ void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
|
|||||||
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
||||||
myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
myRasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
|
||||||
|
|
||||||
QgsMapToPixel *myMapToPixel = new QgsMapToPixel( myMapUnitsPerPixel);
|
QgsMapToPixel *myMapToPixel = new QgsMapToPixel( myMapUnitsPerPixel );
|
||||||
|
|
||||||
QPainter * myQPainter = new QPainter( theQPixmap );
|
QPainter * myQPainter = new QPainter( theQPixmap );
|
||||||
draw( myQPainter, myRasterViewPort, myMapToPixel );
|
draw( myQPainter, myRasterViewPort, myMapToPixel );
|
||||||
@ -3181,9 +3186,7 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
|
|||||||
QString format = rpNode.namedItem( "wmsFormat" ).toElement().text();
|
QString format = rpNode.namedItem( "wmsFormat" ).toElement().text();
|
||||||
|
|
||||||
// Collect CRS
|
// Collect CRS
|
||||||
QString crs = srs().authid();
|
setDataProvider( mProviderKey, layers, styles, format, crs().authid() );
|
||||||
|
|
||||||
setDataProvider( mProviderKey, layers, styles, format, crs );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3654,14 +3657,14 @@ void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPo
|
|||||||
//from calling generate raster band stats
|
//from calling generate raster band stats
|
||||||
mRGBMinimumMaximumEstimated = true;
|
mRGBMinimumMaximumEstimated = true;
|
||||||
|
|
||||||
setMinimumValue( myRedBandNo, mDataProvider->minimumValue ( myRedBandNo ) );
|
setMinimumValue( myRedBandNo, mDataProvider->minimumValue( myRedBandNo ) );
|
||||||
setMaximumValue( myRedBandNo, mDataProvider->maximumValue ( myRedBandNo ) );
|
setMaximumValue( myRedBandNo, mDataProvider->maximumValue( myRedBandNo ) );
|
||||||
|
|
||||||
setMinimumValue( myGreenBandNo, mDataProvider->minimumValue ( myGreenBandNo ) );
|
setMinimumValue( myGreenBandNo, mDataProvider->minimumValue( myGreenBandNo ) );
|
||||||
setMaximumValue( myGreenBandNo, mDataProvider->maximumValue ( myGreenBandNo ) );
|
setMaximumValue( myGreenBandNo, mDataProvider->maximumValue( myGreenBandNo ) );
|
||||||
|
|
||||||
setMinimumValue( myBlueBandNo, mDataProvider->minimumValue ( myBlueBandNo ) );
|
setMinimumValue( myBlueBandNo, mDataProvider->minimumValue( myBlueBandNo ) );
|
||||||
setMaximumValue( myBlueBandNo, mDataProvider->maximumValue ( myBlueBandNo ) );
|
setMaximumValue( myBlueBandNo, mDataProvider->maximumValue( myBlueBandNo ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
//Read and display pixels
|
//Read and display pixels
|
||||||
@ -3840,7 +3843,7 @@ void QgsRasterLayer::drawPalettedSingleBandColor( QPainter * theQPainter, QgsRas
|
|||||||
* @param theRasterViewPort pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
|
* @param theRasterViewPort pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
|
||||||
* @param theQgsMapToPixel transformation between map coordinates and canvas pixels
|
* @param theQgsMapToPixel transformation between map coordinates and canvas pixels
|
||||||
* @param theBandNo band number
|
* @param theBandNo band number
|
||||||
*/
|
*/
|
||||||
void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
|
void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
|
||||||
const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
|
const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
|
||||||
{
|
{
|
||||||
@ -3924,7 +3927,6 @@ void QgsRasterLayer::drawPalettedSingleBandGray( QPainter * theQPainter, QgsRast
|
|||||||
* @param theBandNo band number
|
* @param theBandNo band number
|
||||||
gray.
|
gray.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
|
void QgsRasterLayer::drawPalettedSingleBandPseudoColor( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
|
||||||
const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
|
const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
|
||||||
{
|
{
|
||||||
@ -4034,7 +4036,7 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
|
|||||||
}
|
}
|
||||||
|
|
||||||
int myDataType = mDataProvider->dataType( theBandNo );
|
int myDataType = mDataProvider->dataType( theBandNo );
|
||||||
QgsDebugMsg( "myDataType = " + QString::number( myDataType) );
|
QgsDebugMsg( "myDataType = " + QString::number( myDataType ) );
|
||||||
QgsRasterImageBuffer imageBuffer( mDataProvider, theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform[0] );
|
QgsRasterImageBuffer imageBuffer( mDataProvider, theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform[0] );
|
||||||
imageBuffer.reset();
|
imageBuffer.reset();
|
||||||
|
|
||||||
@ -4061,12 +4063,12 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
|
|||||||
//This case will be true the first time the image is loaded, so just approimate the min max to keep
|
//This case will be true the first time the image is loaded, so just approimate the min max to keep
|
||||||
//from calling generate raster band stats
|
//from calling generate raster band stats
|
||||||
mGrayMinimumMaximumEstimated = true;
|
mGrayMinimumMaximumEstimated = true;
|
||||||
setMaximumValue( theBandNo, mDataProvider->maximumValue ( theBandNo ) );
|
setMaximumValue( theBandNo, mDataProvider->maximumValue( theBandNo ) );
|
||||||
setMinimumValue( theBandNo, mDataProvider->minimumValue ( theBandNo ) );
|
setMinimumValue( theBandNo, mDataProvider->minimumValue( theBandNo ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDebugMsg( " -> imageBuffer.nextScanLine");
|
QgsDebugMsg( " -> imageBuffer.nextScanLine" );
|
||||||
while ( imageBuffer.nextScanLine( &imageScanLine, &rasterScanLine ) )
|
while ( imageBuffer.nextScanLine( &imageScanLine, &rasterScanLine ) )
|
||||||
{
|
{
|
||||||
//QgsDebugMsg( " rendering line");
|
//QgsDebugMsg( " rendering line");
|
||||||
@ -4075,7 +4077,7 @@ void QgsRasterLayer::drawSingleBandGray( QPainter * theQPainter, QgsRasterViewPo
|
|||||||
myGrayValue = readValue( rasterScanLine, myDataType, i );
|
myGrayValue = readValue( rasterScanLine, myDataType, i );
|
||||||
//QgsDebugMsg( QString( "i = %1 myGrayValue = %2 ").arg(i).arg( myGrayValue ) );
|
//QgsDebugMsg( QString( "i = %1 myGrayValue = %2 ").arg(i).arg( myGrayValue ) );
|
||||||
//if ( myGrayValue != -2147483647 ) {
|
//if ( myGrayValue != -2147483647 ) {
|
||||||
//QgsDebugMsg( "myGrayValue = " + QString::number( myGrayValue ) );
|
//QgsDebugMsg( "myGrayValue = " + QString::number( myGrayValue ) );
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if ( mValidNoDataValue && ( qAbs( myGrayValue - mNoDataValue ) <= TINY_VALUE || myGrayValue != myGrayValue ) )
|
if ( mValidNoDataValue && ( qAbs( myGrayValue - mNoDataValue ) <= TINY_VALUE || myGrayValue != myGrayValue ) )
|
||||||
@ -4202,10 +4204,12 @@ void QgsRasterLayer::drawSingleBandPseudoColor( QPainter * theQPainter,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//QString QgsRasterLayer::generateBandName( int theBandNumber )
|
#if 0
|
||||||
//{
|
QString QgsRasterLayer::generateBandName( int theBandNumber )
|
||||||
//return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
|
{
|
||||||
//}
|
return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method looks to see if a given band name exists.
|
* This method looks to see if a given band name exists.
|
||||||
@ -4218,7 +4222,7 @@ bool QgsRasterLayer::hasBand( QString const & theBandName )
|
|||||||
|
|
||||||
for ( int i = 1; i <= mDataProvider->bandCount(); i++ )
|
for ( int i = 1; i <= mDataProvider->bandCount(); i++ )
|
||||||
{
|
{
|
||||||
QString myColorQString = mDataProvider->colorInterpretationName ( i );
|
QString myColorQString = mDataProvider->colorInterpretationName( i );
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
QgsLogger::debug( "band", i, __FILE__, __FUNCTION__, __LINE__, 2 );
|
QgsLogger::debug( "band", i, __FILE__, __FUNCTION__, __LINE__, 2 );
|
||||||
#endif
|
#endif
|
||||||
@ -4249,9 +4253,9 @@ QString QgsRasterLayer::projectionWkt()
|
|||||||
*/
|
*/
|
||||||
void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort )
|
void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort )
|
||||||
{
|
{
|
||||||
int size = mDataProvider->dataTypeSize(bandNo)/8;
|
int size = mDataProvider->dataTypeSize( bandNo ) / 8;
|
||||||
|
|
||||||
/*
|
#if 0
|
||||||
QgsDebugMsg( "calling RasterIO with " +
|
QgsDebugMsg( "calling RasterIO with " +
|
||||||
QString( ", source NW corner: " ) + QString::number( viewPort->rectXOffset ) +
|
QString( ", source NW corner: " ) + QString::number( viewPort->rectXOffset ) +
|
||||||
", " + QString::number( viewPort->rectYOffset ) +
|
", " + QString::number( viewPort->rectYOffset ) +
|
||||||
@ -4259,7 +4263,7 @@ void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort )
|
|||||||
", " + QString::number( viewPort->clippedHeight ) +
|
", " + QString::number( viewPort->clippedHeight ) +
|
||||||
", dest size: " + QString::number( viewPort->drawableAreaXDim ) +
|
", dest size: " + QString::number( viewPort->drawableAreaXDim ) +
|
||||||
", " + QString::number( viewPort->drawableAreaYDim ) );
|
", " + QString::number( viewPort->drawableAreaYDim ) );
|
||||||
*/
|
#endif
|
||||||
void *data = VSIMalloc( size * viewPort->drawableAreaXDim * viewPort->drawableAreaYDim );
|
void *data = VSIMalloc( size * viewPort->drawableAreaXDim * viewPort->drawableAreaYDim );
|
||||||
|
|
||||||
/* Abort if out of memory */
|
/* Abort if out of memory */
|
||||||
@ -4270,13 +4274,13 @@ void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: check extent
|
// TODO: check extent
|
||||||
QgsRectangle partExtent (
|
QgsRectangle partExtent(
|
||||||
viewPort->mDrawnExtent.xMinimum(),
|
viewPort->mDrawnExtent.xMinimum(),
|
||||||
viewPort->mDrawnExtent.yMinimum(),
|
viewPort->mDrawnExtent.yMinimum(),
|
||||||
viewPort->mDrawnExtent.xMaximum(),
|
viewPort->mDrawnExtent.xMaximum(),
|
||||||
viewPort->mDrawnExtent.yMaximum()
|
viewPort->mDrawnExtent.yMaximum()
|
||||||
);
|
);
|
||||||
mDataProvider->readBlock ( bandNo, partExtent, viewPort->drawableAreaXDim, viewPort->drawableAreaYDim, QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem(), data );
|
mDataProvider->readBlock( bandNo, partExtent, viewPort->drawableAreaXDim, viewPort->drawableAreaYDim, QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem(), data );
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -4422,7 +4426,7 @@ QString QgsRasterLayer::validateBandName( QString const & theBandName )
|
|||||||
}
|
}
|
||||||
|
|
||||||
QgsRasterImageBuffer::QgsRasterImageBuffer( QgsRasterDataProvider *dataProvider, int bandNo, QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel, double* geoTransform ):
|
QgsRasterImageBuffer::QgsRasterImageBuffer( QgsRasterDataProvider *dataProvider, int bandNo, QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel, double* geoTransform ):
|
||||||
mDataProvider( dataProvider ), mBandNo(bandNo), mPainter( p ), mViewPort( viewPort ), mMapToPixel( mapToPixel ), mGeoTransform( geoTransform ), mValid( false ), mWritingEnabled( true ), mDrawPixelRect( false ), mCurrentImage( 0 ), mCurrentGDALData( 0 )
|
mDataProvider( dataProvider ), mBandNo( bandNo ), mPainter( p ), mViewPort( viewPort ), mMapToPixel( mapToPixel ), mGeoTransform( geoTransform ), mValid( false ), mWritingEnabled( true ), mDrawPixelRect( false ), mCurrentImage( 0 ), mCurrentGDALData( 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -4496,7 +4500,7 @@ bool QgsRasterImageBuffer::nextScanLine( QRgb** imageScanLine, void** rasterScan
|
|||||||
{
|
{
|
||||||
*imageScanLine = 0;
|
*imageScanLine = 0;
|
||||||
}
|
}
|
||||||
int size = mDataProvider->dataTypeSize(mBandNo)/8;
|
int size = mDataProvider->dataTypeSize( mBandNo ) / 8;
|
||||||
*rasterScanLine = ( unsigned char * )mCurrentGDALData + mCurrentPartImageRow * mViewPort->drawableAreaXDim * size;
|
*rasterScanLine = ( unsigned char * )mCurrentGDALData + mCurrentPartImageRow * mViewPort->drawableAreaXDim * size;
|
||||||
|
|
||||||
++mCurrentPartImageRow;
|
++mCurrentPartImageRow;
|
||||||
@ -4512,7 +4516,7 @@ bool QgsRasterImageBuffer::createNextPartImage()
|
|||||||
{
|
{
|
||||||
if ( mWritingEnabled )
|
if ( mWritingEnabled )
|
||||||
{
|
{
|
||||||
// TODO: consider similar system with raster providers, see the comment
|
// TODO: consider similar system with raster providers, see the comment
|
||||||
// in QgsRasterImageBuffer::drawPixelRectangle()
|
// in QgsRasterImageBuffer::drawPixelRectangle()
|
||||||
// e.g request the block with raster resolution and draw pixels as rectangles
|
// e.g request the block with raster resolution and draw pixels as rectangles
|
||||||
//if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
|
//if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
|
||||||
@ -4533,9 +4537,9 @@ bool QgsRasterImageBuffer::createNextPartImage()
|
|||||||
imageY = mViewPort->topLeftPoint.y() + mCurrentPartRasterMin / mMapToPixel->mapUnitsPerPixel();
|
imageY = mViewPort->topLeftPoint.y() + mCurrentPartRasterMin / mMapToPixel->mapUnitsPerPixel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDebugMsg( QString("mCurrentPartRasterMin = %1").arg( mCurrentPartRasterMin) );
|
QgsDebugMsg( QString( "mCurrentPartRasterMin = %1" ).arg( mCurrentPartRasterMin ) );
|
||||||
QgsDebugMsg( QString("imageX = %1 imageY = %2").arg(imageX).arg(imageY) );
|
QgsDebugMsg( QString( "imageX = %1 imageY = %2" ).arg( imageX ).arg( imageY ) );
|
||||||
mPainter->drawImage( QPointF ( imageX, imageY ), //the top-left point in the paint device
|
mPainter->drawImage( QPointF( imageX, imageY ), //the top-left point in the paint device
|
||||||
*mCurrentImage );
|
*mCurrentImage );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4545,7 +4549,7 @@ bool QgsRasterImageBuffer::createNextPartImage()
|
|||||||
CPLFree( mCurrentGDALData ); mCurrentGDALData = 0;
|
CPLFree( mCurrentGDALData ); mCurrentGDALData = 0;
|
||||||
|
|
||||||
mCurrentPart++; // NEW
|
mCurrentPart++; // NEW
|
||||||
QgsDebugMsg( QString("mCurrentPartRasterMax = %1 mViewPort->drawableAreaYDim = %2").arg(mCurrentPartRasterMax).arg(mViewPort->drawableAreaYDim) );
|
QgsDebugMsg( QString( "mCurrentPartRasterMax = %1 mViewPort->drawableAreaYDim = %2" ).arg( mCurrentPartRasterMax ).arg( mViewPort->drawableAreaYDim ) );
|
||||||
if ( mCurrentPartRasterMax >= mViewPort->drawableAreaYDim )
|
if ( mCurrentPartRasterMax >= mViewPort->drawableAreaYDim )
|
||||||
{
|
{
|
||||||
return false; //already at the end...
|
return false; //already at the end...
|
||||||
@ -4561,7 +4565,7 @@ bool QgsRasterImageBuffer::createNextPartImage()
|
|||||||
mCurrentPartImageRow = 0;
|
mCurrentPartImageRow = 0;
|
||||||
|
|
||||||
//read GDAL image data
|
//read GDAL image data
|
||||||
int size = mDataProvider->dataTypeSize ( mBandNo ) / 8 ;
|
int size = mDataProvider->dataTypeSize( mBandNo ) / 8 ;
|
||||||
int xSize = mViewPort->drawableAreaXDim;
|
int xSize = mViewPort->drawableAreaXDim;
|
||||||
int ySize = mViewPort->drawableAreaYDim;
|
int ySize = mViewPort->drawableAreaYDim;
|
||||||
|
|
||||||
@ -4578,7 +4582,7 @@ bool QgsRasterImageBuffer::createNextPartImage()
|
|||||||
overlapRows = 0;
|
overlapRows = 0;
|
||||||
}
|
}
|
||||||
int rasterYSize = mCurrentPartRasterMax - mCurrentPartRasterMin + overlapRows;
|
int rasterYSize = mCurrentPartRasterMax - mCurrentPartRasterMin + overlapRows;
|
||||||
QgsDebugMsg( "rasterYSize = " + QString::number( rasterYSize ));
|
QgsDebugMsg( "rasterYSize = " + QString::number( rasterYSize ) );
|
||||||
|
|
||||||
// TODO: consider something like this
|
// TODO: consider something like this
|
||||||
//if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight ) //for zoomed in rasters
|
//if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight ) //for zoomed in rasters
|
||||||
@ -4595,23 +4599,23 @@ bool QgsRasterImageBuffer::createNextPartImage()
|
|||||||
//ySize = qAbs((( rasterYSize ) / mMapToPixel->mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5;
|
//ySize = qAbs((( rasterYSize ) / mMapToPixel->mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QgsDebugMsg( QString("xSize = %1 ySize = %2").arg(xSize).arg(ySize) );
|
QgsDebugMsg( QString( "xSize = %1 ySize = %2" ).arg( xSize ).arg( ySize ) );
|
||||||
if ( ySize < 1 || xSize < 1 )
|
if ( ySize < 1 || xSize < 1 )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mNumCurrentImageRows = ySize;
|
mNumCurrentImageRows = ySize;
|
||||||
QgsDebugMsg( "alloc " + QString::number( size * xSize * ySize) );
|
QgsDebugMsg( "alloc " + QString::number( size * xSize * ySize ) );
|
||||||
mCurrentGDALData = VSIMalloc( size * xSize * ySize );
|
mCurrentGDALData = VSIMalloc( size * xSize * ySize );
|
||||||
|
|
||||||
double yMax = mViewPort->mDrawnExtent.yMaximum() - mCurrentRow * mMapToPixel->mapUnitsPerPixel();
|
double yMax = mViewPort->mDrawnExtent.yMaximum() - mCurrentRow * mMapToPixel->mapUnitsPerPixel();
|
||||||
double yMin = yMax - ySize * mMapToPixel->mapUnitsPerPixel();
|
double yMin = yMax - ySize * mMapToPixel->mapUnitsPerPixel();
|
||||||
|
|
||||||
QgsDebugMsg( QString("mCurrentRow = %1 yMaximum = %2 ySize = %3 mapUnitsPerPixel = %4").arg(mCurrentRow).arg(mViewPort->mDrawnExtent.yMaximum()).arg(ySize).arg(mMapToPixel->mapUnitsPerPixel()) );
|
QgsDebugMsg( QString( "mCurrentRow = %1 yMaximum = %2 ySize = %3 mapUnitsPerPixel = %4" ).arg( mCurrentRow ).arg( mViewPort->mDrawnExtent.yMaximum() ).arg( ySize ).arg( mMapToPixel->mapUnitsPerPixel() ) );
|
||||||
QgsRectangle myPartExtent ( mViewPort->mDrawnExtent.xMinimum(), yMin,
|
QgsRectangle myPartExtent( mViewPort->mDrawnExtent.xMinimum(), yMin,
|
||||||
mViewPort->mDrawnExtent.xMaximum(), yMax );
|
mViewPort->mDrawnExtent.xMaximum(), yMax );
|
||||||
QgsDebugMsg( "myPartExtent is " + myPartExtent.toString() );
|
QgsDebugMsg( "myPartExtent is " + myPartExtent.toString() );
|
||||||
mDataProvider->readBlock ( mBandNo, myPartExtent, xSize, ySize, mViewPort->mSrcCRS, mViewPort->mDestCRS, mCurrentGDALData );
|
mDataProvider->readBlock( mBandNo, myPartExtent, xSize, ySize, mViewPort->mSrcCRS, mViewPort->mDestCRS, mCurrentGDALData );
|
||||||
|
|
||||||
//create the QImage
|
//create the QImage
|
||||||
if ( mWritingEnabled )
|
if ( mWritingEnabled )
|
||||||
@ -4630,9 +4634,9 @@ void QgsRasterImageBuffer::drawPixelRectangle()
|
|||||||
{
|
{
|
||||||
// TODO: consider using similar with raster providers, originaly it was used only with
|
// TODO: consider using similar with raster providers, originaly it was used only with
|
||||||
// 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight
|
// 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight
|
||||||
// but why? but I believe that it should be used always if the ration of original
|
// but why? but I believe that it should be used always if the ration of original
|
||||||
// raster resolution and device resolution is under certain limit
|
// raster resolution and device resolution is under certain limit
|
||||||
/*
|
#if 0
|
||||||
// Set up the initial offset into the myQImage we want to copy to the map canvas
|
// Set up the initial offset into the myQImage we want to copy to the map canvas
|
||||||
// This is useful when the source image pixels are larger than the screen image.
|
// This is useful when the source image pixels are larger than the screen image.
|
||||||
int paintXoffset = 0;
|
int paintXoffset = 0;
|
||||||
@ -4654,7 +4658,7 @@ void QgsRasterImageBuffer::drawPixelRectangle()
|
|||||||
* qAbs( mGeoTransform[5] )
|
* qAbs( mGeoTransform[5] )
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//fix for zoomed in rasters
|
//fix for zoomed in rasters
|
||||||
@ -4753,7 +4757,7 @@ void QgsRasterImageBuffer::drawPixelRectangle()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep this for now, it is used by Python interface!!!
|
// Keep this for now, it is used by Python interface!!!
|
||||||
@ -4767,8 +4771,9 @@ void QgsRasterLayer::registerGdalDrivers()
|
|||||||
bool QgsRasterLayer::readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList )
|
bool QgsRasterLayer::readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList )
|
||||||
{
|
{
|
||||||
// TODO : check if exists - returned vale?
|
// TODO : check if exists - returned vale?
|
||||||
QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->colorTable ( theBandNumber );
|
QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->colorTable( theBandNumber );
|
||||||
if ( myColorRampItemList.size() == 0 ) {
|
if ( myColorRampItemList.size() == 0 )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*theList = myColorRampItemList;
|
*theList = myColorRampItemList;
|
||||||
|
@ -298,14 +298,14 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
|
|||||||
//
|
//
|
||||||
|
|
||||||
/** \brief Initialize default values */
|
/** \brief Initialize default values */
|
||||||
void init ();
|
void init();
|
||||||
|
|
||||||
// For backward compatibility (Python) get rid of it once python is updated
|
// For backward compatibility (Python) get rid of it once python is updated
|
||||||
void setDataProvider( const QString & provider,
|
void setDataProvider( const QString & provider,
|
||||||
const QStringList & layers,
|
const QStringList & layers,
|
||||||
const QStringList & styles,
|
const QStringList & styles,
|
||||||
const QString & format,
|
const QString & format,
|
||||||
const QString & crs);
|
const QString & crs );
|
||||||
/** [ data provider interface ] Set the data provider */
|
/** [ data provider interface ] Set the data provider */
|
||||||
void setDataProvider( const QString & provider,
|
void setDataProvider( const QString & provider,
|
||||||
const QStringList & layers,
|
const QStringList & layers,
|
||||||
@ -314,9 +314,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
|
|||||||
const QString & crs,
|
const QString & crs,
|
||||||
bool loadDefaultStyleFlag );
|
bool loadDefaultStyleFlag );
|
||||||
|
|
||||||
static QLibrary* loadProviderLibrary( QString theProviderKey);
|
static QLibrary* loadProviderLibrary( QString theProviderKey );
|
||||||
static QgsRasterDataProvider* loadProvider( QString theProviderKey, QString theDataSource = 0);
|
static QgsRasterDataProvider* loadProvider( QString theProviderKey, QString theDataSource = 0 );
|
||||||
|
|
||||||
|
|
||||||
/** \brief Accessor for blue band name mapping */
|
/** \brief Accessor for blue band name mapping */
|
||||||
QString blueBandName() const { return mBlueBandName; }
|
QString blueBandName() const { return mBlueBandName; }
|
||||||
@ -657,7 +657,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
|
|||||||
bool theTryInternalFlag = false );
|
bool theTryInternalFlag = false );
|
||||||
|
|
||||||
/** \brief Populate the histogram vector for a given band */
|
/** \brief Populate the histogram vector for a given band */
|
||||||
|
|
||||||
void populateHistogram( int theBandNoInt,
|
void populateHistogram( int theBandNoInt,
|
||||||
int theBinCountInt = 256,
|
int theBinCountInt = 256,
|
||||||
bool theIgnoreOutOfRangeFlag = true,
|
bool theIgnoreOutOfRangeFlag = true,
|
||||||
@ -692,9 +692,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
|
|||||||
//
|
//
|
||||||
/** \brief Drawing routine for color type data */
|
/** \brief Drawing routine for color type data */
|
||||||
void drawSingleBandColorData( QPainter * theQPainter,
|
void drawSingleBandColorData( QPainter * theQPainter,
|
||||||
QgsRasterViewPort * theRasterViewPort,
|
QgsRasterViewPort * theRasterViewPort,
|
||||||
const QgsMapToPixel* theQgsMapToPixel,
|
const QgsMapToPixel* theQgsMapToPixel,
|
||||||
int theBandNoInt );
|
int theBandNoInt );
|
||||||
|
|
||||||
/** \brief Drawing routine for multiband image */
|
/** \brief Drawing routine for multiband image */
|
||||||
void drawMultiBandColor( QPainter * theQPainter,
|
void drawMultiBandColor( QPainter * theQPainter,
|
||||||
@ -912,7 +912,7 @@ class CORE_EXPORT QgsRasterImageBuffer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QgsRasterImageBuffer( QgsRasterDataProvider *dataProvider, int bandNo, QPainter* p,
|
QgsRasterImageBuffer( QgsRasterDataProvider *dataProvider, int bandNo, QPainter* p,
|
||||||
QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel, double* mGeoTransform );
|
QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel, double* mGeoTransform );
|
||||||
~QgsRasterImageBuffer();
|
~QgsRasterImageBuffer();
|
||||||
void reset( int maxPixelsInVirtualMemory = 5000000 );
|
void reset( int maxPixelsInVirtualMemory = 5000000 );
|
||||||
/**Returns a pointer to the next scan line (or 0 if end)*/
|
/**Returns a pointer to the next scan line (or 0 if end)*/
|
||||||
@ -948,7 +948,7 @@ class CORE_EXPORT QgsRasterImageBuffer
|
|||||||
int mCurrentPartImageRow; //current image row
|
int mCurrentPartImageRow; //current image row
|
||||||
int mNumCurrentImageRows; //number of image rows for the current part
|
int mNumCurrentImageRows; //number of image rows for the current part
|
||||||
|
|
||||||
int mCurrentPart;
|
int mCurrentPart;
|
||||||
|
|
||||||
//current memory image and gdal scan data
|
//current memory image and gdal scan data
|
||||||
QImage* mCurrentImage;
|
QImage* mCurrentImage;
|
||||||
|
@ -40,7 +40,7 @@ struct QgsRasterViewPort
|
|||||||
QgsPoint bottomRightPoint;
|
QgsPoint bottomRightPoint;
|
||||||
/** \brief Distance in map units from left edge to right edge for the part of the raster that
|
/** \brief Distance in map units from left edge to right edge for the part of the raster that
|
||||||
* is to be rendered.*/
|
* is to be rendered.*/
|
||||||
|
|
||||||
int drawableAreaXDim;
|
int drawableAreaXDim;
|
||||||
/** \brief Distance in map units from bottom edge to top edge for the part of the raster that
|
/** \brief Distance in map units from bottom edge to top edge for the part of the raster that
|
||||||
* is to be rendered.*/
|
* is to be rendered.*/
|
||||||
|
@ -85,13 +85,13 @@ int CPL_STDCALL progressCallback( double dfComplete,
|
|||||||
|
|
||||||
if ( nPercent == 100 )
|
if ( nPercent == 100 )
|
||||||
{
|
{
|
||||||
fprintf( stdout, "%d - done.\n", (int) floor(dfComplete*100) );
|
fprintf( stdout, "%d - done.\n", ( int ) floor( dfComplete*100 ) );
|
||||||
//mypLayer->showProgress( 100 );
|
//mypLayer->showProgress( 100 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int myProgress = ( int ) floor( dfComplete * 100 );
|
int myProgress = ( int ) floor( dfComplete * 100 );
|
||||||
fprintf( stdout, "%d.", myProgress);
|
fprintf( stdout, "%d.", myProgress );
|
||||||
//mypLayer->showProgress( myProgress );
|
//mypLayer->showProgress( myProgress );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
}
|
}
|
||||||
@ -134,18 +134,18 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
|
|||||||
if ( mGdalBaseDataset == NULL )
|
if ( mGdalBaseDataset == NULL )
|
||||||
{
|
{
|
||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot open GDAL dataset ") + uri + " : "
|
QObject::tr( "Cannot open GDAL dataset " ) + uri + " : "
|
||||||
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDebugMsg ("GdalDataset opened" );
|
QgsDebugMsg( "GdalDataset opened" );
|
||||||
|
|
||||||
for ( int i = 0; i < GDALGetRasterCount( mGdalBaseDataset ); i++ )
|
for ( int i = 0; i < GDALGetRasterCount( mGdalBaseDataset ); i++ )
|
||||||
{
|
{
|
||||||
mMinMaxComputed.append(false);
|
mMinMaxComputed.append( false );
|
||||||
mMinimum.append(0);
|
mMinimum.append( 0 );
|
||||||
mMaximum.append(0);
|
mMaximum.append( 0 );
|
||||||
}
|
}
|
||||||
// Check if we need a warped VRT for this file.
|
// Check if we need a warped VRT for this file.
|
||||||
if (( GDALGetGeoTransform( mGdalBaseDataset, mGeoTransform ) == CE_None
|
if (( GDALGetGeoTransform( mGdalBaseDataset, mGeoTransform ) == CE_None
|
||||||
@ -179,8 +179,8 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
|
|||||||
if ( myGDALBand == NULL )
|
if ( myGDALBand == NULL )
|
||||||
{
|
{
|
||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot get GDAL raster band : " )
|
QObject::tr( "Cannot get GDAL raster band : " )
|
||||||
+ QString::fromUtf8( CPLGetLastErrorMsg() ) ) ;
|
+ QString::fromUtf8( CPLGetLastErrorMsg() ) ) ;
|
||||||
|
|
||||||
GDALDereferenceDataset( mGdalBaseDataset );
|
GDALDereferenceDataset( mGdalBaseDataset );
|
||||||
mGdalBaseDataset = NULL;
|
mGdalBaseDataset = NULL;
|
||||||
@ -251,23 +251,24 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
|
|||||||
mValidNoDataValue = true;
|
mValidNoDataValue = true;
|
||||||
for ( int i = 1; i <= GDALGetRasterCount( mGdalBaseDataset ); i++ )
|
for ( int i = 1; i <= GDALGetRasterCount( mGdalBaseDataset ); i++ )
|
||||||
{
|
{
|
||||||
computeMinMax ( i );
|
computeMinMax( i );
|
||||||
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
|
||||||
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
|
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
|
||||||
int isValid = false;
|
int isValid = false;
|
||||||
double myNoDataValue = GDALGetRasterNoDataValue( GDALGetRasterBand( mGdalDataset, i ), &isValid );
|
double myNoDataValue = GDALGetRasterNoDataValue( GDALGetRasterBand( mGdalDataset, i ), &isValid );
|
||||||
if ( isValid )
|
if ( isValid )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString("GDALGetRasterNoDataValue = %1").arg( myNoDataValue ) ) ;
|
QgsDebugMsg( QString( "GDALGetRasterNoDataValue = %1" ).arg( myNoDataValue ) ) ;
|
||||||
mGdalDataType.append( myGdalDataType );
|
mGdalDataType.append( myGdalDataType );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// But we need a null value in case of reprojection and BTW also for
|
// But we need a null value in case of reprojection and BTW also for
|
||||||
// aligned margines
|
// aligned margines
|
||||||
|
|
||||||
switch ( srcDataType( i ) ) {
|
switch ( srcDataType( i ) )
|
||||||
|
{
|
||||||
case QgsRasterDataProvider::Byte:
|
case QgsRasterDataProvider::Byte:
|
||||||
// Use longer data type to avoid conflict with real data
|
// Use longer data type to avoid conflict with real data
|
||||||
myNoDataValue = -32768.0;
|
myNoDataValue = -32768.0;
|
||||||
@ -291,58 +292,58 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
myNoDataValue = std::numeric_limits<int>::max();
|
myNoDataValue = std::numeric_limits<int>::max();
|
||||||
// Would NaN work well?
|
// Would NaN work well?
|
||||||
//myNoDataValue = std::numeric_limits<double>::quiet_NaN();
|
//myNoDataValue = std::numeric_limits<double>::quiet_NaN();
|
||||||
mGdalDataType.append( myGdalDataType );
|
mGdalDataType.append( myGdalDataType );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mNoDataValue.append( myNoDataValue );
|
mNoDataValue.append( myNoDataValue );
|
||||||
QgsDebugMsg( QString("mNoDataValue[%1] = %1").arg(i-1).arg ( mNoDataValue[i-1] ) );
|
QgsDebugMsg( QString( "mNoDataValue[%1] = %1" ).arg( i - 1 ).arg( mNoDataValue[i-1] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// This block of code was in old version in QgsRasterLayer::bandStatistics
|
// This block of code was in old version in QgsRasterLayer::bandStatistics
|
||||||
//ifdefs below to remove compiler warning about unused vars
|
//ifdefs below to remove compiler warning about unused vars
|
||||||
#ifdef QGISDEBUG
|
#ifdef QGISDEBUG
|
||||||
/*
|
/*
|
||||||
int success;
|
int success;
|
||||||
double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
|
double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
|
||||||
|
|
||||||
if ( ! success )
|
if ( ! success )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "myGdalBand->GetMinimum() failed" );
|
QgsDebugMsg( "myGdalBand->GetMinimum() failed" );
|
||||||
}
|
}
|
||||||
|
|
||||||
double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
|
double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
|
||||||
|
|
||||||
if ( ! success )
|
if ( ! success )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "myGdalBand->GetMaximum() failed" );
|
QgsDebugMsg( "myGdalBand->GetMaximum() failed" );
|
||||||
}
|
}
|
||||||
|
|
||||||
double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
|
double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
|
||||||
|
|
||||||
if ( ! success )
|
if ( ! success )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "myGdalBand->GetNoDataValue() failed" );
|
QgsDebugMsg( "myGdalBand->GetNoDataValue() failed" );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsLogger::debug( "GDALminium: ", GDALminimum, __FILE__, __FUNCTION__, __LINE__ );
|
QgsLogger::debug( "GDALminium: ", GDALminimum, __FILE__, __FUNCTION__, __LINE__ );
|
||||||
QgsLogger::debug( "GDALmaximum: ", GDALmaximum, __FILE__, __FUNCTION__, __LINE__ );
|
QgsLogger::debug( "GDALmaximum: ", GDALmaximum, __FILE__, __FUNCTION__, __LINE__ );
|
||||||
QgsLogger::debug( "GDALnodata: ", GDALnodata, __FILE__, __FUNCTION__, __LINE__ );
|
QgsLogger::debug( "GDALnodata: ", GDALnodata, __FILE__, __FUNCTION__, __LINE__ );
|
||||||
|
|
||||||
double GDALrange[2]; // calculated min/max, as opposed to the
|
double GDALrange[2]; // calculated min/max, as opposed to the
|
||||||
// dataset provided
|
// dataset provided
|
||||||
|
|
||||||
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange );
|
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange );
|
||||||
QgsLogger::debug( "approximate computed GDALminium:", GDALrange[0], __FILE__, __FUNCTION__, __LINE__, 1 );
|
QgsLogger::debug( "approximate computed GDALminium:", GDALrange[0], __FILE__, __FUNCTION__, __LINE__, 1 );
|
||||||
QgsLogger::debug( "approximate computed GDALmaximum:", GDALrange[1], __FILE__, __FUNCTION__, __LINE__, 1 );
|
QgsLogger::debug( "approximate computed GDALmaximum:", GDALrange[1], __FILE__, __FUNCTION__, __LINE__, 1 );
|
||||||
|
|
||||||
GDALComputeRasterMinMax( myGdalBand, 0, GDALrange );
|
GDALComputeRasterMinMax( myGdalBand, 0, GDALrange );
|
||||||
QgsLogger::debug( "exactly computed GDALminium:", GDALrange[0] );
|
QgsLogger::debug( "exactly computed GDALminium:", GDALrange[0] );
|
||||||
QgsLogger::debug( "exactly computed GDALmaximum:", GDALrange[1] );
|
QgsLogger::debug( "exactly computed GDALmaximum:", GDALrange[1] );
|
||||||
|
|
||||||
QgsDebugMsg( "starting manual stat computation" );
|
QgsDebugMsg( "starting manual stat computation" );
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mValid = true;
|
mValid = true;
|
||||||
@ -375,7 +376,7 @@ void QgsGdalProvider::closeDataset()
|
|||||||
GDALClose( mGdalDataset );
|
GDALClose( mGdalDataset );
|
||||||
mGdalDataset = NULL;
|
mGdalDataset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsGdalProvider::metadata()
|
QString QgsGdalProvider::metadata()
|
||||||
{
|
{
|
||||||
QString myMetadata ;
|
QString myMetadata ;
|
||||||
@ -512,16 +513,16 @@ QImage* QgsGdalProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
|
|||||||
void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *block )
|
void QgsGdalProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *block )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Entered" );
|
QgsDebugMsg( "Entered" );
|
||||||
|
|
||||||
QgsDebugMsg( "yBlock = " + QString::number( yBlock ) );
|
QgsDebugMsg( "yBlock = " + QString::number( yBlock ) );
|
||||||
|
|
||||||
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
||||||
//GDALReadBlock( myGdalBand, xBlock, yBlock, block );
|
//GDALReadBlock( myGdalBand, xBlock, yBlock, block );
|
||||||
|
|
||||||
/* We have to read with correct data type consistent with other readBlock functions */
|
/* We have to read with correct data type consistent with other readBlock functions */
|
||||||
int xOff = xBlock * mXBlockSize;
|
int xOff = xBlock * mXBlockSize;
|
||||||
int yOff = yBlock * mYBlockSize;
|
int yOff = yBlock * mYBlockSize;
|
||||||
GDALRasterIO ( myGdalBand, GF_Read, xOff, yOff, mXBlockSize, mYBlockSize, block, mXBlockSize, mYBlockSize, (GDALDataType) mGdalDataType[theBandNo-1], 0, 0 );
|
GDALRasterIO( myGdalBand, GF_Read, xOff, yOff, mXBlockSize, mYBlockSize, block, mXBlockSize, mYBlockSize, ( GDALDataType ) mGdalDataType[theBandNo-1], 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent, int thePixelWidth, int thePixelHeight, void *theBlock )
|
void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent, int thePixelWidth, int thePixelHeight, void *theBlock )
|
||||||
@ -531,46 +532,42 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
|
|||||||
QgsDebugMsg( "theExtent: " + theExtent.toString() );
|
QgsDebugMsg( "theExtent: " + theExtent.toString() );
|
||||||
QgsDebugMsg( "crs(): " + crs().toWkt() );
|
QgsDebugMsg( "crs(): " + crs().toWkt() );
|
||||||
|
|
||||||
|
|
||||||
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
|
||||||
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
|
|
||||||
|
|
||||||
QString myMemDsn;
|
QString myMemDsn;
|
||||||
myMemDsn.sprintf ( "DATAPOINTER = %p", theBlock );
|
myMemDsn.sprintf( "DATAPOINTER = %p", theBlock );
|
||||||
QgsDebugMsg( myMemDsn );
|
QgsDebugMsg( myMemDsn );
|
||||||
|
|
||||||
myMemDsn.sprintf ( "MEM:::DATAPOINTER=%lu,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=%s,PIXELOFFSET=0,LINEOFFSET=0,BANDOFFSET=0", (long)theBlock, thePixelWidth, thePixelHeight, GDALGetDataTypeName( (GDALDataType)mGdalDataType[theBandNo-1] ) );
|
myMemDsn.sprintf( "MEM:::DATAPOINTER=%lu,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE=%s,PIXELOFFSET=0,LINEOFFSET=0,BANDOFFSET=0", ( long )theBlock, thePixelWidth, thePixelHeight, GDALGetDataTypeName(( GDALDataType )mGdalDataType[theBandNo-1] ) );
|
||||||
|
|
||||||
QgsDebugMsg( "Open GDAL MEM : " + myMemDsn );
|
QgsDebugMsg( "Open GDAL MEM : " + myMemDsn );
|
||||||
|
|
||||||
CPLErrorReset();
|
CPLErrorReset();
|
||||||
GDALDatasetH myGdalMemDataset = GDALOpen( TO8F( myMemDsn ), GA_Update );
|
GDALDatasetH myGdalMemDataset = GDALOpen( TO8F( myMemDsn ), GA_Update );
|
||||||
|
|
||||||
if ( !myGdalMemDataset )
|
if ( !myGdalMemDataset )
|
||||||
{
|
{
|
||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot open GDAL MEM dataset ") + myMemDsn + " : "
|
QObject::tr( "Cannot open GDAL MEM dataset " ) + myMemDsn + " : "
|
||||||
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GDALSetProjection( myGdalMemDataset, theDestCRS.toWkt().toAscii().constData() );
|
//GDALSetProjection( myGdalMemDataset, theDestCRS.toWkt().toAscii().constData() );
|
||||||
|
|
||||||
double myMemGeoTransform[6];
|
double myMemGeoTransform[6];
|
||||||
myMemGeoTransform[0] = theExtent.xMinimum(); /* top left x */
|
myMemGeoTransform[0] = theExtent.xMinimum(); /* top left x */
|
||||||
myMemGeoTransform[1] = theExtent.width()/thePixelWidth; /* w-e pixel resolution */
|
myMemGeoTransform[1] = theExtent.width() / thePixelWidth; /* w-e pixel resolution */
|
||||||
myMemGeoTransform[2] = 0; /* rotation, 0 if image is "north up" */
|
myMemGeoTransform[2] = 0; /* rotation, 0 if image is "north up" */
|
||||||
myMemGeoTransform[3] = theExtent.yMaximum(); /* top left y */
|
myMemGeoTransform[3] = theExtent.yMaximum(); /* top left y */
|
||||||
myMemGeoTransform[4] = 0; /* rotation, 0 if image is "north up" */
|
myMemGeoTransform[4] = 0; /* rotation, 0 if image is "north up" */
|
||||||
myMemGeoTransform[5] = -1. * theExtent.height()/thePixelHeight; /* n-s pixel resolution */
|
myMemGeoTransform[5] = -1. * theExtent.height() / thePixelHeight; /* n-s pixel resolution */
|
||||||
|
|
||||||
double myGeoTransform[6];
|
double myGeoTransform[6];
|
||||||
GDALGetGeoTransform( mGdalDataset, myGeoTransform );
|
GDALGetGeoTransform( mGdalDataset, myGeoTransform );
|
||||||
GDALSetGeoTransform( myGdalMemDataset, myMemGeoTransform );
|
GDALSetGeoTransform( myGdalMemDataset, myMemGeoTransform );
|
||||||
|
|
||||||
for ( int i = 0 ; i < 6; i++ )
|
for ( int i = 0 ; i < 6; i++ )
|
||||||
{
|
{
|
||||||
QgsDebugMsg ( QString("transform : %1 %2").arg(myGeoTransform[i]).arg ( myMemGeoTransform[i] ) );
|
QgsDebugMsg( QString( "transform : %1 %2" ).arg( myGeoTransform[i] ).arg( myMemGeoTransform[i] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
GDALWarpOptions *myWarpOptions = GDALCreateWarpOptions();
|
GDALWarpOptions *myWarpOptions = GDALCreateWarpOptions();
|
||||||
@ -579,44 +576,44 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
|
|||||||
myWarpOptions->hDstDS = myGdalMemDataset;
|
myWarpOptions->hDstDS = myGdalMemDataset;
|
||||||
|
|
||||||
myWarpOptions->nBandCount = 1;
|
myWarpOptions->nBandCount = 1;
|
||||||
myWarpOptions->panSrcBands =
|
myWarpOptions->panSrcBands =
|
||||||
(int *) CPLMalloc(sizeof(int) * myWarpOptions->nBandCount );
|
( int * ) CPLMalloc( sizeof( int ) * myWarpOptions->nBandCount );
|
||||||
myWarpOptions->panSrcBands[0] = theBandNo;
|
myWarpOptions->panSrcBands[0] = theBandNo;
|
||||||
myWarpOptions->panDstBands =
|
myWarpOptions->panDstBands =
|
||||||
(int *) CPLMalloc(sizeof(int) * myWarpOptions->nBandCount );
|
( int * ) CPLMalloc( sizeof( int ) * myWarpOptions->nBandCount );
|
||||||
myWarpOptions->panDstBands[0] = 1;
|
myWarpOptions->panDstBands[0] = 1;
|
||||||
|
|
||||||
// TODO move here progressCallback and use it
|
// TODO move here progressCallback and use it
|
||||||
myWarpOptions->pfnProgress = GDALTermProgress;
|
myWarpOptions->pfnProgress = GDALTermProgress;
|
||||||
|
|
||||||
QgsDebugMsg ( "src wkt: " + QString (GDALGetProjectionRef(mGdalDataset) ) );
|
QgsDebugMsg( "src wkt: " + QString( GDALGetProjectionRef( mGdalDataset ) ) );
|
||||||
QgsDebugMsg ( "dst wkt: " + QString (GDALGetProjectionRef(myGdalMemDataset) ) );
|
QgsDebugMsg( "dst wkt: " + QString( GDALGetProjectionRef( myGdalMemDataset ) ) );
|
||||||
myWarpOptions->pTransformerArg =
|
myWarpOptions->pTransformerArg =
|
||||||
GDALCreateGenImgProjTransformer(
|
GDALCreateGenImgProjTransformer(
|
||||||
mGdalDataset,
|
mGdalDataset,
|
||||||
NULL,
|
NULL,
|
||||||
myGdalMemDataset,
|
myGdalMemDataset,
|
||||||
NULL,
|
NULL,
|
||||||
FALSE, 0.0, 1
|
FALSE, 0.0, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
CPLAssert( myWarpOptions->pTransformerArg != NULL);
|
CPLAssert( myWarpOptions->pTransformerArg != NULL );
|
||||||
myWarpOptions->pfnTransformer = GDALGenImgProjTransform;
|
myWarpOptions->pfnTransformer = GDALGenImgProjTransform;
|
||||||
|
|
||||||
myWarpOptions->padfDstNoDataReal = (double *) CPLMalloc( myWarpOptions->nBandCount * sizeof(double));
|
myWarpOptions->padfDstNoDataReal = ( double * ) CPLMalloc( myWarpOptions->nBandCount * sizeof( double ) );
|
||||||
myWarpOptions->padfDstNoDataImag = (double *) CPLMalloc( myWarpOptions->nBandCount * sizeof(double));
|
myWarpOptions->padfDstNoDataImag = ( double * ) CPLMalloc( myWarpOptions->nBandCount * sizeof( double ) );
|
||||||
|
|
||||||
myWarpOptions->padfDstNoDataReal[0] = mNoDataValue[theBandNo-1];
|
myWarpOptions->padfDstNoDataReal[0] = mNoDataValue[theBandNo-1];
|
||||||
myWarpOptions->padfDstNoDataImag[0] = 0.0;
|
myWarpOptions->padfDstNoDataImag[0] = 0.0;
|
||||||
|
|
||||||
GDALSetRasterNoDataValue( GDALGetRasterBand( myGdalMemDataset,
|
GDALSetRasterNoDataValue( GDALGetRasterBand( myGdalMemDataset,
|
||||||
myWarpOptions->panDstBands[0] ),
|
myWarpOptions->panDstBands[0] ),
|
||||||
myWarpOptions->padfDstNoDataReal[0] );
|
myWarpOptions->padfDstNoDataReal[0] );
|
||||||
|
|
||||||
// TODO optimize somehow to avoid no data init if not necessary
|
// TODO optimize somehow to avoid no data init if not necessary
|
||||||
// i.e. no projection, but there is also the problem with margine
|
// i.e. no projection, but there is also the problem with margine
|
||||||
myWarpOptions->papszWarpOptions =
|
myWarpOptions->papszWarpOptions =
|
||||||
CSLSetNameValue(myWarpOptions->papszWarpOptions,"INIT_DEST", "NO_DATA" );
|
CSLSetNameValue( myWarpOptions->papszWarpOptions, "INIT_DEST", "NO_DATA" );
|
||||||
|
|
||||||
myWarpOptions->eResampleAlg = GRA_NearestNeighbour;
|
myWarpOptions->eResampleAlg = GRA_NearestNeighbour;
|
||||||
|
|
||||||
@ -625,54 +622,56 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
|
|||||||
myOperation.Initialize( myWarpOptions );
|
myOperation.Initialize( myWarpOptions );
|
||||||
CPLErrorReset();
|
CPLErrorReset();
|
||||||
CPLErr myErr;
|
CPLErr myErr;
|
||||||
myErr = myOperation.ChunkAndWarpImage( 0, 0, thePixelWidth, thePixelHeight );
|
myErr = myOperation.ChunkAndWarpImage( 0, 0, thePixelWidth, thePixelHeight );
|
||||||
if ( myErr != CPLE_None )
|
if ( myErr != CPLE_None )
|
||||||
{
|
{
|
||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot ChunkAndWarpImage : " )
|
QObject::tr( "Cannot ChunkAndWarpImage : " )
|
||||||
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
+ QString::fromUtf8( CPLGetLastErrorMsg() ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GDALDestroyGenImgProjTransformer( myWarpOptions->pTransformerArg );
|
GDALDestroyGenImgProjTransformer( myWarpOptions->pTransformerArg );
|
||||||
GDALDestroyWarpOptions( myWarpOptions );
|
GDALDestroyWarpOptions( myWarpOptions );
|
||||||
|
|
||||||
// flush should not be necessary
|
// flush should not be necessary
|
||||||
//GDALFlushCache ( myGdalMemDataset );
|
//GDALFlushCache ( myGdalMemDataset );
|
||||||
// this was causing crash ???
|
// this was causing crash ???
|
||||||
// The MEM driver does not free() the memory passed as DATAPOINTER so we can closee the dataset
|
// The MEM driver does not free() the memory passed as DATAPOINTER so we can closee the dataset
|
||||||
GDALClose( myGdalMemDataset );
|
GDALClose( myGdalMemDataset );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double QgsGdalProvider::noDataValue() const {
|
double QgsGdalProvider::noDataValue() const
|
||||||
if ( mNoDataValue.size () > 0 ) {
|
{
|
||||||
|
if ( mNoDataValue.size() > 0 )
|
||||||
|
{
|
||||||
return mNoDataValue[0];
|
return mNoDataValue[0];
|
||||||
}
|
}
|
||||||
return std::numeric_limits<int>::max(); // should not happen or be used
|
return std::numeric_limits<int>::max(); // should not happen or be used
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsGdalProvider::computeMinMax ( int theBandNo )
|
void QgsGdalProvider::computeMinMax( int theBandNo )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString("theBandNo = %1 mMinMaxComputed = %2").arg(theBandNo).arg(mMinMaxComputed[theBandNo-1]) );
|
QgsDebugMsg( QString( "theBandNo = %1 mMinMaxComputed = %2" ).arg( theBandNo ).arg( mMinMaxComputed[theBandNo-1] ) );
|
||||||
if ( mMinMaxComputed[theBandNo-1] ) return;
|
if ( mMinMaxComputed[theBandNo-1] ) return;
|
||||||
double GDALrange[2];
|
double GDALrange[2];
|
||||||
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
||||||
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange ); //Approximate
|
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange ); //Approximate
|
||||||
QgsDebugMsg( QString("GDALrange[0] = %1 GDALrange[1] = %2").arg(GDALrange[0]).arg(GDALrange[1]) );
|
QgsDebugMsg( QString( "GDALrange[0] = %1 GDALrange[1] = %2" ).arg( GDALrange[0] ).arg( GDALrange[1] ) );
|
||||||
mMinimum[theBandNo-1] = GDALrange[0];
|
mMinimum[theBandNo-1] = GDALrange[0];
|
||||||
mMaximum[theBandNo-1] = GDALrange[1];
|
mMaximum[theBandNo-1] = GDALrange[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
double QgsGdalProvider::minimumValue( int theBandNo ) const
|
double QgsGdalProvider::minimumValue( int theBandNo ) const
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString("theBandNo = %1").arg(theBandNo) );
|
QgsDebugMsg( QString( "theBandNo = %1" ).arg( theBandNo ) );
|
||||||
//computeMinMax ( theBandNo );
|
//computeMinMax ( theBandNo );
|
||||||
return mMinimum[theBandNo-1];
|
return mMinimum[theBandNo-1];
|
||||||
}
|
}
|
||||||
double QgsGdalProvider::maximumValue( int theBandNo ) const
|
double QgsGdalProvider::maximumValue( int theBandNo ) const
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QString("theBandNo = %1").arg(theBandNo) );
|
QgsDebugMsg( QString( "theBandNo = %1" ).arg( theBandNo ) );
|
||||||
//computeMinMax ( theBandNo );
|
//computeMinMax ( theBandNo );
|
||||||
return mMaximum[theBandNo-1];
|
return mMaximum[theBandNo-1];
|
||||||
}
|
}
|
||||||
@ -682,11 +681,11 @@ double QgsGdalProvider::maximumValue( int theBandNo ) const
|
|||||||
* @param theList a pointer the object that will hold the color table
|
* @param theList a pointer the object that will hold the color table
|
||||||
* @return true of a color table was able to be read, false otherwise
|
* @return true of a color table was able to be read, false otherwise
|
||||||
*/
|
*/
|
||||||
QList<QgsColorRampShader::ColorRampItem> QgsGdalProvider::colorTable(int theBandNumber)const
|
QList<QgsColorRampShader::ColorRampItem> QgsGdalProvider::colorTable( int theBandNumber )const
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "entered." );
|
QgsDebugMsg( "entered." );
|
||||||
QList<QgsColorRampShader::ColorRampItem> ct;
|
QList<QgsColorRampShader::ColorRampItem> ct;
|
||||||
|
|
||||||
|
|
||||||
//Invalid band number, segfault prevention
|
//Invalid band number, segfault prevention
|
||||||
if ( 0 >= theBandNumber )
|
if ( 0 >= theBandNumber )
|
||||||
@ -784,14 +783,16 @@ QgsRectangle QgsGdalProvider::extent()
|
|||||||
|
|
||||||
// this is only called once when statistics are calculated
|
// this is only called once when statistics are calculated
|
||||||
// TODO
|
// TODO
|
||||||
int QgsGdalProvider::xBlockSize() const {
|
int QgsGdalProvider::xBlockSize() const
|
||||||
return mXBlockSize;
|
{
|
||||||
}
|
return mXBlockSize;
|
||||||
int QgsGdalProvider::yBlockSize() const {
|
}
|
||||||
return mYBlockSize;
|
int QgsGdalProvider::yBlockSize() const
|
||||||
|
{
|
||||||
|
return mYBlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsGdalProvider::xSize() const { return mWidth; }
|
int QgsGdalProvider::xSize() const { return mWidth; }
|
||||||
int QgsGdalProvider::ySize() const { return mHeight; }
|
int QgsGdalProvider::ySize() const { return mHeight; }
|
||||||
|
|
||||||
bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
|
bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
|
||||||
@ -826,7 +827,7 @@ bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>
|
|||||||
double value;
|
double value;
|
||||||
|
|
||||||
CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
|
CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
|
||||||
&value, 1, 1, GDT_Float64, 0, 0 );
|
&value, 1, 1, GDT_Float64, 0, 0 );
|
||||||
|
|
||||||
if ( err != CPLE_None )
|
if ( err != CPLE_None )
|
||||||
{
|
{
|
||||||
@ -859,18 +860,19 @@ bool QgsGdalProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>
|
|||||||
|
|
||||||
int QgsGdalProvider::capabilities() const
|
int QgsGdalProvider::capabilities() const
|
||||||
{
|
{
|
||||||
int capability = QgsRasterDataProvider::Identify
|
int capability = QgsRasterDataProvider::Identify
|
||||||
| QgsRasterDataProvider::ExactResolution
|
| QgsRasterDataProvider::ExactResolution
|
||||||
| QgsRasterDataProvider::EstimatedMinimumMaximum
|
| QgsRasterDataProvider::EstimatedMinimumMaximum
|
||||||
| QgsRasterDataProvider::BuildPyramids
|
| QgsRasterDataProvider::BuildPyramids
|
||||||
| QgsRasterDataProvider::Histogram
|
| QgsRasterDataProvider::Histogram
|
||||||
| QgsRasterDataProvider::Size;
|
| QgsRasterDataProvider::Size;
|
||||||
return capability;
|
return capability;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
|
int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
|
||||||
{
|
{
|
||||||
switch ( theGdalDataType ) {
|
switch ( theGdalDataType )
|
||||||
|
{
|
||||||
case GDT_Unknown:
|
case GDT_Unknown:
|
||||||
return QgsRasterDataProvider::UnknownDataType;
|
return QgsRasterDataProvider::UnknownDataType;
|
||||||
break;
|
break;
|
||||||
@ -916,23 +918,24 @@ int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const
|
|||||||
|
|
||||||
int QgsGdalProvider::srcDataType( int bandNo ) const
|
int QgsGdalProvider::srcDataType( int bandNo ) const
|
||||||
{
|
{
|
||||||
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo );
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo );
|
||||||
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
|
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand );
|
||||||
return dataTypeFormGdal ( myGdalDataType );
|
return dataTypeFormGdal( myGdalDataType );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsGdalProvider::dataType( int bandNo ) const
|
int QgsGdalProvider::dataType( int bandNo ) const
|
||||||
{
|
{
|
||||||
return dataTypeFormGdal ( mGdalDataType[bandNo-1] );
|
return dataTypeFormGdal( mGdalDataType[bandNo-1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsGdalProvider::bandCount() const
|
int QgsGdalProvider::bandCount() const
|
||||||
{
|
{
|
||||||
return GDALGetRasterCount( mGdalDataset);
|
return GDALGetRasterCount( mGdalDataset );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsGdalProvider::colorInterpretation ( int theBandNo ) const {
|
int QgsGdalProvider::colorInterpretation( int theBandNo ) const
|
||||||
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
{
|
||||||
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
|
||||||
return GDALGetRasterColorInterpretation( myGdalBand );
|
return GDALGetRasterColorInterpretation( myGdalBand );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,7 +948,7 @@ void QgsGdalProvider::registerGdalDrivers()
|
|||||||
|
|
||||||
bool QgsGdalProvider::isValid()
|
bool QgsGdalProvider::isValid()
|
||||||
{
|
{
|
||||||
QgsDebugMsg ( QString("valid = %1").arg(mValid));
|
QgsDebugMsg( QString( "valid = %1" ).arg( mValid ) );
|
||||||
return mValid;
|
return mValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1061,8 +1064,8 @@ void QgsGdalProvider::populateHistogram( int theBandNo, QgsRasterBandStats & t
|
|||||||
* @param theTryInternalFlag - Try to make the pyramids internal if supported (e.g. geotiff). If not supported it will revert to creating external .ovr file anyway.
|
* @param theTryInternalFlag - Try to make the pyramids internal if supported (e.g. geotiff). If not supported it will revert to creating external .ovr file anyway.
|
||||||
* @return null string on success, otherwise a string specifying error
|
* @return null string on success, otherwise a string specifying error
|
||||||
*/
|
*/
|
||||||
QString QgsGdalProvider::buildPyramids( QList<QgsRasterPyramid> const & theRasterPyramidList,
|
QString QgsGdalProvider::buildPyramids( QList<QgsRasterPyramid> const & theRasterPyramidList,
|
||||||
QString const & theResamplingMethod, bool theTryInternalFlag )
|
QString const & theResamplingMethod, bool theTryInternalFlag )
|
||||||
{
|
{
|
||||||
//TODO: Consider making theRasterPyramidList modifyable by this method to indicate if the pyramid exists after build attempt
|
//TODO: Consider making theRasterPyramidList modifyable by this method to indicate if the pyramid exists after build attempt
|
||||||
//without requiring the user to rebuild the pyramid list to get the updated infomation
|
//without requiring the user to rebuild the pyramid list to get the updated infomation
|
||||||
@ -1352,7 +1355,7 @@ QGISEXTERN bool isProvider()
|
|||||||
*/
|
*/
|
||||||
QGISEXTERN void buildSupportedRasterFileFilter( QString & theFileFiltersString )
|
QGISEXTERN void buildSupportedRasterFileFilter( QString & theFileFiltersString )
|
||||||
{
|
{
|
||||||
QgsDebugMsg("Entered");
|
QgsDebugMsg( "Entered" );
|
||||||
// first get the GDAL driver manager
|
// first get the GDAL driver manager
|
||||||
//registerGdalDrivers();
|
//registerGdalDrivers();
|
||||||
|
|
||||||
|
@ -186,14 +186,14 @@ class QgsGdalProvider : public QgsRasterDataProvider
|
|||||||
*/
|
*/
|
||||||
int capabilities() const;
|
int capabilities() const;
|
||||||
|
|
||||||
int dataType ( int bandNo ) const;
|
int dataType( int bandNo ) const;
|
||||||
int srcDataType ( int bandNo ) const;
|
int srcDataType( int bandNo ) const;
|
||||||
|
|
||||||
int dataTypeFormGdal ( int theGdalDataType ) const;
|
int dataTypeFormGdal( int theGdalDataType ) const;
|
||||||
|
|
||||||
int bandCount() const;
|
int bandCount() const;
|
||||||
|
|
||||||
int colorInterpretation ( int bandNo ) const;
|
int colorInterpretation( int bandNo ) const;
|
||||||
|
|
||||||
int xBlockSize() const;
|
int xBlockSize() const;
|
||||||
int yBlockSize() const;
|
int yBlockSize() const;
|
||||||
@ -206,18 +206,18 @@ class QgsGdalProvider : public QgsRasterDataProvider
|
|||||||
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
|
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
|
||||||
|
|
||||||
double noDataValue() const;
|
double noDataValue() const;
|
||||||
void computeMinMax(int bandNo);
|
void computeMinMax( int bandNo );
|
||||||
double minimumValue(int bandNo) const;
|
double minimumValue( int bandNo ) const;
|
||||||
double maximumValue(int bandNo) const;
|
double maximumValue( int bandNo ) const;
|
||||||
|
|
||||||
QList<QgsColorRampShader::ColorRampItem> colorTable(int bandNo)const;
|
QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get metadata in a format suitable for feeding directly
|
* Get metadata in a format suitable for feeding directly
|
||||||
* into a subset of the GUI raster properties "Metadata" tab.
|
* into a subset of the GUI raster properties "Metadata" tab.
|
||||||
*/
|
*/
|
||||||
QString metadata();
|
QString metadata();
|
||||||
|
|
||||||
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
|
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
|
||||||
void addLayers( QStringList const & layers, QStringList const & styles = QStringList() ) {}
|
void addLayers( QStringList const & layers, QStringList const & styles = QStringList() ) {}
|
||||||
@ -233,11 +233,11 @@ class QgsGdalProvider : public QgsRasterDataProvider
|
|||||||
QStringList subLayers() const;
|
QStringList subLayers() const;
|
||||||
|
|
||||||
void populateHistogram( int theBandNoInt,
|
void populateHistogram( int theBandNoInt,
|
||||||
QgsRasterBandStats & theBandStats,
|
QgsRasterBandStats & theBandStats,
|
||||||
int theBinCountInt = 256,
|
int theBinCountInt = 256,
|
||||||
bool theIgnoreOutOfRangeFlag = true,
|
bool theIgnoreOutOfRangeFlag = true,
|
||||||
bool theThoroughBandScanFlag = false
|
bool theThoroughBandScanFlag = false
|
||||||
);
|
);
|
||||||
|
|
||||||
QString buildPyramids( const QList<QgsRasterPyramid> &,
|
QString buildPyramids( const QList<QgsRasterPyramid> &,
|
||||||
const QString & theResamplingMethod = "NEAREST",
|
const QString & theResamplingMethod = "NEAREST",
|
||||||
@ -258,9 +258,9 @@ class QgsGdalProvider : public QgsRasterDataProvider
|
|||||||
/** \brief Whether this raster has overviews / pyramids or not */
|
/** \brief Whether this raster has overviews / pyramids or not */
|
||||||
bool mHasPyramids;
|
bool mHasPyramids;
|
||||||
|
|
||||||
/** \brief Gdal data types used to represent data in in QGIS,
|
/** \brief Gdal data types used to represent data in in QGIS,
|
||||||
may be longer than source data type to keep nulls
|
may be longer than source data type to keep nulls
|
||||||
indexed from 0
|
indexed from 0
|
||||||
*/
|
*/
|
||||||
QList<int>mGdalDataType;
|
QList<int>mGdalDataType;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ int main( int argc, char **argv )
|
|||||||
G_adjust_Cell_head( &window, 1, 1 );
|
G_adjust_Cell_head( &window, 1, 1 );
|
||||||
G_set_window( &window );
|
G_set_window( &window );
|
||||||
|
|
||||||
raster_type = G_raster_map_type ( name, "" );
|
raster_type = G_raster_map_type( name, "" );
|
||||||
fp = G_raster_map_is_fp( name, mapset );
|
fp = G_raster_map_is_fp( name, mapset );
|
||||||
|
|
||||||
/* use DCELL even if the map is FCELL */
|
/* use DCELL even if the map is FCELL */
|
||||||
@ -180,7 +180,7 @@ static int cell_draw( char *name,
|
|||||||
alpha = 0;
|
alpha = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strcmp(format,"color") == 0 )
|
if ( strcmp( format, "color" ) == 0 )
|
||||||
{
|
{
|
||||||
// We need data suitable for QImage 32-bpp
|
// We need data suitable for QImage 32-bpp
|
||||||
// the data are stored in QImage as QRgb which is unsigned int.
|
// the data are stored in QImage as QRgb which is unsigned int.
|
||||||
@ -198,28 +198,35 @@ static int cell_draw( char *name,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int *val;
|
int *val;
|
||||||
val = (int*) (ptr);
|
val = ( int* )( ptr );
|
||||||
//G_debug ( 0, "val = %d", *val );
|
//G_debug ( 0, "val = %d", *val );
|
||||||
if ( data_type == CELL_TYPE) {
|
if ( data_type == CELL_TYPE )
|
||||||
//G_debug ( 0, "valx = %d", *((CELL *) ptr));
|
{
|
||||||
}
|
//G_debug ( 0, "valx = %d", *((CELL *) ptr));
|
||||||
if ( G_is_null_value(ptr, data_type) ) {
|
}
|
||||||
if ( data_type == CELL_TYPE) {
|
if ( G_is_null_value( ptr, data_type ) )
|
||||||
int nul = -2147483647;
|
{
|
||||||
fwrite( &nul , 4, 1, fo );
|
if ( data_type == CELL_TYPE )
|
||||||
} else if ( data_type == DCELL_TYPE) {
|
|
||||||
double nul = 2.2250738585072014e-308;
|
|
||||||
fwrite( &nul , 8, 1, fo );
|
|
||||||
} else if ( data_type == FCELL_TYPE) {
|
|
||||||
double nul = 1.17549435e-38F;
|
|
||||||
fwrite( &nul , 4, 1, fo );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
fwrite( ptr, raster_size, 1, fo );
|
int nul = -2147483647;
|
||||||
|
fwrite( &nul , 4, 1, fo );
|
||||||
}
|
}
|
||||||
|
else if ( data_type == DCELL_TYPE )
|
||||||
|
{
|
||||||
|
double nul = 2.2250738585072014e-308;
|
||||||
|
fwrite( &nul , 8, 1, fo );
|
||||||
|
}
|
||||||
|
else if ( data_type == FCELL_TYPE )
|
||||||
|
{
|
||||||
|
double nul = 1.17549435e-38F;
|
||||||
|
fwrite( &nul , 4, 1, fo );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fwrite( ptr, raster_size, 1, fo );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ptr = G_incr_void_ptr( ptr, raster_size );
|
ptr = G_incr_void_ptr( ptr, raster_size );
|
||||||
}
|
}
|
||||||
|
@ -95,44 +95,45 @@ int main( int argc, char **argv )
|
|||||||
// raster informations
|
// raster informations
|
||||||
else if ( strcmp( "info", info_opt->answer ) == 0 )
|
else if ( strcmp( "info", info_opt->answer ) == 0 )
|
||||||
{
|
{
|
||||||
struct FPRange range;
|
struct FPRange range;
|
||||||
double zmin, zmax;
|
double zmin, zmax;
|
||||||
|
|
||||||
// Data type
|
// Data type
|
||||||
RASTER_MAP_TYPE raster_type = G_raster_map_type ( rast_opt->answer, "" );
|
RASTER_MAP_TYPE raster_type = G_raster_map_type( rast_opt->answer, "" );
|
||||||
fprintf( stdout, "TYPE:%d\n", raster_type );
|
fprintf( stdout, "TYPE:%d\n", raster_type );
|
||||||
|
|
||||||
// Statistics
|
// Statistics
|
||||||
if (G_read_fp_range( rast_opt->answer, "", &range) < 0) {
|
if ( G_read_fp_range( rast_opt->answer, "", &range ) < 0 )
|
||||||
G_fatal_error(("Unable to read range file"));
|
{
|
||||||
}
|
G_fatal_error(( "Unable to read range file" ) );
|
||||||
G_get_fp_range_min_max(&range, &zmin, &zmax);
|
}
|
||||||
fprintf( stdout, "MIN_VALUE:%f\n", zmin );
|
G_get_fp_range_min_max( &range, &zmin, &zmax );
|
||||||
fprintf( stdout, "MAX_VALUE:%f\n", zmax );
|
fprintf( stdout, "MIN_VALUE:%f\n", zmin );
|
||||||
|
fprintf( stdout, "MAX_VALUE:%f\n", zmax );
|
||||||
}
|
}
|
||||||
else if ( strcmp( "colors", info_opt->answer ) == 0 )
|
else if ( strcmp( "colors", info_opt->answer ) == 0 )
|
||||||
{
|
{
|
||||||
// Color table
|
// Color table
|
||||||
struct Colors colors;
|
struct Colors colors;
|
||||||
int i, ccount;
|
int i, ccount;
|
||||||
if( G_read_colors( rast_opt->answer, "", &colors ) == 1 )
|
if ( G_read_colors( rast_opt->answer, "", &colors ) == 1 )
|
||||||
{
|
{
|
||||||
//int maxcolor;
|
//int maxcolor;
|
||||||
//CELL min, max;
|
//CELL min, max;
|
||||||
|
|
||||||
//G_get_color_range ( &min, &max, &colors);
|
|
||||||
ccount = G_colors_count ( &colors );
|
|
||||||
for( i = ccount-1; i >= 0; i-- )
|
|
||||||
{
|
|
||||||
DCELL val1, val2;
|
|
||||||
unsigned char r1, g1, b1, r2, g2, b2;
|
|
||||||
|
|
||||||
G_get_f_color_rule ( &val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2, &colors, i );
|
//G_get_color_range ( &min, &max, &colors);
|
||||||
fprintf ( stdout, "%e %e %d %d %d %d %d %d\n", val1, val2, r1, g1, b1, r2, g2, b2 );
|
ccount = G_colors_count( &colors );
|
||||||
}
|
for ( i = ccount - 1; i >= 0; i-- )
|
||||||
}
|
{
|
||||||
|
DCELL val1, val2;
|
||||||
|
unsigned char r1, g1, b1, r2, g2, b2;
|
||||||
|
|
||||||
|
G_get_f_color_rule( &val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2, &colors, i );
|
||||||
|
fprintf( stdout, "%e %e %d %d %d %d %d %d\n", val1, val2, r1, g1, b1, r2, g2, b2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( strcmp( "query", info_opt->answer ) == 0 )
|
else if ( strcmp( "query", info_opt->answer ) == 0 )
|
||||||
{
|
{
|
||||||
double x, y;
|
double x, y;
|
||||||
|
@ -1194,7 +1194,7 @@ void GRASS_EXPORT QgsGrass::size( QString gisdbase, QString location, QString ma
|
|||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot get raster extent" ) + "\n" + e.what() );
|
QObject::tr( "Cannot get raster extent" ) + "\n" + e.what() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsDebugMsg( QString( "raster size = %1 %2" ).arg( *cols ).arg( *rows ) );
|
QgsDebugMsg( QString( "raster size = %1 %2" ).arg( *cols ).arg( *rows ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1208,8 +1208,9 @@ QHash<QString, QString> GRASS_EXPORT QgsGrass::info( QString gisdbase, QString l
|
|||||||
QString str = QgsGrass::getInfo( "info", gisdbase, location, mapset, map, type );
|
QString str = QgsGrass::getInfo( "info", gisdbase, location, mapset, map, type );
|
||||||
QgsDebugMsg( str );
|
QgsDebugMsg( str );
|
||||||
QStringList list = str.split( "\n" );
|
QStringList list = str.split( "\n" );
|
||||||
for ( int i = 0; i < list.size(); i++ ) {
|
for ( int i = 0; i < list.size(); i++ )
|
||||||
QStringList keyVal = list[i].split(':');
|
{
|
||||||
|
QStringList keyVal = list[i].split( ':' );
|
||||||
if ( list[i].isEmpty() ) { continue; }
|
if ( list[i].isEmpty() ) { continue; }
|
||||||
if ( keyVal.size() != 2 )
|
if ( keyVal.size() != 2 )
|
||||||
{
|
{
|
||||||
@ -1223,7 +1224,7 @@ QHash<QString, QString> GRASS_EXPORT QgsGrass::info( QString gisdbase, QString l
|
|||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot get map info" ) + "\n" + e.what() );
|
QObject::tr( "Cannot get map info" ) + "\n" + e.what() );
|
||||||
}
|
}
|
||||||
return inf;
|
return inf;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QgsGrass::Color> GRASS_EXPORT QgsGrass::colors( QString gisdbase, QString location, QString mapset, QString map )
|
QList<QgsGrass::Color> GRASS_EXPORT QgsGrass::colors( QString gisdbase, QString location, QString mapset, QString map )
|
||||||
@ -1236,16 +1237,15 @@ QList<QgsGrass::Color> GRASS_EXPORT QgsGrass::colors( QString gisdbase, QString
|
|||||||
QString str = QgsGrass::getInfo( "colors", gisdbase, location, mapset, map, QgsGrass::Raster );
|
QString str = QgsGrass::getInfo( "colors", gisdbase, location, mapset, map, QgsGrass::Raster );
|
||||||
QgsDebugMsg( str );
|
QgsDebugMsg( str );
|
||||||
QStringList list = str.split( "\n" );
|
QStringList list = str.split( "\n" );
|
||||||
for ( int i = 0; i < list.size(); i++ ) {
|
for ( int i = 0; i < list.size(); i++ )
|
||||||
double v1, v2;
|
{
|
||||||
int r1, r2, g1, g2, b1, b2;
|
|
||||||
QgsGrass::Color c;
|
QgsGrass::Color c;
|
||||||
if ( list[i].isEmpty() ) { continue; }
|
if ( list[i].isEmpty() ) { continue; }
|
||||||
if ( sscanf( list[i].toUtf8().data(), "%lf %lf %d %d %d %d %d %d", &(c.value1), &(c.value2), &(c.red1), &(c.green1), &(c.blue1), &(c.red2), &(c.green2), &(c.blue2) ) != 8 )
|
if ( sscanf( list[i].toUtf8().data(), "%lf %lf %d %d %d %d %d %d", &( c.value1 ), &( c.value2 ), &( c.red1 ), &( c.green1 ), &( c.blue1 ), &( c.red2 ), &( c.green2 ), &( c.blue2 ) ) != 8 )
|
||||||
{
|
{
|
||||||
throw QgsGrass::Exception( "Cannot parse GRASS colors" + list[i] + " (" + str + " ) " );
|
throw QgsGrass::Exception( "Cannot parse GRASS colors" + list[i] + " (" + str + " ) " );
|
||||||
}
|
}
|
||||||
ct.append( c);
|
ct.append( c );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( QgsGrass::Exception &e )
|
catch ( QgsGrass::Exception &e )
|
||||||
@ -1253,7 +1253,7 @@ QList<QgsGrass::Color> GRASS_EXPORT QgsGrass::colors( QString gisdbase, QString
|
|||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
QObject::tr( "Cannot get colors" ) + "\n" + e.what() );
|
QObject::tr( "Cannot get colors" ) + "\n" + e.what() );
|
||||||
}
|
}
|
||||||
return ct;
|
return ct;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QString> GRASS_EXPORT QgsGrass::query( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
|
QMap<QString, QString> GRASS_EXPORT QgsGrass::query( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
|
||||||
|
@ -52,7 +52,8 @@ class QgsGrass
|
|||||||
Exception( const QString &msg ) : std::runtime_error( msg.toUtf8().constData() ) {}
|
Exception( const QString &msg ) : std::runtime_error( msg.toUtf8().constData() ) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Color {
|
struct Color
|
||||||
|
{
|
||||||
double value1, value2;
|
double value1, value2;
|
||||||
int red1, red2, green1, green2, blue1, blue2;
|
int red1, red2, green1, green2, blue1, blue2;
|
||||||
};
|
};
|
||||||
@ -196,7 +197,7 @@ class QgsGrass
|
|||||||
|
|
||||||
// ! Get raster map size
|
// ! Get raster map size
|
||||||
static GRASS_EXPORT void size( QString gisdbase, QString location,
|
static GRASS_EXPORT void size( QString gisdbase, QString location,
|
||||||
QString mapset, QString map, int *cols, int *rows );
|
QString mapset, QString map, int *cols, int *rows );
|
||||||
|
|
||||||
// ! Get raster info
|
// ! Get raster info
|
||||||
static GRASS_EXPORT QHash<QString, QString> info( QString gisdbase, QString location,
|
static GRASS_EXPORT QHash<QString, QString> info( QString gisdbase, QString location,
|
||||||
|
@ -76,7 +76,7 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
|
|||||||
QgsDebugMsg( QString( "mapset: %1" ).arg( mMapset ) );
|
QgsDebugMsg( QString( "mapset: %1" ).arg( mMapset ) );
|
||||||
QgsDebugMsg( QString( "mapName: %1" ).arg( mMapName ) );
|
QgsDebugMsg( QString( "mapName: %1" ).arg( mMapName ) );
|
||||||
|
|
||||||
mValidNoDataValue = true;
|
mValidNoDataValue = true;
|
||||||
|
|
||||||
mCrs = QgsGrass::crs( mGisdbase, mLocation );
|
mCrs = QgsGrass::crs( mGisdbase, mLocation );
|
||||||
|
|
||||||
@ -91,15 +91,15 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
|
|||||||
|
|
||||||
// TODO: refresh mRows and mCols if raster was rewritten
|
// TODO: refresh mRows and mCols if raster was rewritten
|
||||||
// We have to decide some reasonable block size, not to big to occupate too much
|
// We have to decide some reasonable block size, not to big to occupate too much
|
||||||
// memory, not too small to result in too many calls to readBlock -> qgis.d.rast
|
// memory, not too small to result in too many calls to readBlock -> qgis.d.rast
|
||||||
// for statistics
|
// for statistics
|
||||||
int cache_size = 10000000; // ~ 10 MB
|
int cache_size = 10000000; // ~ 10 MB
|
||||||
mYBlockSize = cache_size / (dataTypeSize(dataType ( 1 ) )/8) / mCols;
|
mYBlockSize = cache_size / ( dataTypeSize( dataType( 1 ) ) / 8 ) / mCols;
|
||||||
if ( mYBlockSize > mRows )
|
if ( mYBlockSize > mRows )
|
||||||
{
|
{
|
||||||
mYBlockSize = mRows;
|
mYBlockSize = mRows;
|
||||||
}
|
}
|
||||||
QgsDebugMsg( "mYBlockSize = " + QString::number ( mYBlockSize ) );
|
QgsDebugMsg( "mYBlockSize = " + QString::number( mYBlockSize ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsGrassRasterProvider::~QgsGrassRasterProvider()
|
QgsGrassRasterProvider::~QgsGrassRasterProvider()
|
||||||
@ -153,7 +153,7 @@ void QgsGrassRasterProvider::readBlock( int bandNo, int xBlock, int yBlock, void
|
|||||||
{
|
{
|
||||||
QgsDebugMsg( "Entered" );
|
QgsDebugMsg( "Entered" );
|
||||||
// TODO: optimize, see extent()
|
// TODO: optimize, see extent()
|
||||||
|
|
||||||
QgsDebugMsg( "yBlock = " + QString::number( yBlock ) );
|
QgsDebugMsg( "yBlock = " + QString::number( yBlock ) );
|
||||||
|
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
@ -167,13 +167,13 @@ void QgsGrassRasterProvider::readBlock( int bandNo, int xBlock, int yBlock, void
|
|||||||
double yMaximum = ext.yMaximum() - cellHeight * yBlock * mYBlockSize;
|
double yMaximum = ext.yMaximum() - cellHeight * yBlock * mYBlockSize;
|
||||||
double yMinimum = yMaximum - cellHeight * mYBlockSize;
|
double yMinimum = yMaximum - cellHeight * mYBlockSize;
|
||||||
|
|
||||||
QgsDebugMsg( "mYBlockSize = " + QString::number ( mYBlockSize ) );
|
QgsDebugMsg( "mYBlockSize = " + QString::number( mYBlockSize ) );
|
||||||
arguments.append(( QString( "window=%1,%2,%3,%4,%5,%6" )
|
arguments.append(( QString( "window=%1,%2,%3,%4,%5,%6" )
|
||||||
.arg( ext.xMinimum() ).arg( yMinimum )
|
.arg( ext.xMinimum() ).arg( yMinimum )
|
||||||
.arg( ext.xMaximum() ).arg( yMaximum )
|
.arg( ext.xMaximum() ).arg( yMaximum )
|
||||||
.arg( mCols ).arg( mYBlockSize ) ) );
|
.arg( mCols ).arg( mYBlockSize ) ) );
|
||||||
|
|
||||||
arguments.append( "format=value");
|
arguments.append( "format=value" );
|
||||||
QProcess process( this );
|
QProcess process( this );
|
||||||
QString cmd = QgsApplication::prefixPath() + "/" QGIS_LIBEXEC_SUBDIR "/grass/modules/qgis.d.rast";
|
QString cmd = QgsApplication::prefixPath() + "/" QGIS_LIBEXEC_SUBDIR "/grass/modules/qgis.d.rast";
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
@ -191,13 +191,14 @@ void QgsGrassRasterProvider::readBlock( int bandNo, int xBlock, int yBlock, void
|
|||||||
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
|
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
|
||||||
// byteCount() in Qt >= 4.6
|
// byteCount() in Qt >= 4.6
|
||||||
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
|
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
|
||||||
int size = mCols * mYBlockSize * dataTypeSize(bandNo) / 8;
|
int size = mCols * mYBlockSize * dataTypeSize( bandNo ) / 8;
|
||||||
QgsDebugMsg ( QString ( "mCols = %1 mYBlockSize = %2 dataTypeSize = %3" ).arg ( mCols ).arg ( mYBlockSize ).arg ( dataTypeSize(bandNo) ) );
|
QgsDebugMsg( QString( "mCols = %1 mYBlockSize = %2 dataTypeSize = %3" ).arg( mCols ).arg( mYBlockSize ).arg( dataTypeSize( bandNo ) ) );
|
||||||
if ( size != data.size() ) {
|
if ( size != data.size() )
|
||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
{
|
||||||
QString( "%1 bytes expected but %2 byte were read from qgis.d.rast" ).arg(size).arg(data.size() ) );
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
|
QString( "%1 bytes expected but %2 byte were read from qgis.d.rast" ).arg( size ).arg( data.size() ) );
|
||||||
size = size < data.size() ? size : data.size();
|
size = size < data.size() ? size : data.size();
|
||||||
}
|
}
|
||||||
memcpy( block, data.data(), size );
|
memcpy( block, data.data(), size );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +216,7 @@ void QgsGrassRasterProvider::readBlock( int bandNo, QgsRectangle const & viewEx
|
|||||||
.arg( viewExtent.xMinimum() ).arg( viewExtent.yMinimum() )
|
.arg( viewExtent.xMinimum() ).arg( viewExtent.yMinimum() )
|
||||||
.arg( viewExtent.xMaximum() ).arg( viewExtent.yMaximum() )
|
.arg( viewExtent.xMaximum() ).arg( viewExtent.yMaximum() )
|
||||||
.arg( pixelWidth ).arg( pixelHeight ) ) );
|
.arg( pixelWidth ).arg( pixelHeight ) ) );
|
||||||
arguments.append( "format=value");
|
arguments.append( "format=value" );
|
||||||
QProcess process( this );
|
QProcess process( this );
|
||||||
QString cmd = QgsApplication::prefixPath() + "/" QGIS_LIBEXEC_SUBDIR "/grass/modules/qgis.d.rast";
|
QString cmd = QgsApplication::prefixPath() + "/" QGIS_LIBEXEC_SUBDIR "/grass/modules/qgis.d.rast";
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
@ -234,61 +235,72 @@ void QgsGrassRasterProvider::readBlock( int bandNo, QgsRectangle const & viewEx
|
|||||||
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
|
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
|
||||||
// byteCount() in Qt >= 4.6
|
// byteCount() in Qt >= 4.6
|
||||||
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
|
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
|
||||||
int size = pixelWidth * pixelHeight * dataTypeSize(bandNo) / 8;
|
int size = pixelWidth * pixelHeight * dataTypeSize( bandNo ) / 8;
|
||||||
if ( size != data.size() ) {
|
if ( size != data.size() )
|
||||||
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
{
|
||||||
QString( "%1 bytes expected but %2 byte were read from qgis.d.rast" ).arg(size).arg(data.size() ) );
|
QMessageBox::warning( 0, QObject::tr( "Warning" ),
|
||||||
|
QString( "%1 bytes expected but %2 byte were read from qgis.d.rast" ).arg( size ).arg( data.size() ) );
|
||||||
size = size < data.size() ? size : data.size();
|
size = size < data.size() ? size : data.size();
|
||||||
}
|
}
|
||||||
memcpy( block, data.data(), size );
|
memcpy( block, data.data(), size );
|
||||||
}
|
}
|
||||||
|
|
||||||
double QgsGrassRasterProvider::noDataValue() const {
|
double QgsGrassRasterProvider::noDataValue() const
|
||||||
|
{
|
||||||
double nul;
|
double nul;
|
||||||
if ( mGrassDataType == CELL_TYPE ) {
|
if ( mGrassDataType == CELL_TYPE )
|
||||||
|
{
|
||||||
nul = -2147483647;
|
nul = -2147483647;
|
||||||
} else if ( mGrassDataType == DCELL_TYPE ) {
|
}
|
||||||
|
else if ( mGrassDataType == DCELL_TYPE )
|
||||||
|
{
|
||||||
nul = 2.2250738585072014e-308;
|
nul = 2.2250738585072014e-308;
|
||||||
} else if ( mGrassDataType == FCELL_TYPE ) {
|
}
|
||||||
|
else if ( mGrassDataType == FCELL_TYPE )
|
||||||
|
{
|
||||||
nul = 1.17549435e-38F;
|
nul = 1.17549435e-38F;
|
||||||
}
|
}
|
||||||
QgsDebugMsg( QString( "noDataValue = %1" ).arg( nul ) );
|
QgsDebugMsg( QString( "noDataValue = %1" ).arg( nul ) );
|
||||||
return nul;
|
return nul;
|
||||||
}
|
}
|
||||||
|
|
||||||
double QgsGrassRasterProvider::minimumValue( int bandNo ) const {
|
double QgsGrassRasterProvider::minimumValue( int bandNo ) const
|
||||||
|
{
|
||||||
return mInfo["MIN_VALUE"].toDouble();
|
return mInfo["MIN_VALUE"].toDouble();
|
||||||
}
|
}
|
||||||
double QgsGrassRasterProvider::maximumValue( int bandNo ) const {
|
double QgsGrassRasterProvider::maximumValue( int bandNo ) const
|
||||||
|
{
|
||||||
return mInfo["MAX_VALUE"].toDouble();
|
return mInfo["MAX_VALUE"].toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QgsColorRampShader::ColorRampItem> QgsGrassRasterProvider::colorTable(int bandNo)const {
|
QList<QgsColorRampShader::ColorRampItem> QgsGrassRasterProvider::colorTable( int bandNo )const
|
||||||
|
{
|
||||||
QList<QgsColorRampShader::ColorRampItem> ct;
|
QList<QgsColorRampShader::ColorRampItem> ct;
|
||||||
|
|
||||||
// TODO: check if color can be realy discontinuous in GRASS,
|
// TODO: check if color can be realy discontinuous in GRASS,
|
||||||
// for now we just believe that they are continuous, i.e. end and beginning
|
// for now we just believe that they are continuous, i.e. end and beginning
|
||||||
// of the ramp with the same value has the same color
|
// of the ramp with the same value has the same color
|
||||||
// we are also expecting ordered CT records in the list
|
// we are also expecting ordered CT records in the list
|
||||||
QList<QgsGrass::Color> colors = QgsGrass::colors( mGisdbase, mLocation, mMapset, mMapName );
|
QList<QgsGrass::Color> colors = QgsGrass::colors( mGisdbase, mLocation, mMapset, mMapName );
|
||||||
QList<QgsGrass::Color>::iterator i;
|
QList<QgsGrass::Color>::iterator i;
|
||||||
|
|
||||||
double v, r, g, b;
|
double v, r, g, b;
|
||||||
for (i = colors.begin(); i != colors.end(); ++i)
|
for ( i = colors.begin(); i != colors.end(); ++i )
|
||||||
{
|
{
|
||||||
if ( ct.count() == 0 || i->value1 != v || i->red1 != r || i->green1 != g || i->blue1 != b ) {
|
if ( ct.count() == 0 || i->value1 != v || i->red1 != r || i->green1 != g || i->blue1 != b )
|
||||||
|
{
|
||||||
// not added in previous rule
|
// not added in previous rule
|
||||||
QgsColorRampShader::ColorRampItem ctItem1;
|
QgsColorRampShader::ColorRampItem ctItem1;
|
||||||
ctItem1.value = i->value1;
|
ctItem1.value = i->value1;
|
||||||
ctItem1.color = QColor::fromRgb( i->red1, i->green1, i->blue1);
|
ctItem1.color = QColor::fromRgb( i->red1, i->green1, i->blue1 );
|
||||||
ct.append(ctItem1);
|
ct.append( ctItem1 );
|
||||||
QgsDebugMsg( QString("color %1 %2 %3 %4").arg(i->value1).arg(i->red1).arg(i->green1).arg(i->blue1) );
|
QgsDebugMsg( QString( "color %1 %2 %3 %4" ).arg( i->value1 ).arg( i->red1 ).arg( i->green1 ).arg( i->blue1 ) );
|
||||||
}
|
}
|
||||||
QgsColorRampShader::ColorRampItem ctItem2;
|
QgsColorRampShader::ColorRampItem ctItem2;
|
||||||
ctItem2.value = i->value2;
|
ctItem2.value = i->value2;
|
||||||
ctItem2.color = QColor::fromRgb( i->red2, i->green2, i->blue2);
|
ctItem2.color = QColor::fromRgb( i->red2, i->green2, i->blue2 );
|
||||||
ct.append(ctItem2);
|
ct.append( ctItem2 );
|
||||||
QgsDebugMsg( QString("color %1 %2 %3 %4").arg(i->value2).arg(i->red2).arg(i->green2).arg(i->blue2) );
|
QgsDebugMsg( QString( "color %1 %2 %3 %4" ).arg( i->value2 ).arg( i->red2 ).arg( i->green2 ).arg( i->blue2 ) );
|
||||||
|
|
||||||
v = i->value2; r = i->red2; g = i->green2; b = i->blue2;
|
v = i->value2; r = i->red2; g = i->green2; b = i->blue2;
|
||||||
}
|
}
|
||||||
@ -311,14 +323,15 @@ QgsRectangle QgsGrassRasterProvider::extent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is only called once when statistics are calculated
|
// this is only called once when statistics are calculated
|
||||||
int QgsGrassRasterProvider::xBlockSize() const { return mCols; }
|
int QgsGrassRasterProvider::xBlockSize() const { return mCols; }
|
||||||
int QgsGrassRasterProvider::yBlockSize() const {
|
int QgsGrassRasterProvider::yBlockSize() const
|
||||||
return mYBlockSize;
|
{
|
||||||
|
return mYBlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this should be always refreshed if raster has changed ?
|
// TODO this should be always refreshed if raster has changed ?
|
||||||
// maybe also only for stats
|
// maybe also only for stats
|
||||||
int QgsGrassRasterProvider::xSize() const { return mCols; }
|
int QgsGrassRasterProvider::xSize() const { return mCols; }
|
||||||
int QgsGrassRasterProvider::ySize() const { return mRows; }
|
int QgsGrassRasterProvider::ySize() const { return mRows; }
|
||||||
|
|
||||||
bool QgsGrassRasterProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
|
bool QgsGrassRasterProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
|
||||||
@ -331,10 +344,10 @@ bool QgsGrassRasterProvider::identify( const QgsPoint& thePoint, QMap<QString, Q
|
|||||||
|
|
||||||
int QgsGrassRasterProvider::capabilities() const
|
int QgsGrassRasterProvider::capabilities() const
|
||||||
{
|
{
|
||||||
int capability = QgsRasterDataProvider::Identify
|
int capability = QgsRasterDataProvider::Identify
|
||||||
| QgsRasterDataProvider::ExactResolution
|
| QgsRasterDataProvider::ExactResolution
|
||||||
| QgsRasterDataProvider::ExactMinimumMaximum
|
| QgsRasterDataProvider::ExactMinimumMaximum
|
||||||
| QgsRasterDataProvider::Size;
|
| QgsRasterDataProvider::Size;
|
||||||
return capability;
|
return capability;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +358,8 @@ int QgsGrassRasterProvider::dataType( int bandNo ) const
|
|||||||
|
|
||||||
int QgsGrassRasterProvider::srcDataType( int bandNo ) const
|
int QgsGrassRasterProvider::srcDataType( int bandNo ) const
|
||||||
{
|
{
|
||||||
switch ( mGrassDataType ) {
|
switch ( mGrassDataType )
|
||||||
|
{
|
||||||
case CELL_TYPE:
|
case CELL_TYPE:
|
||||||
return QgsRasterDataProvider::Int32;
|
return QgsRasterDataProvider::Int32;
|
||||||
break;
|
break;
|
||||||
@ -365,10 +379,12 @@ int QgsGrassRasterProvider::bandCount() const
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsGrassRasterProvider::colorInterpretation ( int bandNo ) const {
|
int QgsGrassRasterProvider::colorInterpretation( int bandNo ) const
|
||||||
|
{
|
||||||
// TODO: avoid loading color table here or cache it
|
// TODO: avoid loading color table here or cache it
|
||||||
QList<QgsColorRampShader::ColorRampItem> ct = colorTable(bandNo);
|
QList<QgsColorRampShader::ColorRampItem> ct = colorTable( bandNo );
|
||||||
if ( ct.size() > 0 ) {
|
if ( ct.size() > 0 )
|
||||||
|
{
|
||||||
return QgsRasterDataProvider::PaletteIndex;
|
return QgsRasterDataProvider::PaletteIndex;
|
||||||
}
|
}
|
||||||
return QgsRasterDataProvider::GrayIndex;
|
return QgsRasterDataProvider::GrayIndex;
|
||||||
@ -378,27 +394,27 @@ QString QgsGrassRasterProvider::metadata()
|
|||||||
{
|
{
|
||||||
QString myMetadata ;
|
QString myMetadata ;
|
||||||
QStringList myList;
|
QStringList myList;
|
||||||
myList.append ( "GISDBASE: " + mGisdbase );
|
myList.append( "GISDBASE: " + mGisdbase );
|
||||||
myList.append ( "LOCATION: " + mLocation );
|
myList.append( "LOCATION: " + mLocation );
|
||||||
myList.append ( "MAPSET: " + mMapset );
|
myList.append( "MAPSET: " + mMapset );
|
||||||
myList.append ( "MAP: " + mMapName );
|
myList.append( "MAP: " + mMapName );
|
||||||
|
|
||||||
QHash<QString, QString>::iterator i;
|
QHash<QString, QString>::iterator i;
|
||||||
for (i = mInfo.begin(); i != mInfo.end(); ++i)
|
for ( i = mInfo.begin(); i != mInfo.end(); ++i )
|
||||||
{
|
{
|
||||||
myList.append ( i.key() + " : " + i.value() );
|
myList.append( i.key() + " : " + i.value() );
|
||||||
}
|
}
|
||||||
myMetadata += QgsRasterDataProvider::makeTableCells( myList );
|
myMetadata += QgsRasterDataProvider::makeTableCells( myList );
|
||||||
|
|
||||||
|
|
||||||
return myMetadata;
|
return myMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsGrassRasterProvider::populateHistogram( int theBandNoInt,
|
void QgsGrassRasterProvider::populateHistogram( int theBandNoInt,
|
||||||
QgsRasterBandStats & theBandStats,
|
QgsRasterBandStats & theBandStats,
|
||||||
int theBinCount,
|
int theBinCount,
|
||||||
bool theIgnoreOutOfRangeFlag,
|
bool theIgnoreOutOfRangeFlag,
|
||||||
bool theHistogramEstimatedFlag)
|
bool theHistogramEstimatedFlag )
|
||||||
{
|
{
|
||||||
// TODO: we could either implement it in QgsRasterDataProvider::populateHistogram
|
// TODO: we could either implement it in QgsRasterDataProvider::populateHistogram
|
||||||
// or use r.stats (see d.histogram)
|
// or use r.stats (see d.histogram)
|
||||||
@ -414,8 +430,8 @@ void QgsGrassRasterProvider::populateHistogram( int theBandNoInt,
|
|||||||
theBandStats.histogramVector->push_back( 0 );
|
theBandStats.histogramVector->push_back( 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QgsDebugMsg( ">>>>> Histogram vector now contains " +
|
QgsDebugMsg( ">>>>> Histogram vector now contains " +
|
||||||
QString::number( theBandStats.histogramVector->size() ) + " elements" );
|
QString::number( theBandStats.histogramVector->size() ) + " elements" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,12 +177,12 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
|
|||||||
*/
|
*/
|
||||||
int capabilities() const;
|
int capabilities() const;
|
||||||
|
|
||||||
int dataType ( int bandNo ) const;
|
int dataType( int bandNo ) const;
|
||||||
int srcDataType ( int bandNo ) const;
|
int srcDataType( int bandNo ) const;
|
||||||
|
|
||||||
int bandCount() const;
|
int bandCount() const;
|
||||||
|
|
||||||
int colorInterpretation ( int bandNo ) const;
|
int colorInterpretation( int bandNo ) const;
|
||||||
|
|
||||||
int xBlockSize() const;
|
int xBlockSize() const;
|
||||||
int yBlockSize() const;
|
int yBlockSize() const;
|
||||||
@ -195,18 +195,18 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
|
|||||||
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
|
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
|
||||||
|
|
||||||
double noDataValue() const;
|
double noDataValue() const;
|
||||||
double minimumValue(int bandNo)const;
|
double minimumValue( int bandNo )const;
|
||||||
double maximumValue(int bandNo)const;
|
double maximumValue( int bandNo )const;
|
||||||
|
|
||||||
QList<QgsColorRampShader::ColorRampItem> colorTable(int bandNo)const;
|
QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const;
|
||||||
|
|
||||||
// void buildSupportedRasterFileFilter( QString & theFileFiltersString );
|
// void buildSupportedRasterFileFilter( QString & theFileFiltersString );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get metadata in a format suitable for feeding directly
|
* Get metadata in a format suitable for feeding directly
|
||||||
* into a subset of the GUI raster properties "Metadata" tab.
|
* into a subset of the GUI raster properties "Metadata" tab.
|
||||||
*/
|
*/
|
||||||
QString metadata();
|
QString metadata();
|
||||||
|
|
||||||
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
|
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
|
||||||
void addLayers( QStringList const & layers, QStringList const & styles = QStringList() ) {}
|
void addLayers( QStringList const & layers, QStringList const & styles = QStringList() ) {}
|
||||||
@ -216,11 +216,11 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
|
|||||||
void setImageCrs( QString const & crs ) {}
|
void setImageCrs( QString const & crs ) {}
|
||||||
|
|
||||||
void populateHistogram( int theBandNoInt,
|
void populateHistogram( int theBandNoInt,
|
||||||
QgsRasterBandStats & theBandStats,
|
QgsRasterBandStats & theBandStats,
|
||||||
int theBinCountInt = 256,
|
int theBinCountInt = 256,
|
||||||
bool theIgnoreOutOfRangeFlag = true,
|
bool theIgnoreOutOfRangeFlag = true,
|
||||||
bool theThoroughBandScanFlag = false
|
bool theThoroughBandScanFlag = false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -693,14 +693,16 @@ void QgsWmsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
|
|||||||
// TODO: optimize to avoid writing to QImage
|
// TODO: optimize to avoid writing to QImage
|
||||||
QImage* image = draw( viewExtent, pixelWidth, pixelHeight );
|
QImage* image = draw( viewExtent, pixelWidth, pixelHeight );
|
||||||
|
|
||||||
if ( ! image ) { // should not happen
|
if ( ! image ) // should not happen
|
||||||
|
{
|
||||||
QgsDebugMsg( "image is NULL" );
|
QgsDebugMsg( "image is NULL" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QgsDebugMsg( QString("image height = %1 bytesPerLine = %2").arg(image->height() ) . arg ( image->bytesPerLine() ) ) ;
|
QgsDebugMsg( QString( "image height = %1 bytesPerLine = %2" ).arg( image->height() ) . arg( image->bytesPerLine() ) ) ;
|
||||||
int myExpectedSize = pixelWidth * pixelHeight * 4;
|
int myExpectedSize = pixelWidth * pixelHeight * 4;
|
||||||
int myImageSize = image->height() * image->bytesPerLine();
|
int myImageSize = image->height() * image->bytesPerLine();
|
||||||
if ( myExpectedSize != myImageSize ) { // should not happen
|
if ( myExpectedSize != myImageSize ) // should not happen
|
||||||
|
{
|
||||||
QgsDebugMsg( "unexpected image size" );
|
QgsDebugMsg( "unexpected image size" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1009,7 +1011,7 @@ int QgsWmsProvider::srcDataType( int bandNo ) const
|
|||||||
int QgsWmsProvider::bandCount() const
|
int QgsWmsProvider::bandCount() const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsWmsProvider::capabilitiesReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
|
void QgsWmsProvider::capabilitiesReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
|
||||||
{
|
{
|
||||||
|
@ -529,10 +529,10 @@ class QgsWmsProvider : public QgsRasterDataProvider
|
|||||||
*/
|
*/
|
||||||
int capabilities() const;
|
int capabilities() const;
|
||||||
|
|
||||||
int dataType ( int bandNo ) const;
|
int dataType( int bandNo ) const;
|
||||||
int srcDataType ( int bandNo ) const;
|
int srcDataType( int bandNo ) const;
|
||||||
int bandCount() const;
|
int bandCount() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get metadata in a format suitable for feeding directly
|
* Get metadata in a format suitable for feeding directly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user