Skip to content
Permalink
Browse files

raster cleanup

  • Loading branch information
blazek committed Apr 29, 2013
1 parent 1515c45 commit 229419ee133b9a6d9b38d13176ae895707ebc9c2
@@ -27,9 +27,6 @@ class QgsRasterBandStats
/*! Compares region, size etc. not collected statistics */
bool contains( const QgsRasterBandStats &s ) const;

/** \brief The name of the band that these stats belong to. */
QString bandName;

/** \brief The gdal band number (starts at 1)*/
int bandNumber;

@@ -82,7 +82,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );

/** Get list of user no data value ranges */
virtual QgsRasterRangeList userNoDataValue( int bandNo ) const;
virtual QgsRasterRangeList userNoDataValues( int bandNo ) const;

virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const;

@@ -181,9 +181,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
*/
virtual bool setNoDataValue( int bandNo, double noDataValue );

/**Returns the formats supported by create()*/
virtual QStringList createFormats() const;

/** Remove dataset*/
virtual bool remove();

@@ -190,7 +190,8 @@ class QgsRasterLayer : QgsMapLayer
QString providerType() const;

/** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */
double rasterUnitsPerPixel();
double rasterUnitsPerPixelX();
double rasterUnitsPerPixelY();

/** \brief Mutator for contrast enhancement algorithm
* @param theAlgorithm Contrast enhancement algorithm
@@ -200,7 +201,7 @@ class QgsRasterLayer : QgsMapLayer
* @param theGenerateLookupTableFlag Generate llokup table. */


void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
QgsRaster::ContrastEnhancementLimits theLimits = QgsRaster::ContrastEnhancementMinMax,
QgsRectangle theExtent = QgsRectangle(),
int theSampleSize = QgsRasterLayer::SAMPLE_SIZE,
@@ -2716,7 +2716,7 @@ void QgsLegend::legendLayerZoomNative()
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( currentLayer->layer() );
if ( layer )
{
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixel() ) );
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixelX() ) );
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );

layer->setCacheImage( NULL );
@@ -2732,11 +2732,11 @@ void QgsLegend::legendLayerZoomNative()
p2 = ct.transform( p2 );
double width = sqrt( p1.sqrDist( p2 ) ); // width of reprojected pixel
// This is not perfect of course, we use the resolution in just one direction
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / width ) );
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixelX() / width ) );
}
else
{
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixelX() / mMapCanvas->mapUnitsPerPixel() ) );
}
mMapCanvas->refresh();
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
@@ -2757,7 +2757,7 @@ void QgsLegend::legendLayerStretchUsingCurrentExtent()

QgsRectangle myRectangle;
myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( layer, mMapCanvas->extent() );
layer->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm, QgsRaster::ContrastEnhancementMinMax, myRectangle );
layer->setContrastEnhancement( contrastEnhancementAlgorithm, QgsRaster::ContrastEnhancementMinMax, myRectangle );

layer->setCacheImage( NULL );
refreshLayerSymbology( layer->id() );
@@ -6491,7 +6491,7 @@ void QgisApp::histogramStretch( bool visibleAreaOnly, QgsRaster::ContrastEnhance
QgsRectangle myRectangle;
if ( visibleAreaOnly ) myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( myRasterLayer, mMapCanvas->extent() );

myRasterLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, theLimits, myRectangle );
myRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, theLimits, myRectangle );

myRasterLayer->setCacheImage( NULL );
mMapCanvas->refresh();
@@ -645,7 +645,7 @@ void QgsRasterLayerProperties::sync()
mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
lblSrcNoDataValue->setEnabled( enableSrcNoData );

