[QGIS Commit] r14516 - in branches/raster-providers/src: core
core/raster providers/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Nov 5 17:41:00 EDT 2010
Author: rblazek
Date: 2010-11-05 14:41:00 -0700 (Fri, 05 Nov 2010)
New Revision: 14516
Modified:
branches/raster-providers/src/core/qgsrasterdataprovider.h
branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
branches/raster-providers/src/core/raster/qgsrasterlayer.h
branches/raster-providers/src/providers/grass/qgis.d.rast.c
branches/raster-providers/src/providers/grass/qgis.g.info.c
branches/raster-providers/src/providers/grass/qgsgrass.cpp
branches/raster-providers/src/providers/grass/qgsgrass.h
branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp
branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h
Log:
drawing style init, color table
Modified: branches/raster-providers/src/core/qgsrasterdataprovider.h
===================================================================
--- branches/raster-providers/src/core/qgsrasterdataprovider.h 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/core/qgsrasterdataprovider.h 2010-11-05 21:41:00 UTC (rev 14516)
@@ -23,6 +23,7 @@
#include "qgslogger.h"
#include "qgsdataprovider.h"
+#include "qgscolorrampshader.h"
class QImage;
class QgsPoint;
@@ -208,6 +209,7 @@
virtual int ySize() const { return 0; }
/** read block of data */
+ // TODO clarify what happens on the last block (the part outside raster)
virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data ){}
/** read block of data using give extent and size */
@@ -219,6 +221,8 @@
virtual double minimumValue(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>(); }
+
/**
* Get metadata in a format suitable for feeding directly
* into a subset of the GUI raster properties "Metadata" tab.
Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.cpp 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.cpp 2010-11-05 21:41:00 UTC (rev 14516)
@@ -1279,7 +1279,8 @@
//GDALDataType myDataType = GDALGetRasterDataType( myGdalBand );
int myDataType = mDataProvider->dataType( theBand );
// TODO
- void* myGdalScanData = readData( myGdalBand, &mLastViewPort );
+ //void* myGdalScanData = readData( myGdalBand, &mLastViewPort );
+ void* myGdalScanData = NULL;
/* Check for out of memory error */
if ( myGdalScanData == NULL )
@@ -1598,6 +1599,7 @@
/ theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[1] ) + 1;
int totalPixelHeight = fabs(( myRasterViewPort->clippedYMax - myRasterViewPort->clippedYMin )
/ theQgsMapToPixel.mapUnitsPerPixel() * mGeoTransform[5] ) + 1;
+ // TODO optimize cache size - guess computer RAM?
int numParts = totalPixelWidth * totalPixelHeight / 5000000 + 1.0;
int numRowsPerPart = totalPixelHeight / numParts + 1.0;
@@ -1967,37 +1969,40 @@
QgsDebugMsg( "row = " + QString::number( row ) + " col = " + QString::number( col ) );
- for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
+ //for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
+ for ( int i = 1; i <= mDataProvider->bandCount(); i++ )
{
- GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, i );
- GDALDataType type = GDALGetRasterDataType( gdalBand );
- int size = GDALGetDataTypeSize( type ) / 8;
+ //GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, i );
+ //GDALDataType type = GDALGetRasterDataType( gdalBand );
+ //int size = GDALGetDataTypeSize( type ) / 8;
+ int size = mDataProvider->dataTypeSize(mDataProvider->dataType(i))/8;
void *data = CPLMalloc( size );
- CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
- data, 1, 1, type, 0, 0 );
+ // TODO
+ //CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
+ //data, 1, 1, type, 0, 0 );
- if ( err != CPLE_None )
- {
- QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
- }
+ //if ( err != CPLE_None )
+ //{
+ //QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
+ //}
- double value = readValue( data, type, 0 );
-#ifdef QGISDEBUG
- QgsLogger::debug( "value", value, 1, __FILE__, __FUNCTION__, __LINE__ );
-#endif
- QString v;
+ //double value = readValue( data, type, 0 );
+//#ifdef QGISDEBUG
+ //QgsLogger::debug( "value", value, 1, __FILE__, __FUNCTION__, __LINE__ );
+//#endif
+ //QString v;
- if ( mValidNoDataValue && ( fabs( value - mNoDataValue ) <= TINY_VALUE || value != value ) )
- {
- v = tr( "null (no data)" );
- }
- else
- {
- v.setNum( value );
- }
+ //if ( mValidNoDataValue && ( fabs( value - mNoDataValue ) <= TINY_VALUE || value != value ) )
+ //{
+ //v = tr( "null (no data)" );
+ //}
+ //else
+ //{
+ //v.setNum( value );
+ //}
- theResults[ generateBandName( i )] = v;
+ //theResults[ generateBandName( i )] = v;
CPLFree( data );
}
@@ -3257,106 +3262,199 @@
QgsDebugMsg( "Library name is " + mLib->fileName() );
bool loaded = mLib->load();
- if ( loaded )
+ mValid = false; // assume the layer is invalid until we determine otherwise
+ if ( !loaded )
{
- QgsDebugMsg( "Loaded data provider library" );
- QgsDebugMsg( "Attempting to resolve the classFactory function" );
- classFactoryFunction_t * classFactory = ( classFactoryFunction_t * ) cast_to_fptr( mLib->resolve( "classFactory" ) );
+ mValid = false;
+ QgsLogger::warning( "QgsRasterLayer::setDataProvider: Failed to load ../providers/libproviders.so" );
- mValid = false; // assume the layer is invalid until we
- // determine otherwise
- if ( classFactory )
- {
- QgsDebugMsg( "Getting pointer to a mDataProvider object from the library" );
- //XXX - This was a dynamic cast but that kills the Windows
- // version big-time with an abnormal termination error
- // mDataProvider = (QgsRasterDataProvider*)(classFactory((const
- // char*)(dataSource.utf8())));
+ }
+ QgsDebugMsg( "Loaded data provider library" );
+ QgsDebugMsg( "Attempting to resolve the classFactory function" );
+ classFactoryFunction_t * classFactory = ( classFactoryFunction_t * ) cast_to_fptr( mLib->resolve( "classFactory" ) );
- // Copied from qgsproviderregistry in preference to the above.
- mDataProvider = ( QgsRasterDataProvider* )( *classFactory )( &mDataSource );
+ if ( !classFactory )
+ {
+ QgsLogger::warning( "QgsRasterLayer::setDataProvider: Cannot resolve the classFactory function" );
+ return;
+ }
+ QgsDebugMsg( "Getting pointer to a mDataProvider object from the library" );
+ //XXX - This was a dynamic cast but that kills the Windows
+ // version big-time with an abnormal termination error
+ // mDataProvider = (QgsRasterDataProvider*)(classFactory((const
+ // char*)(dataSource.utf8())));
- if ( mDataProvider )
- {
- QgsDebugMsg( "Instantiated the data provider plugin" +
- QString( " with layer list of " ) + layers.join( ", " ) + " and style list of " + styles.join( ", " ) +
- " and format of " + format + " and CRS of " + crs );
- if ( mDataProvider->isValid() )
- {
- mValid = true;
+ // Copied from qgsproviderregistry in preference to the above.
+ mDataProvider = ( QgsRasterDataProvider* )( *classFactory )( &mDataSource );
- mDataProvider->addLayers( layers, styles );
- mDataProvider->setImageEncoding( format );
- mDataProvider->setImageCrs( crs );
+ if ( !mDataProvider )
+ {
+ QgsLogger::warning( "QgsRasterLayer::setDataProvider: Unable to instantiate the data provider plugin" );
+ return;
+ }
+ QgsDebugMsg( "Instantiated the data provider plugin"
+ + QString( " with layer list of " ) + layers.join( ", " )
+ + " and style list of " + styles.join( ", " )
+ + " and format of " + format + " and CRS of " + crs );
+ if ( ! mDataProvider->isValid() )
+ {
+ QgsLogger::warning( "QgsRasterLayer::setDataProvider: Data provider is invalid." );
+ return;
+ }
- setNoDataValue( mDataProvider->noDataValue() );
+ mDataProvider->addLayers( layers, styles );
+ mDataProvider->setImageEncoding( format );
+ mDataProvider->setImageCrs( crs );
- // get the extent
- QgsRectangle mbr = mDataProvider->extent();
+ setNoDataValue( mDataProvider->noDataValue() );
- // show the extent
- QString s = mbr.toString();
- QgsDebugMsg( "Extent of layer: " + s );
- // store the extent
- mLayerExtent.setXMaximum( mbr.xMaximum() );
- mLayerExtent.setXMinimum( mbr.xMinimum() );
- mLayerExtent.setYMaximum( mbr.yMaximum() );
- mLayerExtent.setYMinimum( mbr.yMinimum() );
+ // get the extent
+ QgsRectangle mbr = mDataProvider->extent();
- // upper case the first letter of the layer name
- QgsDebugMsg( "mLayerName: " + name() );
+ // show the extent
+ QString s = mbr.toString();
+ QgsDebugMsg( "Extent of layer: " + s );
+ // store the extent
+ mLayerExtent.setXMaximum( mbr.xMaximum() );
+ mLayerExtent.setXMinimum( mbr.xMinimum() );
+ mLayerExtent.setYMaximum( mbr.yMaximum() );
+ mLayerExtent.setYMinimum( mbr.yMinimum() );
- // set up the raster drawing style
- mDrawingStyle = MultiBandColor; //sensible default
+ // upper case the first letter of the layer name
+ QgsDebugMsg( "mLayerName: " + name() );
- // Setup source CRS
- if ( mProviderKey == "wms" )
- {
- *mCRS = QgsCoordinateReferenceSystem();
- mCRS->createFromOgcWmsCrs( crs );
- }
- else
- {
- *mCRS = QgsCoordinateReferenceSystem( mDataProvider->crs() );
- }
- //mBandCount = GDALGetRasterCount( mGdalDataset );
- mBandCount = mDataProvider->bandCount( );
- for ( int i = 1; i <= mBandCount; i++ )
- {
- //GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
- QgsRasterBandStats myRasterBandStats;
- myRasterBandStats.bandName = generateBandName( i );
- myRasterBandStats.bandNumber = i;
- myRasterBandStats.statsGathered = false;
- myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector();
- //Store the default color table
- // TODO
- //readColorTable( i, &myRasterBandStats.colorTable );
+ // set up the raster drawing style
+ mDrawingStyle = MultiBandColor; //sensible default
- mRasterStatsList.push_back( myRasterBandStats );
+ // Setup source CRS
+ if ( mProviderKey == "wms" )
+ {
+ *mCRS = QgsCoordinateReferenceSystem();
+ mCRS->createFromOgcWmsCrs( crs );
+ }
+ else
+ {
+ *mCRS = QgsCoordinateReferenceSystem( mDataProvider->crs() );
+ }
+ //mBandCount = GDALGetRasterCount( mGdalDataset );
+ mBandCount = mDataProvider->bandCount( );
+ for ( int i = 1; i <= mBandCount; i++ )
+ {
+ //GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, i );
+ QgsRasterBandStats myRasterBandStats;
+ myRasterBandStats.bandName = generateBandName( i );
+ myRasterBandStats.bandNumber = i;
+ myRasterBandStats.statsGathered = false;
+ myRasterBandStats.histogramVector = new QgsRasterBandStats::HistogramVector();
+ //Store the default color table
+ //readColorTable( i, &myRasterBandStats.colorTable );
+ QList<QgsColorRampShader::ColorRampItem> ct;
+ ct = mDataProvider->colorTable(i);
+ myRasterBandStats.colorTable = ct;
- //Build a new contrast enhancement for the band and store in list
- //QgsContrastEnhancement myContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )GDALGetRasterDataType( myGdalBand ) );
- QgsContrastEnhancement myContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )mDataProvider->dataType( i ) );
- mContrastEnhancementList.append( myContrastEnhancement );
- }
- }
+ mRasterStatsList.push_back( myRasterBandStats );
+
+ //Build a new contrast enhancement for the band and store in list
+ //QgsContrastEnhancement myContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )GDALGetRasterDataType( myGdalBand ) );
+ QgsContrastEnhancement myContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )mDataProvider->dataType( i ) );
+ mContrastEnhancementList.append( myContrastEnhancement );
+ }
+
+ QSettings myQSettings;
+ setContrastEnhancementAlgorithm( myQSettings.value( "/Raster/defaultContrastEnhancementAlgorithm", "StretchToMinimumMaximum" ).toString() );
+
+ //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
+ //if (( GDALGetRasterCount( mGdalDataset ) > 1 ) )
+ if (( mDataProvider->bandCount() > 1 ) )
+ {
+ mRasterType = Multiband;
+ }
+ //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!
+ // not sure if is worth to add colorTable capability - CT can be empty in any case
+ else if ( bandStatistics(1).colorTable.count() > 0 )
+ {
+ mRasterType = Palette;
+ }
+ else
+ {
+ mRasterType = GrayOrUndefined;
+ }
+
+ if ( mRasterType == Palette )
+ {
+ mRedBandName = TRSTRING_NOT_SET; // sensible default
+ mGreenBandName = TRSTRING_NOT_SET; // sensible default
+ mBlueBandName = TRSTRING_NOT_SET;// sensible default
+ mTransparencyBandName = TRSTRING_NOT_SET; // sensible default
+ mGrayBandName = bandName( 1 ); //sensible default
+ QgsDebugMsg( mGrayBandName );
+
+ mDrawingStyle = PalettedColor; //sensible default
+
+ //Set up a new color ramp shader
+ setColorShadingAlgorithm( ColorRampShader );
+ QgsColorRampShader* myColorRampShader = ( QgsColorRampShader* ) mRasterShader->rasterShaderFunction();
+ //TODO: Make sure the set algorithm and cast was successful,
+ //e.g., if ( 0 != myColorRampShader && myColorRampShader->shaderTypeAsString == "ColorRampShader" )
+ myColorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
+ myColorRampShader->setColorRampItemList( *colorTable( 1 ) );
+ }
+ else if ( mRasterType == Multiband )
+ {
+ //we know we have at least 2 layers...
+ mRedBandName = bandName( myQSettings.value( "/Raster/defaultRedBand", 1 ).toInt() ); // sensible default
+ mGreenBandName = bandName( myQSettings.value( "/Raster/defaultGreenBand", 2 ).toInt() ); // sensible default
+
+ //Check to make sure preferred bands combinations are valid
+ if ( mRedBandName.isEmpty() )
+ {
+ mRedBandName = bandName( 1 );
+ }
+
+ if ( mGreenBandName.isEmpty() )
+ {
+ mGreenBandName = bandName( 2 );
+ }
+
+ //for the third layer we cant be sure so..
+ //if ( GDALGetRasterCount( mGdalDataset ) > 2 )
+ if (( mDataProvider->bandCount() > 2 ) )
+ {
+ mBlueBandName = bandName( myQSettings.value( "/Raster/defaultBlueBand", 3 ).toInt() ); // sensible default
+ if ( mBlueBandName.isEmpty() )
+ {
+ mBlueBandName = bandName( 3 );
}
- else
+ }
+ else
+ {
+ mBlueBandName = bandName( myQSettings.value( "/Raster/defaultBlueBand", 2 ).toInt() ); // sensible default
+ if ( mBlueBandName.isEmpty() )
{
- QgsLogger::warning( "QgsRasterLayer::setDataProvider: Unable to instantiate the data provider plugin" );
- mValid = false;
+ mBlueBandName = bandName( 2 );
}
}
+
+
+ mTransparencyBandName = TRSTRING_NOT_SET;
+ mGrayBandName = TRSTRING_NOT_SET; //sensible default
+ mDrawingStyle = MultiBandColor; //sensible default
}
- else
+ else //GrayOrUndefined
{
- mValid = false;
- QgsLogger::warning( "QgsRasterLayer::setDataProvider: Failed to load ../providers/libproviders.so" );
+ mRedBandName = TRSTRING_NOT_SET; //sensible default
+ mGreenBandName = TRSTRING_NOT_SET; //sensible default
+ mBlueBandName = TRSTRING_NOT_SET; //sensible default
+ mTransparencyBandName = TRSTRING_NOT_SET; //sensible default
+ mDrawingStyle = SingleBandGray; //sensible default
+ mGrayBandName = bandName( 1 );
+ }
- }
+ //mark the layer as valid
+ mValid = true;
QgsDebugMsg( "exiting." );
-
} // QgsRasterLayer::setDataProvider
void QgsRasterLayer::setColorShadingAlgorithm( ColorShadingAlgorithm theShadingAlgorithm )
@@ -4572,9 +4670,10 @@
{
for ( int i = 0; i < theRasterViewPort->drawableAreaXDim; ++i )
{
- myRedValue = readValue( redRasterScanLine, ( GDALDataType )myRedType, i );
- myGreenValue = readValue( greenRasterScanLine, ( GDALDataType )myGreenType, i );
- myBlueValue = readValue( blueRasterScanLine, ( GDALDataType )myBlueType, i );
+ //myRedValue = readValue( redRasterScanLine, ( GDALDataType )myRedType, i );
+ myRedValue = readValue( redRasterScanLine, myRedType, i );
+ myGreenValue = readValue( greenRasterScanLine, myGreenType, i );
+ myBlueValue = readValue( blueRasterScanLine, myBlueType, i );
if ( mValidNoDataValue &&
(
@@ -4680,7 +4779,8 @@
myRedValue = 0;
myGreenValue = 0;
myBlueValue = 0;
- myPixelValue = readValue( rasterScanLine, ( GDALDataType )myDataType, i );
+ //myPixelValue = readValue( rasterScanLine, ( GDALDataType )myDataType, i );
+ myPixelValue = readValue( rasterScanLine, myDataType, i );
if ( mValidNoDataValue && ( fabs( myPixelValue - mNoDataValue ) <= TINY_VALUE || myPixelValue != myPixelValue ) )
{
@@ -4762,7 +4862,8 @@
myRedValue = 0;
myGreenValue = 0;
myBlueValue = 0;
- myPixelValue = readValue( rasterScanLine, ( GDALDataType )myDataType, i );
+ //myPixelValue = readValue( rasterScanLine, ( GDALDataType )myDataType, i );
+ myPixelValue = readValue( rasterScanLine, myDataType, i );
if ( mValidNoDataValue && ( fabs( myPixelValue - mNoDataValue ) <= TINY_VALUE || myPixelValue != myPixelValue ) )
{
@@ -4861,7 +4962,7 @@
myRedValue = 0;
myGreenValue = 0;
myBlueValue = 0;
- myPixelValue = readValue( rasterScanLine, ( GDALDataType )myDataType, i );
+ myPixelValue = readValue( rasterScanLine, myDataType, i );
if ( mValidNoDataValue && ( fabs( myPixelValue - mNoDataValue ) <= TINY_VALUE || myPixelValue != myPixelValue ) )
{
@@ -4966,7 +5067,7 @@
{
for ( int i = 0; i < theRasterViewPort->drawableAreaXDim; ++i )
{
- myGrayValue = readValue( rasterScanLine, ( GDALDataType )myDataType, i );
+ myGrayValue = readValue( rasterScanLine, myDataType, i );
if ( myGrayValue != -2147483647 ) {
//QgsDebugMsg( "myGrayValue = " + QString::number( myGrayValue ) );
}
@@ -5321,10 +5422,12 @@
*data type is the same as raster band. The memory must be released later!
* \return pointer to the memory
*/
-void *QgsRasterLayer::readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort )
+//void *QgsRasterLayer::readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort )
+void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort )
{
- GDALDataType type = GDALGetRasterDataType( gdalBand );
- int size = GDALGetDataTypeSize( type ) / 8;
+ // GDALDataType type = GDALGetRasterDataType( gdalBand );
+ //int size = GDALGetDataTypeSize( type ) / 8;
+ int size = mDataProvider->dataTypeSize(mDataProvider->dataType(bandNo))/8;
QgsDebugMsg( "calling RasterIO with " +
QString( ", source NW corner: " ) + QString::number( viewPort->rectXOffset ) +
@@ -5343,19 +5446,20 @@
}
else
{
- CPLErr myErr = GDALRasterIO( gdalBand, GF_Read,
- viewPort->rectXOffset,
- viewPort->rectYOffset,
- viewPort->clippedWidth,
- viewPort->clippedHeight,
- data,
- viewPort->drawableAreaXDim,
- viewPort->drawableAreaYDim,
- type, 0, 0 );
- if ( myErr != CPLE_None )
- {
- QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
- }
+ // TODO ?
+ //CPLErr myErr = GDALRasterIO( gdalBand, GF_Read,
+ //viewPort->rectXOffset,
+ //viewPort->rectYOffset,
+ //viewPort->clippedWidth,
+ //viewPort->clippedHeight,
+ //data,
+ //viewPort->drawableAreaXDim,
+ //viewPort->drawableAreaYDim,
+ //type, 0, 0 );
+ //if ( myErr != CPLE_None )
+ //{
+ //QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
+ //}
}
return data;
}
@@ -5524,96 +5628,96 @@
//defaults - Needs to be set after the Contrast list has been build
//Try to read the default contrast enhancement from the config file
- QSettings myQSettings;
- setContrastEnhancementAlgorithm( myQSettings.value( "/Raster/defaultContrastEnhancementAlgorithm", "StretchToMinimumMaximum" ).toString() );
+ //QSettings myQSettings;
+ //setContrastEnhancementAlgorithm( myQSettings.value( "/Raster/defaultContrastEnhancementAlgorithm", "StretchToMinimumMaximum" ).toString() );
- //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
- if (( GDALGetRasterCount( mGdalDataset ) > 1 ) )
- {
- mRasterType = Multiband;
- }
- //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!
- {
- mRasterType = Palette;
- }
- else
- {
- mRasterType = GrayOrUndefined;
- }
+ ////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
+ //if (( GDALGetRasterCount( mGdalDataset ) > 1 ) )
+ //{
+ //mRasterType = Multiband;
+ //}
+ ////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!
+ //{
+ //mRasterType = Palette;
+ //}
+ //else
+ //{
+ //mRasterType = GrayOrUndefined;
+ //}
- if ( mRasterType == Palette )
- {
- mRedBandName = TRSTRING_NOT_SET; // sensible default
- mGreenBandName = TRSTRING_NOT_SET; // sensible default
- mBlueBandName = TRSTRING_NOT_SET;// sensible default
- mTransparencyBandName = TRSTRING_NOT_SET; // sensible default
- mGrayBandName = bandName( 1 ); //sensible default
- QgsDebugMsg( mGrayBandName );
+ //if ( mRasterType == Palette )
+ //{
+ //mRedBandName = TRSTRING_NOT_SET; // sensible default
+ //mGreenBandName = TRSTRING_NOT_SET; // sensible default
+ //mBlueBandName = TRSTRING_NOT_SET;// sensible default
+ //mTransparencyBandName = TRSTRING_NOT_SET; // sensible default
+ //mGrayBandName = bandName( 1 ); //sensible default
+ //QgsDebugMsg( mGrayBandName );
- mDrawingStyle = PalettedColor; //sensible default
+ //mDrawingStyle = PalettedColor; //sensible default
- //Set up a new color ramp shader
- setColorShadingAlgorithm( ColorRampShader );
- QgsColorRampShader* myColorRampShader = ( QgsColorRampShader* ) mRasterShader->rasterShaderFunction();
- //TODO: Make sure the set algorithm and cast was successful,
- //e.g., if ( 0 != myColorRampShader && myColorRampShader->shaderTypeAsString == "ColorRampShader" )
- myColorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
- myColorRampShader->setColorRampItemList( *colorTable( 1 ) );
- }
- else if ( mRasterType == Multiband )
- {
- //we know we have at least 2 layers...
- mRedBandName = bandName( myQSettings.value( "/Raster/defaultRedBand", 1 ).toInt() ); // sensible default
- mGreenBandName = bandName( myQSettings.value( "/Raster/defaultGreenBand", 2 ).toInt() ); // sensible default
+ ////Set up a new color ramp shader
+ //setColorShadingAlgorithm( ColorRampShader );
+ //QgsColorRampShader* myColorRampShader = ( QgsColorRampShader* ) mRasterShader->rasterShaderFunction();
+ ////TODO: Make sure the set algorithm and cast was successful,
+ ////e.g., if ( 0 != myColorRampShader && myColorRampShader->shaderTypeAsString == "ColorRampShader" )
+ //myColorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
+ //myColorRampShader->setColorRampItemList( *colorTable( 1 ) );
+ //}
+ //else if ( mRasterType == Multiband )
+ //{
+ ////we know we have at least 2 layers...
+ //mRedBandName = bandName( myQSettings.value( "/Raster/defaultRedBand", 1 ).toInt() ); // sensible default
+ //mGreenBandName = bandName( myQSettings.value( "/Raster/defaultGreenBand", 2 ).toInt() ); // sensible default
- //Check to make sure preferred bands combinations are valid
- if ( mRedBandName.isEmpty() )
- {
- mRedBandName = bandName( 1 );
- }
+ ////Check to make sure preferred bands combinations are valid
+ //if ( mRedBandName.isEmpty() )
+ //{
+ //mRedBandName = bandName( 1 );
+ //}
- if ( mGreenBandName.isEmpty() )
- {
- mGreenBandName = bandName( 2 );
- }
+ //if ( mGreenBandName.isEmpty() )
+ //{
+ //mGreenBandName = bandName( 2 );
+ //}
- //for the third layer we cant be sure so..
- if ( GDALGetRasterCount( mGdalDataset ) > 2 )
- {
- mBlueBandName = bandName( myQSettings.value( "/Raster/defaultBlueBand", 3 ).toInt() ); // sensible default
- if ( mBlueBandName.isEmpty() )
- {
- mBlueBandName = bandName( 3 );
- }
- }
- else
- {
- mBlueBandName = bandName( myQSettings.value( "/Raster/defaultBlueBand", 2 ).toInt() ); // sensible default
- if ( mBlueBandName.isEmpty() )
- {
- mBlueBandName = bandName( 2 );
- }
- }
+ ////for the third layer we cant be sure so..
+ //if ( GDALGetRasterCount( mGdalDataset ) > 2 )
+ //{
+ //mBlueBandName = bandName( myQSettings.value( "/Raster/defaultBlueBand", 3 ).toInt() ); // sensible default
+ //if ( mBlueBandName.isEmpty() )
+ //{
+ //mBlueBandName = bandName( 3 );
+ //}
+ //}
+ //else
+ //{
+ //mBlueBandName = bandName( myQSettings.value( "/Raster/defaultBlueBand", 2 ).toInt() ); // sensible default
+ //if ( mBlueBandName.isEmpty() )
+ //{
+ //mBlueBandName = bandName( 2 );
+ //}
+ //}
- mTransparencyBandName = TRSTRING_NOT_SET;
- mGrayBandName = TRSTRING_NOT_SET; //sensible default
- mDrawingStyle = MultiBandColor; //sensible default
- }
- else //GrayOrUndefined
- {
- mRedBandName = TRSTRING_NOT_SET; //sensible default
- mGreenBandName = TRSTRING_NOT_SET; //sensible default
- mBlueBandName = TRSTRING_NOT_SET; //sensible default
- mTransparencyBandName = TRSTRING_NOT_SET; //sensible default
- mDrawingStyle = SingleBandGray; //sensible default
- mGrayBandName = bandName( 1 );
- }
+ //mTransparencyBandName = TRSTRING_NOT_SET;
+ //mGrayBandName = TRSTRING_NOT_SET; //sensible default
+ //mDrawingStyle = MultiBandColor; //sensible default
+ //}
+ //else //GrayOrUndefined
+ //{
+ //mRedBandName = TRSTRING_NOT_SET; //sensible default
+ //mGreenBandName = TRSTRING_NOT_SET; //sensible default
+ //mBlueBandName = TRSTRING_NOT_SET; //sensible default
+ //mTransparencyBandName = TRSTRING_NOT_SET; //sensible default
+ //mDrawingStyle = SingleBandGray; //sensible default
+ //mGrayBandName = bandName( 1 );
+ //}
- //mark the layer as valid
- mValid = true;
+ ////mark the layer as valid
+ //mValid = true;
return true;
} // QgsRasterLayer::readFile
@@ -5773,6 +5877,7 @@
//decide on the partition of the image
int pixels = mViewPort->drawableAreaXDim * mViewPort->drawableAreaYDim;
+ //maxPixelsInVirtualMemory = 1000;
int mNumPartImages = pixels / maxPixelsInVirtualMemory + 1.0;
mNumRasterRowsPerPart = ( double )mViewPort->clippedHeight / ( double )mNumPartImages + 0.5;
@@ -5781,6 +5886,8 @@
mCurrentPartImageRow = 0;
mNumCurrentImageRows = 0;
+ mCurrentPart = 0;
+
createNextPartImage();
if ( 2 >= mViewPort->clippedWidth && 2 >= mViewPort->clippedHeight )
@@ -5792,7 +5899,7 @@
bool QgsRasterImageBuffer::nextScanLine( QRgb** imageScanLine, void** rasterScanLine )
{
- //QgsDebugMsg( "Entered" );
+ QgsDebugMsg( "mCurrentRow = " + QString::number( mCurrentRow ) );
if ( !mValid )
return false;
@@ -5878,10 +5985,13 @@
delete mCurrentImage; mCurrentImage = 0;
CPLFree( mCurrentGDALData ); mCurrentGDALData = 0;
+ mCurrentPart++; // NEW
+ QgsDebugMsg( QString("mCurrentPartRasterMax = %1 mViewPort->clippedHeight = %2").arg(mCurrentPartRasterMax).arg(mViewPort->clippedHeight) );
if ( mCurrentPartRasterMax >= mViewPort->clippedHeight )
{
return false; //already at the end...
}
+ QgsDebugMsg( ">>" );
mCurrentPartRasterMin = mCurrentPartRasterMax + 1;
mCurrentPartRasterMax = mCurrentPartRasterMin + mNumRasterRowsPerPart;
@@ -5924,6 +6034,7 @@
ySize = fabs((( rasterYSize ) / mMapToPixel->mapUnitsPerPixel() * mGeoTransform[5] ) ) + 0.5;
}
}
+ QgsDebugMsg( QString("xSize = %1 ySize = %2").arg(xSize).arg(ySize) );
if ( ySize < 1 || xSize < 1 )
{
return false;
@@ -5934,13 +6045,16 @@
// mViewPort->rectYOffset + mCurrentRow, mViewPort->clippedWidth, rasterYSize,
// mCurrentGDALData, xSize, ySize, type, 0, 0 );
- // TODO: check this, it is probably not precise
- double yMax = mViewPort->mDrawnExtent.yMaximum() - mCurrentRow * mMapToPixel->mapUnitsPerPixel();
- double yMin = yMax - ySize * mMapToPixel->mapUnitsPerPixel();
-
+
+ // TODO !!! get correct extent
+ double yMin = mViewPort->mDrawnExtent.yMaximum() - mCurrentPartRasterMax ;
+ double yMax = mViewPort->mDrawnExtent.yMaximum() - mCurrentPartRasterMin;
+
+ QgsDebugMsg( QString("mCurrentRow = %1 yMaximum = %2 ySize = %3 mapUnitsPerPixel = %4").arg(mCurrentRow).arg(mViewPort->mDrawnExtent.yMaximum()).arg(ySize).arg(mMapToPixel->mapUnitsPerPixel()) );
QgsRectangle partExtent ( mViewPort->mDrawnExtent.xMinimum(), yMin,
mViewPort->mDrawnExtent.xMaximum(), yMax );
mDataProvider->readBlock ( mBandNo, partExtent, xSize, ySize, mCurrentGDALData );
+
// TODO - error check - throw exception
//if ( myErr != CPLE_None )
Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.h
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.h 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.h 2010-11-05 21:41:00 UTC (rev 14516)
@@ -772,7 +772,8 @@
QString projectionWkt();
/** \brief Allocate memory and load data to that allocated memory */
- void* readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort );
+ //void* readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort );
+ void* readData( int bandNo, QgsRasterViewPort *viewPort );
/** \brief Load the given raster file */
bool readFile( const QString & fileName );
@@ -961,7 +962,10 @@
int mCurrentPartRasterMax; //maximum (raster source) row of current image
int mCurrentPartImageRow; //current image row
int mNumCurrentImageRows; //number of image rows for the current part
+
//QgsRectangle mCurrentPartExtent; // extent of current part in map units
+ int mCurrentPart;
+
//current memory image and gdal scan data
QImage* mCurrentImage;
Modified: branches/raster-providers/src/providers/grass/qgis.d.rast.c
===================================================================
--- branches/raster-providers/src/providers/grass/qgis.d.rast.c 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/providers/grass/qgis.d.rast.c 2010-11-05 21:41:00 UTC (rev 14516)
@@ -197,7 +197,7 @@
val = (int*) (ptr);
//G_debug ( 0, "val = %d", *val );
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) {
Modified: branches/raster-providers/src/providers/grass/qgis.g.info.c
===================================================================
--- branches/raster-providers/src/providers/grass/qgis.g.info.c 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/providers/grass/qgis.g.info.c 2010-11-05 21:41:00 UTC (rev 14516)
@@ -34,7 +34,7 @@
info_opt->key = "info";
info_opt->type = TYPE_STRING;
info_opt->description = "info key";
- info_opt->options = "proj,window,size,query,info";
+ info_opt->options = "proj,window,size,query,info,colors";
rast_opt = G_define_standard_option( G_OPT_R_INPUT );
rast_opt->key = "rast";
@@ -95,11 +95,14 @@
// raster informations
else if ( strcmp( "info", info_opt->answer ) == 0 )
{
- //struct Range crange;
struct FPRange range;
double zmin, zmax;
+
+ // Data type
RASTER_MAP_TYPE raster_type = G_raster_map_type ( rast_opt->answer, "" );
fprintf( stdout, "TYPE:%d\n", raster_type );
+
+ // Statistics
if (G_read_fp_range( rast_opt->answer, "", &range) < 0) {
G_fatal_error(("Unable to read range file"));
}
@@ -107,6 +110,29 @@
fprintf( stdout, "MIN_VALUE:%f\n", zmin );
fprintf( stdout, "MAX_VALUE:%f\n", zmax );
}
+ else if ( strcmp( "colors", info_opt->answer ) == 0 )
+ {
+ // Color table
+ struct Colors colors;
+ int i, ccount;
+ if( G_read_colors( rast_opt->answer, "", &colors ) == 1 )
+ {
+ //int maxcolor;
+ //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 );
+ 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 )
{
double x, y;
Modified: branches/raster-providers/src/providers/grass/qgsgrass.cpp
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrass.cpp 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/providers/grass/qgsgrass.cpp 2010-11-05 21:41:00 UTC (rev 14516)
@@ -1226,6 +1226,36 @@
return inf;
}
+QList<QgsGrass::Color> GRASS_EXPORT QgsGrass::colors( QString gisdbase, QString location, QString mapset, QString map )
+{
+ QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
+ QList<QgsGrass::Color> ct;
+
+ try
+ {
+ QString str = QgsGrass::getInfo( "colors", gisdbase, location, mapset, map, QgsGrass::Raster );
+ QgsDebugMsg( str );
+ QStringList list = str.split( "\n" );
+ for ( int i = 0; i < list.size(); i++ ) {
+ double v1, v2;
+ int r1, r2, g1, g2, b1, b2;
+ QgsGrass::Color c;
+ 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 )
+ {
+ throw QgsGrass::Exception( "Cannot parse GRASS colors" + list[i] + " (" + str + " ) " );
+ }
+ ct.append( c);
+ }
+ }
+ catch ( QgsGrass::Exception &e )
+ {
+ QMessageBox::warning( 0, QObject::tr( "Warning" ),
+ QObject::tr( "Cannot get colors" ) + "\n" + e.what() );
+ }
+ return ct;
+}
+
QMap<QString, QString> GRASS_EXPORT QgsGrass::query( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
{
QgsDebugMsg( QString( "gisdbase = %1 location = %2" ).arg( gisdbase ).arg( location ) );
Modified: branches/raster-providers/src/providers/grass/qgsgrass.h
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrass.h 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/providers/grass/qgsgrass.h 2010-11-05 21:41:00 UTC (rev 14516)
@@ -52,6 +52,11 @@
Exception( const QString &msg ) : std::runtime_error( msg.toUtf8().constData() ) {}
};
+ struct Color {
+ double value1, value2;
+ int red1, red2, green1, green2, blue1, blue2;
+ };
+
//! Get info about the mode
/*! QgsGrass may be running in active or passive mode.
* Active mode means that GISRC is set up and GISRC file is available,
@@ -197,6 +202,10 @@
static GRASS_EXPORT QHash<QString, QString> info( QString gisdbase, QString location,
QString mapset, QString map, MapType type );
+ // ! List of Color
+ static GRASS_EXPORT QList<QgsGrass::Color> colors( QString gisdbase, QString location,
+ QString mapset, QString map );
+
// ! Get map value / feautre info
static GRASS_EXPORT QMap<QString, QString> query( QString gisdbase, QString location,
QString mapset, QString map, MapType type, double x, double y );
Modified: branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp 2010-11-05 21:41:00 UTC (rev 14516)
@@ -85,6 +85,18 @@
mGrassDataType = mInfo["TYPE"].toInt();
QgsDebugMsg( "mGrassDataType = " + QString::number( mGrassDataType ) );
+
+ // TODO: refresh mRows and mCols if raster was rewritten
+ // 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
+ // for statistics
+ int cache_size = 10000000; // ~ 10 MB
+ mYBlockSize = cache_size / (dataTypeSize(dataType ( 1 ) )/8) / mCols;
+ if ( mYBlockSize > mRows )
+ {
+ mYBlockSize = mRows;
+ }
+ QgsDebugMsg( "mYBlockSize = " + QString::number ( mYBlockSize ) );
}
QgsGrassRasterProvider::~QgsGrassRasterProvider()
@@ -146,14 +158,17 @@
QgsRectangle ext = extent();
+
+ // TODO: cut the last block
double cellHeight = ext.height() / mRows;
- double yMaximum = ext.yMaximum() - cellHeight * yBlock;
- double yMinimum = yMaximum - cellHeight;
+ double yMaximum = ext.yMaximum() - cellHeight * yBlock * mYBlockSize;
+ double yMinimum = yMaximum - cellHeight * mYBlockSize;
+ QgsDebugMsg( "mYBlockSize = " + QString::number ( mYBlockSize ) );
arguments.append(( QString( "window=%1,%2,%3,%4,%5,%6" )
.arg( ext.xMinimum() ).arg( yMinimum )
.arg( ext.xMaximum() ).arg( yMaximum )
- .arg( mCols ).arg( 1 ) ) );
+ .arg( mCols ).arg( mYBlockSize ) ) );
arguments.append( "format=value");
QProcess process( this );
@@ -241,6 +256,38 @@
return mInfo["MAX_VALUE"].toDouble();
}
+QList<QgsColorRampShader::ColorRampItem> QgsGrassRasterProvider::colorTable(int bandNo)const {
+ QList<QgsColorRampShader::ColorRampItem> ct;
+
+ // TODO: check if color can be realy discontinuous in GRASS,
+ // 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
+ // we are also expecting ordered CT records in the list
+ QList<QgsGrass::Color> colors = QgsGrass::colors( mGisdbase, mLocation, mMapset, mMapName );
+ QList<QgsGrass::Color>::iterator i;
+
+ double v, r, g, b;
+ for (i = colors.begin(); i != colors.end(); ++i)
+ {
+ if ( ct.count() == 0 || i->value1 != v || i->red1 != r || i->green1 != g || i->blue1 != b ) {
+ // not added in previous rule
+ QgsColorRampShader::ColorRampItem ctItem1;
+ ctItem1.value = i->value1;
+ ctItem1.color = QColor::fromRgb( i->red1, i->green1, i->blue1);
+ ct.append(ctItem1);
+ QgsDebugMsg( QString("color %1 %2 %3 %4").arg(i->value1).arg(i->red1).arg(i->green1).arg(i->blue1) );
+ }
+ QgsColorRampShader::ColorRampItem ctItem2;
+ ctItem2.value = i->value2;
+ ctItem2.color = QColor::fromRgb( i->red2, i->green2, i->blue2);
+ ct.append(ctItem2);
+ 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;
+ }
+ return ct;
+}
+
QgsCoordinateReferenceSystem QgsGrassRasterProvider::crs()
{
QgsDebugMsg( "Entered" );
@@ -258,7 +305,9 @@
// this is only called once when statistics are calculated
int QgsGrassRasterProvider::xBlockSize() const { return mCols; }
-int QgsGrassRasterProvider::yBlockSize() const { return 1; }
+int QgsGrassRasterProvider::yBlockSize() const {
+ return mYBlockSize;
+}
// TODO this should be always refreshed if raster has changed ?
// maybe also only for stats
@@ -282,8 +331,19 @@
int QgsGrassRasterProvider::dataType( int bandNo ) const
{
- // TODO
- return QgsRasterDataProvider::Int32;
+ switch ( mGrassDataType ) {
+ case CELL_TYPE:
+ return QgsGrassRasterProvider::Int32;
+ break;
+ case FCELL_TYPE:
+ return QgsGrassRasterProvider::Float32;
+ break;
+ case DCELL_TYPE:
+ return QgsGrassRasterProvider::Int32;
+ return QgsGrassRasterProvider::Float64;
+ break;
+ }
+ return QgsRasterDataProvider::UnknownDataType;
}
int QgsGrassRasterProvider::bandCount() const
Modified: branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h 2010-11-05 16:20:11 UTC (rev 14515)
+++ branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.h 2010-11-05 21:41:00 UTC (rev 14516)
@@ -29,6 +29,7 @@
#include "qgscoordinatereferencesystem.h"
#include "qgsrasterdataprovider.h"
#include "qgsrectangle.h"
+#include "qgscolorrampshader.h"
#include <QString>
#include <QStringList>
@@ -196,6 +197,9 @@
double minimumValue(int bandNo)const;
double maximumValue(int bandNo)const;
+ QList<QgsColorRampShader::ColorRampItem> colorTable(int bandNo)const;
+
+
/**
* Get metadata in a format suitable for feeding directly
* into a subset of the GUI raster properties "Metadata" tab.
@@ -226,6 +230,7 @@
QgsRectangle mExtent;
int mCols;
int mRows;
+ int mYBlockSize;
QHash<QString, QString> mInfo;
More information about the QGIS-commit
mailing list