Skip to content

Commit

Permalink
raster saveas: load nodata from layer transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 4, 2012
1 parent 72978cf commit 3562bdb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -256,10 +256,17 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
cboxTransparencyBand->addItem( bandName, i );
}

// Alpha band is set in sync()
#if 0
if ( renderer )
{
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->alphaBand() ) );
QgsDebugMsg( QString( "alphaBand = %1" ).arg( renderer->alphaBand() ) );
if ( renderer->alphaBand() > 0 )
{
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->alphaBand() ) );
}
}
#endif
}

// create histogram widget
Expand Down
19 changes: 9 additions & 10 deletions src/core/raster/qgsrasternuller.cpp
Expand Up @@ -56,24 +56,23 @@ void * QgsRasterNuller::readBlock( int bandNo, QgsRectangle const & extent, int

void * rasterData = mInput->block( bandNo, extent, width, height );

QgsRasterInterface::DataType dataType = mInput->dataType( bandNo );
int pixelSize = mInput->typeSize( dataType ) / 8;
QgsRasterInterface::DataType dataType = mInput->dataType( bandNo );

double noDataValue = mInput->noDataValue ( bandNo );
double noDataValue = mInput->noDataValue( bandNo );

for ( int i = 0; i < height; ++i )
for ( int i = 0; i < height; i++ )
{
for ( int j = 0; j < width; ++j )
for ( int j = 0; j < width; j++ )
{
int index = pixelSize * ( i * width + j );
int index = i * width + j;

double value = readValue( rasterData, dataType, index );

foreach ( NoData noData, mNoData )
{
if ( ( value >= noData.min && value <= noData.max ) ||
doubleNear( value, noData.min ) ||
doubleNear( value, noData.max ) )
if (( value >= noData.min && value <= noData.max ) ||
doubleNear( value, noData.min ) ||
doubleNear( value, noData.max ) )
{
writeValue( rasterData, dataType, index, noDataValue );
}
Expand Down
15 changes: 14 additions & 1 deletion src/gui/qgsrasterlayersaveasdialog.cpp
Expand Up @@ -589,7 +589,7 @@ void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
lineEdit->setValidator( new QDoubleValidator( 0 ) );
if ( !qIsNaN( value ) )
{
valueString = QString::number( value, 'f' );
valueString = QgsRasterInterface::printValue( value );
}
break;
default:
Expand All @@ -603,6 +603,8 @@ void QgsRasterLayerSaveAsDialog::addNoDataRow( double min, double max )
lineEdit->setText( valueString );
mNoDataTableWidget->setCellWidget( mNoDataTableWidget->rowCount() - 1, i, lineEdit );

adjustNoDataCellWidth( mNoDataTableWidget->rowCount() - 1, i );

connect( lineEdit, SIGNAL( textEdited( const QString & ) ), this, SLOT( noDataCellTextEdited( const QString & ) ) );
}
mNoDataTableWidget->resizeColumnsToContents();
Expand Down Expand Up @@ -737,6 +739,17 @@ double QgsRasterLayerSaveAsDialog::noDataCellValue( int row, int column ) const
return lineEdit->text().toDouble();
}

void QgsRasterLayerSaveAsDialog::adjustNoDataCellWidth( int row, int column )
{
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>( mNoDataTableWidget->cellWidget( row, column ) );
if ( !lineEdit ) return;

int width = qMax( lineEdit->fontMetrics().width( lineEdit->text() ) + 10, 100 );
width = qMax( width, mNoDataTableWidget->columnWidth( column ) );

lineEdit->setFixedWidth( width );
}

QList<QgsRasterNuller::NoData> QgsRasterLayerSaveAsDialog::noData() const
{
QList<QgsRasterNuller::NoData> noDataList;
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsrasterlayersaveasdialog.h
Expand Up @@ -134,6 +134,7 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
void addNoDataRow( double min, double max );
void setNoDataToEdited( int row );
double noDataCellValue( int row, int column ) const;
void adjustNoDataCellWidth( int row, int column );
};


Expand Down
21 changes: 12 additions & 9 deletions src/ui/qgsrasterlayersaveasdialogbase.ui
Expand Up @@ -29,9 +29,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-293</y>
<width>539</width>
<height>831</height>
<y>-263</y>
<width>549</width>
<height>806</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -527,6 +527,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
<property name="toolTip">
<string>Additional no data values. The specified values will be set to no data in output raster.</string>
</property>
Expand Down Expand Up @@ -568,9 +574,6 @@
</item>
<item row="2" column="0">
<widget class="QToolButton" name="mLoadTransparentNoDataToolButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Load user defined fully transparent (100%) values </string>
</property>
Expand Down Expand Up @@ -643,7 +646,7 @@
<string>No pyramids</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mPyramidsButtonGroup</string>
<string>mPyramidsButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -653,7 +656,7 @@
<string>Build pyramids</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mPyramidsButtonGroup</string>
<string>mPyramidsButtonGroup</string>
</attribute>
</widget>
</item>
Expand All @@ -663,7 +666,7 @@
<string>Use existing</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mPyramidsButtonGroup</string>
<string>mPyramidsButtonGroup</string>
</attribute>
</widget>
</item>
Expand Down

0 comments on commit 3562bdb

Please sign in to comment.