QgsRasterRangeList noDataRangeList = mRasterLayer->dataProvider()->userNoDataValue( 1 );
QgsRasterRangeList noDataRangeList = mRasterLayer->dataProvider()->userNoDataValues( 1 );
QgsDebugMsg( QString( "noDataRangeList.size = %1" ).arg( noDataRangeList.size() ) );
if ( noDataRangeList.size() > 0 )
{
@@ -57,8 +57,11 @@ class CORE_EXPORT QgsFeatureStore
/** Get features list reference */
QgsFeatureList& features() { return mFeatures; }

/** Set map of optional parameters */
void setParams( const QMap<QString, QVariant> &theParams ) { mParams = theParams; }

/** Get map of optional parameters */
QMap<QString, QVariant>& params() { return mParams; }
QMap<QString, QVariant> params() const { return mParams; }

private:
QgsFields mFields;
@@ -48,7 +48,6 @@ class CORE_EXPORT QgsRasterBandStats

QgsRasterBandStats()
{
bandName = "";
statsGathered = None;
minimumValue = std::numeric_limits<double>::max();
maximumValue = std::numeric_limits<double>::min();
@@ -73,19 +72,14 @@ class CORE_EXPORT QgsRasterBandStats
}

/** \brief The name of the band that these stats belong to. */
QString bandName;
//QString bandName;

/** \brief The gdal band number (starts at 1)*/
int bandNumber;

/** Color table
* @note not available in python bindings
*/
QList<QgsColorRampShader::ColorRampItem> colorTable;

/** \brief The number of cells in the band. Equivalent to height x width.
* TODO: check if NO_DATA are excluded!*/
int elementCount;
/** \brief The number of not no data cells in the band. */
// TODO: check if no data are excluded in stats calculation
size_t elementCount;

/** \brief The maximum cell value in the raster band. NO_DATA values
* are ignored. This does not use the gdal GetMaximmum function. */
@@ -273,6 +273,7 @@ bool QgsRasterBlock::hasNoData() const

bool QgsRasterBlock::isNoDataValue( double value, double noDataValue )
{
// TODO: optimize no data value test by memcmp()
// More precise would be qIsNaN(value) && qIsNaN(noDataValue(bandNo)), but probably
// not important and slower
if ( qIsNaN( value ) ||
@@ -205,7 +205,7 @@ QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle cons
}

// apply user no data values
block->applyNoDataValues( userNoDataValue( theBandNo ) );
block->applyNoDataValues( userNoDataValues( theBandNo ) );
return block;
}

@@ -501,7 +501,7 @@ QgsRasterInterface::Capability QgsRasterDataProvider::identifyFormatToCapability
}
}

bool QgsRasterDataProvider::userNoDataValueContains( int bandNo, double value ) const
bool QgsRasterDataProvider::userNoDataValuesContains( int bandNo, double value ) const
{
QgsRasterRangeList rangeList = mUserNoDataValue.value( bandNo - 1 );
return QgsRasterRange::contains( value, rangeList );
@@ -174,7 +174,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );

/** Get list of user no data value ranges */
virtual QgsRasterRangeList userNoDataValue( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }

virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
{ Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
@@ -313,7 +313,8 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }

/** Returns the formats supported by create() */
virtual QStringList createFormats() const { return QStringList(); }
// TODO: this should be static and call C functions in provider library
//static QStringList createFormats();

/** Remove dataset*/
virtual bool remove() { return false; }
@@ -357,7 +358,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
{ Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }

/** Returns true if user no data contains value */
bool userNoDataValueContains( int bandNo, double value ) const;
bool userNoDataValuesContains( int bandNo, double value ) const;

static QStringList cStringList2Q_( char ** stringList );

@@ -46,17 +46,12 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
//number of cols/rows in output pixels
int nCols = 0;
int nRows = 0;
//number of raster cols/rows with oversampling
//int nRasterCols = 0;
//int nRasterRows = 0;
//shift to top left point for the raster part
int topLeftCol = 0;
int topLeftRow = 0;

// We know that the output data type of last pipe filter is QImage data
//QgsRasterDataProvider::DataType rasterType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mGrayBand );

//void* rasterData;
QgsRasterBlock *block;

// readNextRasterPart calcs and resets nCols, nRows, topLeftCol, topLeftRow
@@ -68,11 +63,7 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
QgsDebugMsg( "Cannot get block" );
continue;
}
//create image
//QImage img( nRasterCols, nRasterRows, QImage::Format_ARGB32_Premultiplied );

// TODO: the exact format should be read from input
//QImage img(( uchar * ) rasterData, nCols, nRows, QImage::Format_ARGB32_Premultiplied );
QImage img = block->image();

drawImage( p, viewPort, img, topLeftCol, topLeftRow );
@@ -46,13 +46,11 @@ QgsRasterFileWriter::~QgsRasterFileWriter()

}

//QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( QgsRasterIterator* iter, int nCols, int nRows, QgsRectangle outputExtent,
QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, QgsRectangle outputExtent,
const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog )
{
QgsDebugMsg( "Entered" );

//if ( !iter )
if ( !pipe )
{
return SourceProviderError;
@@ -127,15 +125,12 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
return SourceProviderError;
}

//const QgsRasterInterface* iface = iter->input();
const QgsRasterInterface* iface = pipe->last();
if ( !iface )
{
return SourceProviderError;
}

//const QgsRasterDataProvider* srcProvider = dynamic_cast<const QgsRasterDataProvider*>( iface->srcInput() );
//QgsRasterDataProvider* srcProvider = dynamic_cast<QgsRasterDataProvider*>( iface->srcInput() );
QgsRasterDataProvider* srcProvider = const_cast<QgsRasterDataProvider*>( dynamic_cast<const QgsRasterDataProvider*>( iface->srcInput() ) );
if ( !srcProvider )
{
@@ -179,7 +174,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
bool destHasNoDataValue = false;
double destNoDataValue = std::numeric_limits<double>::quiet_NaN();
QGis::DataType destDataType = srcProvider->srcDataType( bandNo );
//QGis::DataType destDataType = srcProvider->dataType( bandNo );
// TODO: verify what happens/should happen if srcNoDataValue is disabled by setUseSrcNoDataValue
QgsDebugMsg( QString( "srcHasNoDataValue = %1 srcNoDataValue = %2" ).arg( srcHasNoDataValue ).arg( srcProvider->srcNoDataValue( bandNo ) ) );
if ( srcHasNoDataValue )
@@ -330,8 +324,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster(
for ( int i = 1; i <= nBands; ++i )
{
iter->startRasterRead( i, nCols, nRows, outputExtent );
// TODO: no need to alloc memory, change to readBlock() returning the allocated block
//blockList.push_back( qgsMalloc( dataTypeSize * mMaxTileWidth * mMaxTileHeight ) );
blockList.push_back( 0 );
if ( destProvider ) // no tiles
{
@@ -360,7 +352,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster(
if ( !iter->readNextRasterPart( i, iterCols, iterRows, &( blockList[i - 1] ), iterLeft, iterTop ) )
{
// No more parts, create VRT and return
//delete destProvider;
if ( mTiledMode )
{
QString vrtFilePath( mOutputUrl + "/" + vrtFileName() );
@@ -418,7 +409,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster(

if ( mTiledMode ) //write to file
{
//delete destProvider;
QgsRasterDataProvider* partDestProvider = createPartProvider( outputExtent,
nCols, iterCols, iterRows,
iterLeft, iterTop, mOutputUrl,
@@ -473,7 +463,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste
iter->setMaximumTileWidth( mMaxTileWidth );
iter->setMaximumTileHeight( mMaxTileHeight );

//void* data = qgsMalloc( QgsRasterBlock::typeSize( inputDataType ) * mMaxTileWidth * mMaxTileHeight );
void* redData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
void* greenData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
void* blueData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
@@ -490,7 +479,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste

destProvider = initOutput( nCols, nRows, crs, geoTransform, 4, QGis::Byte );

//iter->select( outputExtent, outputMapUnitsPerPixel );
iter->startRasterRead( 1, nCols, nRows, outputExtent );

int nParts = 0;
@@ -701,7 +689,6 @@ void QgsRasterFileWriter::buildPyramids( const QString& filename )
{
QgsDebugMsg( "filename = " + filename );
// open new dataProvider so we can build pyramids with it
//QgsRasterDataProvider* destProvider = QgsRasterLayer::loadProvider( mOutputProviderKey, filename );
QgsRasterDataProvider* destProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( mOutputProviderKey, filename );
if ( !destProvider )
{
@@ -885,14 +872,6 @@ QgsRasterDataProvider* QgsRasterFileWriter::createPartProvider( const QgsRectang
QgsRectangle mapRect( mapLeft, mapBottom, mapRight, mapTop );

QString outputFile = outputUrl + "/" + partFileName( fileIndex );
#if 0
//QgsRasterDataProvider* destProvider = QgsRasterLayer::loadProvider( mOutputProviderKey, outputFile );
QgsRasterDataProvider* destProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( mOutputProviderKey, outputFile );
if ( !destProvider )
{
return 0;
}
#endif

//geotransform
double geoTransform[6];
@@ -904,14 +883,6 @@ QgsRasterDataProvider* QgsRasterFileWriter::createPartProvider( const QgsRectang
geoTransform[5] = -mup;

// perhaps we need a separate createOptions for tiles ?
#if 0
if ( !destProvider->create( mOutputFormat, nBands, type, iterCols, iterRows, geoTransform,
crs ) )
{
delete destProvider;
return 0;
}
#endif

QgsRasterDataProvider* destProvider = QgsRasterDataProvider::create( mOutputProviderKey, outputFile, mOutputFormat, nBands, type, iterCols, iterRows, geoTransform, crs, mCreateOptions ) ;

@@ -937,24 +908,13 @@ QgsRasterDataProvider* QgsRasterFileWriter::initOutput( int nCols, int nRows, co
mCreateOptions << "COPY_SRC_OVERVIEWS=YES";
#endif

//QgsRasterDataProvider* destProvider = QgsRasterLayer::loadProvider( mOutputProviderKey, mOutputUrl );
//QgsRasterDataProvider* destProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( mOutputProviderKey, mOutputUrl );
QgsRasterDataProvider* destProvider = QgsRasterDataProvider::create( mOutputProviderKey, mOutputUrl, mOutputFormat, nBands, type, nCols, nRows, geoTransform, crs, mCreateOptions ) ;

if ( !destProvider )
{
QgsDebugMsg( "No provider created" );
}

#if 0
if ( !destProvider->create( mOutputFormat, nBands, type, nCols, nRows, geoTransform,
crs, mCreateOptions ) )
{
delete destProvider;
return 0;
}
#endif

return destProvider;
}
}

0 comments on commit 229419e

Please sign in to comment.
You can’t perform that action at this time.