Skip to content
Permalink
Browse files

raster saveas: load nodata from layer transparency

  • Loading branch information
blazek committed Sep 4, 2012
1 parent 72978cf commit 3562bdbbceaa0f97316bac8fe772dc5d8e453c6d
@@ -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
@@ -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 );
}
@@ -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:
@@ -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();
@@ -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;
@@ -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 );
};


@@ -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">
@@ -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>
@@ -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>
@@ -643,7 +646,7 @@
<string>No pyramids</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mPyramidsButtonGroup</string>
<string>mPyramidsButtonGroup</string>
</attribute>
</widget>
</item>
@@ -653,7 +656,7 @@
<string>Build pyramids</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mPyramidsButtonGroup</string>
<string>mPyramidsButtonGroup</string>
</attribute>
</widget>
</item>
@@ -663,7 +666,7 @@
<string>Use existing</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mPyramidsButtonGroup</string>
<string>mPyramidsButtonGroup</string>
</attribute>
</widget>
</item>

0 comments on commit 3562bdb

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