QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer* layer ): QgsRasterRendererWidget( layer ) { setupUi( this ); mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) ); mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) ); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mGrayBandComboBox->addItem( displayBandName( i ), i ); } //contrast enhancement algorithms mContrastEnhancementComboBox->addItem( tr( "No enhancement" ), 0 ); mContrastEnhancementComboBox->addItem( tr( "Stretch to MinMax" ), 1 ); mContrastEnhancementComboBox->addItem( tr( "Stretch and clip to MinMax" ), 2 ); mContrastEnhancementComboBox->addItem( tr( "Clip to MinMax" ), 3 ); setFromRenderer( layer->renderer() ); } }
QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ) : QgsRasterRendererWidget( layer, extent ) , mMinMaxWidget( nullptr ) { setupUi( this ); createValidators(); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); layout()->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ), this, SLOT( loadMinMax( int, double, double, int ) ) ); connect( mRedBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onBandChanged( int ) ) ); connect( mGreenBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onBandChanged( int ) ) ); connect( mBlueBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onBandChanged( int ) ) ); //fill available bands into combo boxes mRedBandComboBox->addItem( tr( "Not set" ), -1 ); mGreenBandComboBox->addItem( tr( "Not set" ), -1 ); mBlueBandComboBox->addItem( tr( "Not set" ), -1 ); //contrast enhancement algorithms mContrastEnhancementAlgorithmComboBox->addItem( tr( "No enhancement" ), 0 ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch to MinMax" ), 1 ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch and clip to MinMax" ), 2 ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Clip to MinMax" ), 3 ); int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { QString bandName = displayBandName( i ); mRedBandComboBox->addItem( bandName, i ); mGreenBandComboBox->addItem( bandName, i ); mBlueBandComboBox->addItem( bandName, i ); } setFromRenderer( mRasterLayer->renderer() ); onBandChanged( 0 ); // reset mMinMaxWidget bands connect( mRedMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mRedMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mGreenMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mGreenMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mBlueMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mBlueMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); } }
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ): QgsRasterRendererWidget( layer, extent ) { setupUi( this ); mColorRampComboBox->populate( QgsStyleV2::defaultStyle() ); if ( !mRasterLayer ) { return; } QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mBandComboBox->addItem( displayBandName( i ), i ); } mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 ); mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 ); mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 ); mClassificationModeComboBox->addItem( tr( "Equal interval" ) ); //quantile would be nice as well setFromRenderer( layer->renderer() ); }
QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ) : QgsRasterRendererWidget( layer, extent ) , mMinMaxWidget( nullptr ) , mDisableMinMaxWidgetRefresh( false ) { setupUi( this ); mGradientComboBox->insertItem( 0, tr( "Black to white" ), QgsSingleBandGrayRenderer::BlackToWhite ); mGradientComboBox->insertItem( 1, tr( "White to black" ), QgsSingleBandGrayRenderer::WhiteToBlack ); mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) ); mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) ); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); mMinMaxWidget->setMapCanvas( mCanvas ); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins( 0, 0, 0, 0 ); mMinMaxContainerWidget->setLayout( layout ); layout->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, &QgsRasterMinMaxWidget::widgetChanged, this, &QgsSingleBandGrayRendererWidget::widgetChanged ); connect( mMinMaxWidget, &QgsRasterMinMaxWidget::load, this, &QgsSingleBandGrayRendererWidget::loadMinMax ); //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mGrayBandComboBox->addItem( displayBandName( i ), i ); } //contrast enhancement algorithms mContrastEnhancementComboBox->addItem( tr( "No enhancement" ), QgsContrastEnhancement::NoEnhancement ); mContrastEnhancementComboBox->addItem( tr( "Stretch to MinMax" ), QgsContrastEnhancement::StretchToMinimumMaximum ); mContrastEnhancementComboBox->addItem( tr( "Stretch and clip to MinMax" ), QgsContrastEnhancement::StretchAndClipToMinimumMaximum ); mContrastEnhancementComboBox->addItem( tr( "Clip to MinMax" ), QgsContrastEnhancement::ClipToMinimumMaximum ); setFromRenderer( layer->renderer() ); connect( mGradientComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) ); connect( mContrastEnhancementComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) ); } }
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ): QgsRasterRendererWidget( layer, extent ) { setupUi( this ); mColormapTreeWidget->setColumnWidth( 1, 50 ); mColorRampComboBox->populate( QgsStyleV2::defaultStyle() ); if ( !mRasterLayer ) { return; } QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } // Must be before adding items to mBandComboBox (signal) mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) ); mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) ); mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins( 0, 0, 0, 0 ); mMinMaxContainerWidget->setLayout( layout ); layout->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ), this, SLOT( loadMinMax( int, double, double, int ) ) ); //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mBandComboBox->addItem( displayBandName( i ), i ); } mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 ); mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 ); mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 ); mColorInterpolationComboBox->setCurrentIndex( 1 ); mClassificationModeComboBox->addItem( tr( "Equal interval" ) ); //quantile would be nice as well mNumberOfEntriesSpinBox->setValue( 5 ); // some default setFromRenderer( layer->renderer() ); }
QgsHillshadeRendererWidget::QgsHillshadeRendererWidget( QgsRasterLayer *layer, const QgsRectangle &extent ) : QgsRasterRendererWidget( layer, extent ) { setupUi( this ); mLightAngle->setMaximum( 90 ); mLightAzimuth->setMaximum( 360.00 ); mLightAngle->setValue( 45.00 ); mLightAngle->setClearValue( 45.0 ); mLightAzimuth->setValue( 315.00 ); mLightAzimuth->setClearValue( 315.00 ); // Update the dial correctly on_mLightAzimuth_updated( 315.00 ); mZFactor->setValue( 1 ); mZFactor->setClearValue( 1 ); mMultiDirection->setChecked( false ); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mBandsCombo->addItem( displayBandName( i ), i ); } } setFromRenderer( layer->renderer() ); connect( mLightAngle, SIGNAL( valueChanged( double ) ), this, SIGNAL( widgetChanged() ) ); connect( mLightAzimuth, SIGNAL( valueChanged( double ) ), this, SLOT( on_mLightAzimuth_updated( double ) ) ); connect( mLightAzimuthDial, SIGNAL( valueChanged( int ) ), this, SLOT( on_mLightAzimuthDail_updated( int ) ) ); connect( mZFactor, SIGNAL( valueChanged( double ) ), this, SIGNAL( widgetChanged() ) ); connect( mMultiDirection, SIGNAL( toggled( bool ) ), this, SIGNAL( widgetChanged() ) ); }
QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ): QgsRasterRendererWidget( layer, extent ) { setupUi( this ); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mBandComboBox->addItem( displayBandName( i ), i ); } setFromRenderer( mRasterLayer->renderer() ); connect( mBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) ); } }
QgsSingleBandGrayRendererWidget::QgsSingleBandGrayRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ): QgsRasterRendererWidget( layer, extent ) { setupUi( this ); mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) ); mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) ); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); layout()->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, SIGNAL( load( int, double, double ) ), this, SLOT( loadMinMax( int, double, double ) ) ); //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mGrayBandComboBox->addItem( displayBandName( i ), i ); } //contrast enhancement algorithms mContrastEnhancementComboBox->addItem( tr( "No enhancement" ), 0 ); mContrastEnhancementComboBox->addItem( tr( "Stretch to MinMax" ), 1 ); mContrastEnhancementComboBox->addItem( tr( "Stretch and clip to MinMax" ), 2 ); mContrastEnhancementComboBox->addItem( tr( "Clip to MinMax" ), 3 ); setFromRenderer( layer->renderer() ); } }
QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer* layer ): QgsRasterRendererWidget( layer ) { setupUi( this ); createValidators(); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } //fill available bands into combo boxes mRedBandComboBox->addItem( tr( "Not set" ), -1 ); mGreenBandComboBox->addItem( tr( "Not set" ), -1 ); mBlueBandComboBox->addItem( tr( "Not set" ), -1 ); //contrast enhancement algorithms mContrastEnhancementAlgorithmComboBox->addItem( tr( "No enhancement" ), 0 ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch to MinMax" ), 1 ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch and clip to MinMax" ), 2 ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Clip to MinMax" ), 3 ); int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { QString bandName = displayBandName( i ); mRedBandComboBox->addItem( bandName, i ); mGreenBandComboBox->addItem( bandName, i ); mBlueBandComboBox->addItem( bandName, i ); } setFromRenderer( mRasterLayer->renderer() ); } }
bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri, QString theExpectedKey, QString theExpectedUri ) { bool ok = true; mReport += "\n\n"; //QgsRasterDataProvider* verifiedProvider = QgsRasterLayer::loadProvider( theVerifiedKey, theVerifiedUri ); QgsRasterDataProvider* verifiedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theVerifiedKey, theVerifiedUri ); if ( !verifiedProvider || !verifiedProvider->isValid() ) { error( QString( "Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey ).arg( theVerifiedUri ), mReport ); ok = false; } //QgsRasterDataProvider* expectedProvider = QgsRasterLayer::loadProvider( theExpectedKey, theExpectedUri ); QgsRasterDataProvider* expectedProvider = ( QgsRasterDataProvider* ) QgsProviderRegistry::instance()->provider( theExpectedKey, theExpectedUri ); if ( !expectedProvider || !expectedProvider->isValid() ) { error( QString( "Cannot load provider %1 with URI: %2" ).arg( theExpectedKey ).arg( theExpectedUri ), mReport ); ok = false; } if ( !ok ) return false; mReport += QString( "Verified URI: %1<br>" ).arg( theVerifiedUri.replace( "&", "&" ) ); mReport += QString( "Expected URI: %1<br>" ).arg( theExpectedUri.replace( "&", "&" ) ); mReport += "<br>"; mReport += QString( "<table style='%1'>\n" ).arg( mTabStyle ); mReport += compareHead(); compare( "Band count", verifiedProvider->bandCount(), expectedProvider->bandCount(), mReport, ok ); compare( "Width", verifiedProvider->xSize(), expectedProvider->xSize(), mReport, ok ); compare( "Height", verifiedProvider->ySize(), expectedProvider->ySize(), mReport, ok ); compareRow( "Extent", verifiedProvider->extent().toString(), expectedProvider->extent().toString(), mReport, verifiedProvider->extent() == expectedProvider->extent() ); if ( verifiedProvider->extent() != expectedProvider->extent() ) ok = false; mReport += "</table>\n"; if ( !ok ) return false; bool allOk = true; for ( int band = 1; band <= expectedProvider->bandCount(); band++ ) { bool bandOk = true; mReport += QString( "<h3>Band %1</h3>\n" ).arg( band ); mReport += QString( "<table style='%1'>\n" ).arg( mTabStyle ); mReport += compareHead(); // Data types may differ (?) bool typesOk = true; compare( "Source data type", verifiedProvider->srcDataType( band ), expectedProvider->srcDataType( band ), mReport, typesOk ); compare( "Data type", verifiedProvider->dataType( band ), expectedProvider->dataType( band ), mReport, typesOk ) ; // TODO: not yet sure if noDataValue() should exist at all //compare( "No data (NULL) value", verifiedProvider->noDataValue( band ), expectedProvider->noDataValue( band ), mReport, typesOk ); bool statsOk = true; QgsRasterBandStats verifiedStats = verifiedProvider->bandStatistics( band ); QgsRasterBandStats expectedStats = expectedProvider->bandStatistics( band ); // Min/max may 'slightly' differ, for big numbers however, the difference may // be quite big, for example for Float32 with max -3.332e+38, the difference is 1.47338e+24 double tol = tolerance( expectedStats.minimumValue ); compare( "Minimum value", verifiedStats.minimumValue, expectedStats.minimumValue, mReport, statsOk, tol ); tol = tolerance( expectedStats.maximumValue ); compare( "Maximum value", verifiedStats.maximumValue, expectedStats.maximumValue, mReport, statsOk, tol ); // TODO: enable once fixed (WCS excludes nulls but GDAL does not) //compare( "Cells count", verifiedStats.elementCount, expectedStats.elementCount, mReport, statsOk ); tol = tolerance( expectedStats.mean ); compare( "Mean", verifiedStats.mean, expectedStats.mean, mReport, statsOk, tol ); // stdDev usually differ significantly tol = tolerance( expectedStats.stdDev, 1 ); compare( "Standard deviation", verifiedStats.stdDev, expectedStats.stdDev, mReport, statsOk, tol ); mReport += "</table>"; mReport += "<br>"; if ( !bandOk ) { allOk = false; continue; } if ( !statsOk || !typesOk ) { allOk = false; // create values table anyway so that values are available } mReport += "<table><tr>"; mReport += "<td>Data comparison</td>"; mReport += QString( "<td style='%1 %2 border: 1px solid'>correct value</td>" ).arg( mCellStyle ).arg( mOkStyle ); mReport += "<td></td>"; mReport += QString( "<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).arg( mCellStyle ).arg( mErrStyle ); mReport += "</tr></table>"; mReport += "<br>"; int width = expectedProvider->xSize(); int height = expectedProvider->ySize(); QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height ); QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height ); if ( !expectedBlock || !expectedBlock->isValid() || !verifiedBlock || !verifiedBlock->isValid() ) { allOk = false; mReport += "cannot read raster block"; continue; } // compare data values QString htmlTable = QString( "<table style='%1'>" ).arg( mTabStyle ); for ( int row = 0; row < height; row ++ ) { htmlTable += "<tr>"; for ( int col = 0; col < width; col ++ ) { bool cellOk = true; double verifiedVal = verifiedBlock->value( row, col ); double expectedVal = expectedBlock->value( row, col ); QString valStr; if ( compare( verifiedVal, expectedVal, 0 ) ) { valStr = QString( "%1" ).arg( verifiedVal ); } else { cellOk = false; allOk = false; valStr = QString( "%1<br>%2" ).arg( verifiedVal ).arg( expectedVal ); } htmlTable += QString( "<td style='%1 %2'>%3</td>" ).arg( mCellStyle ).arg( cellOk ? mOkStyle : mErrStyle ).arg( valStr ); } htmlTable += "</tr>"; } htmlTable += "</table>"; mReport += htmlTable; delete expectedBlock; delete verifiedBlock; } delete verifiedProvider; delete expectedProvider; return allOk; }
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ) : QgsRasterRendererWidget( layer, extent ) , mMinMaxWidget( nullptr ) , mMinMaxOrigin( 0 ) { QSettings settings; setupUi( this ); mColormapTreeWidget->setColumnWidth( ColorColumn, 50 ); QString defaultPalette = settings.value( "/Raster/defaultPalette", "Spectral" ).toString(); mColorRampComboBox->populate( QgsStyle::defaultStyle() ); QgsDebugMsg( "defaultPalette = " + defaultPalette ); mColorRampComboBox->setCurrentIndex( mColorRampComboBox->findText( defaultPalette ) ); connect( mButtonEditRamp, SIGNAL( clicked() ), mColorRampComboBox, SLOT( editSourceRamp() ) ); if ( !mRasterLayer ) { return; } QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } // Must be before adding items to mBandComboBox (signal) mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) ); mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) ); mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); mMinMaxWidget->setMapCanvas( mCanvas ); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins( 0, 0, 0, 0 ); mMinMaxContainerWidget->setLayout( layout ); layout->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ), this, SLOT( loadMinMax( int, double, double, int ) ) ); //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mBandComboBox->addItem( displayBandName( i ), i ); } mColorInterpolationComboBox->addItem( tr( "Discrete" ), QgsColorRampShader::DISCRETE ); mColorInterpolationComboBox->addItem( tr( "Linear" ), QgsColorRampShader::INTERPOLATED ); mColorInterpolationComboBox->addItem( tr( "Exact" ), QgsColorRampShader::EXACT ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( QgsColorRampShader::INTERPOLATED ) ); mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous ); mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval ); mClassificationModeComboBox->addItem( tr( "Quantile" ), Quantile ); mNumberOfEntriesSpinBox->setValue( 5 ); // some default setFromRenderer( layer->renderer() ); // If there is currently no min/max, load default with user current default options if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() ) { mMinMaxWidget->load(); } on_mClassificationModeComboBox_currentIndexChanged( 0 ); resetClassifyButton(); connect( mClassificationModeComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mMinLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mColorRampComboBox, SIGNAL( sourceRampEdited() ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mColorRampComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mInvertCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mNumberOfEntriesSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( on_mClassifyButton_clicked() ) ); connect( mClipCheckBox, SIGNAL( toggled( bool ) ), this, SIGNAL( widgetChanged() ) ); }
bool QgsGrassRasterImport::import() { QgsDebugMsg( "entered" ); if ( !mPipe ) { setError( "Pipe is null." ); return false; } QgsRasterDataProvider * provider = mPipe->provider(); if ( !provider ) { setError( "Pipe has no provider." ); return false; } if ( !provider->isValid() ) { setError( "Provider is not valid." ); return false; } int redBand = 0; int greenBand = 0; int blueBand = 0; for ( int band = 1; band <= provider->bandCount(); band++ ) { QgsDebugMsg( QString( "band = %1" ).arg( band ) ); int colorInterpretation = provider->colorInterpretation( band ); if ( colorInterpretation == QgsRaster::RedBand ) { redBand = band; } else if ( colorInterpretation == QgsRaster::GreenBand ) { greenBand = band; } else if ( colorInterpretation == QgsRaster::BlueBand ) { blueBand = band; } QGis::DataType qgis_out_type = QGis::UnknownDataType; RASTER_MAP_TYPE data_type = -1; switch ( provider->dataType( band ) ) { case QGis::Byte: case QGis::UInt16: case QGis::Int16: case QGis::UInt32: case QGis::Int32: qgis_out_type = QGis::Int32; break; case QGis::Float32: qgis_out_type = QGis::Float32; break; case QGis::Float64: qgis_out_type = QGis::Float64; break; case QGis::ARGB32: case QGis::ARGB32_Premultiplied: qgis_out_type = QGis::Int32; // split to multiple bands? break; case QGis::CInt16: case QGis::CInt32: case QGis::CFloat32: case QGis::CFloat64: case QGis::UnknownDataType: setError( tr( "Data type %1 not supported" ).arg( provider->dataType( band ) ) ); return false; } QgsDebugMsg( QString( "data_type = %1" ).arg( data_type ) ); QString module = QgsGrass::qgisGrassModulePath() + "/qgis.r.in"; QStringList arguments; QString name = mGrassObject.name(); if ( provider->bandCount() > 1 ) { // raster.<band> to keep in sync with r.in.gdal name += QString( ".%1" ).arg( band ); } arguments.append( "output=" + name ); // get list of all output names QTemporaryFile gisrcFile; QProcess* process = 0; try { process = QgsGrass::startModule( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset(), module, arguments, gisrcFile ); } catch ( QgsGrass::Exception &e ) { setError( e.what() ); return false; } QDataStream outStream( process ); outStream << mExtent << ( qint32 )mXSize << ( qint32 )mYSize; outStream << ( qint32 )qgis_out_type; // calculate reasonable block size (5MB) int maximumTileHeight = 5000000 / mXSize; maximumTileHeight = std::max( 1, maximumTileHeight ); // smaller if reprojecting so that it can be canceled quickly if ( mPipe->projector() ) { maximumTileHeight = std::max( 1, 100000 / mXSize ); } QgsRasterIterator iter( mPipe->last() ); iter.setMaximumTileWidth( mXSize ); iter.setMaximumTileHeight( maximumTileHeight ); iter.startRasterRead( band, mXSize, mYSize, mExtent ); int iterLeft = 0; int iterTop = 0; int iterCols = 0; int iterRows = 0; QgsRasterBlock* block = 0; process->setReadChannel( QProcess::StandardOutput ); while ( iter.readNextRasterPart( band, iterCols, iterRows, &block, iterLeft, iterTop ) ) { for ( int row = 0; row < iterRows; row++ ) { if ( !block->convert( qgis_out_type ) ) { setError( tr( "Cannot convert block (%1) to data type %2" ).arg( block->toString() ).arg( qgis_out_type ) ); delete block; return false; } // prepare null values double noDataValue; if ( block->hasNoDataValue() ) { noDataValue = block->noDataValue(); } else { switch ( qgis_out_type ) { case QGis::Int32: noDataValue = -2147483648.0; break; case QGis::Float32: noDataValue = std::numeric_limits<float>::max() * -1.0; break; case QGis::Float64: noDataValue = std::numeric_limits<double>::max() * -1.0; break; default: // should not happen noDataValue = std::numeric_limits<double>::max() * -1.0; } for ( qgssize i = 0; i < ( qgssize )block->width()*block->height(); i++ ) { if ( block->isNoData( i ) ) { block->setValue( i, noDataValue ); } } } char * data = block->bits( row, 0 ); int size = iterCols * block->dataTypeSize(); QByteArray byteArray = QByteArray::fromRawData( data, size ); // does not copy data and does not take ownership if ( isCanceled() ) { outStream << true; // cancel module break; } outStream << false; // not canceled outStream << noDataValue; outStream << byteArray; // Without waitForBytesWritten() it does not finish ok on Windows (process timeout) process->waitForBytesWritten( -1 ); #ifndef Q_OS_WIN // wait until the row is written to allow quick cancel (don't send data to buffer) process->waitForReadyRead(); bool result; outStream >> result; #endif } delete block; if ( isCanceled() ) { outStream << true; // cancel module break; } } // TODO: send something back from module and read it here to close map correctly in module process->closeWriteChannel(); // TODO: best timeout? process->waitForFinished( 30000 ); QString stdoutString = process->readAllStandardOutput().data(); QString stderrString = process->readAllStandardError().data(); QString processResult = QString( "exitStatus=%1, exitCode=%2, error=%3, errorString=%4 stdout=%5, stderr=%6" ) .arg( process->exitStatus() ).arg( process->exitCode() ) .arg( process->error() ).arg( process->errorString() ) .arg( stdoutString.replace( "\n", ", " ) ).arg( stderrString.replace( "\n", ", " ) ); QgsDebugMsg( "processResult: " + processResult ); if ( process->exitStatus() != QProcess::NormalExit ) { setError( process->errorString() ); delete process; return false; } if ( process->exitCode() != 0 ) { setError( stderrString ); delete process; return false; } delete process; } QgsDebugMsg( QString( "redBand = %1 greenBand = %2 blueBand = %3" ).arg( redBand ).arg( greenBand ).arg( blueBand ) ); if ( redBand > 0 && greenBand > 0 && blueBand > 0 ) { // TODO: check if the group exists // I_find_group() QString name = mGrassObject.name(); G_TRY { QgsGrass::setMapset( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset() ); struct Ref ref; I_get_group_ref( name.toUtf8().data(), &ref ); QString redName = name + QString( ".%1" ).arg( redBand ); QString greenName = name + QString( ".%1" ).arg( greenBand ); QString blueName = name + QString( ".%1" ).arg( blueBand ); I_add_file_to_group_ref( redName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref ); I_add_file_to_group_ref( greenName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref ); I_add_file_to_group_ref( blueName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref ); I_put_group_ref( name.toUtf8().data(), &ref ); } G_CATCH( QgsGrass::Exception &e ) { QgsDebugMsg( QString( "Cannot create group: %1" ).arg( e.what() ) ); }
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ) : QgsRasterRendererWidget( layer, extent ) , mMinMaxWidget( NULL ) , mMinMaxOrigin( 0 ) { QSettings settings; setupUi( this ); mColormapTreeWidget->setColumnWidth( 1, 50 ); QString defaultPalette = settings.value( "/Raster/defaultPalette", "Spectral" ).toString(); mColorRampComboBox->populate( QgsStyleV2::defaultStyle() ); QgsDebugMsg( "defaultPalette = " + defaultPalette ); mColorRampComboBox->setCurrentIndex( mColorRampComboBox->findText( defaultPalette ) ); if ( !mRasterLayer ) { return; } QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } // Must be before adding items to mBandComboBox (signal) mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) ); mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) ); mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins( 0, 0, 0, 0 ); mMinMaxContainerWidget->setLayout( layout ); layout->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ), this, SLOT( loadMinMax( int, double, double, int ) ) ); //fill available bands into combo box int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { mBandComboBox->addItem( displayBandName( i ), i ); } mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 ); mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 ); mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 ); mColorInterpolationComboBox->setCurrentIndex( 1 ); mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous ); mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval ); //quantile would be nice as well mNumberOfEntriesSpinBox->setValue( 5 ); // some default setFromRenderer( layer->renderer() ); // If there is currently no min/max, load default with user current default options if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() ) { mMinMaxWidget->load(); } on_mClassificationModeComboBox_currentIndexChanged( 0 ); resetClassifyButton(); }
QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ) : QgsRasterRendererWidget( layer, extent ) , mMinMaxWidget( nullptr ) , mDisableMinMaxWidgetRefresh( false ) { setupUi( this ); createValidators(); if ( mRasterLayer ) { QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); if ( !provider ) { return; } mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this ); mMinMaxWidget->setExtent( extent ); mMinMaxWidget->setMapCanvas( mCanvas ); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins( 0, 0, 0, 0 ); mMinMaxContainerWidget->setLayout( layout ); layout->addWidget( mMinMaxWidget ); connect( mMinMaxWidget, &QgsRasterMinMaxWidget::widgetChanged, this, &QgsMultiBandColorRendererWidget::widgetChanged ); connect( mMinMaxWidget, &QgsRasterMinMaxWidget::load, this, &QgsMultiBandColorRendererWidget::loadMinMax ); connect( mRedBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onBandChanged( int ) ) ); connect( mGreenBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onBandChanged( int ) ) ); connect( mBlueBandComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onBandChanged( int ) ) ); //fill available bands into combo boxes mRedBandComboBox->addItem( tr( "Not set" ), -1 ); mGreenBandComboBox->addItem( tr( "Not set" ), -1 ); mBlueBandComboBox->addItem( tr( "Not set" ), -1 ); //contrast enhancement algorithms mContrastEnhancementAlgorithmComboBox->addItem( tr( "No enhancement" ), QgsContrastEnhancement::NoEnhancement ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch to MinMax" ), QgsContrastEnhancement::StretchToMinimumMaximum ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Stretch and clip to MinMax" ), QgsContrastEnhancement::StretchAndClipToMinimumMaximum ); mContrastEnhancementAlgorithmComboBox->addItem( tr( "Clip to MinMax" ), QgsContrastEnhancement::ClipToMinimumMaximum ); int nBands = provider->bandCount(); for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1 { QString bandName = displayBandName( i ); mRedBandComboBox->addItem( bandName, i ); mGreenBandComboBox->addItem( bandName, i ); mBlueBandComboBox->addItem( bandName, i ); } setFromRenderer( mRasterLayer->renderer() ); onBandChanged( 0 ); // reset mMinMaxWidget bands connect( mContrastEnhancementAlgorithmComboBox, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( widgetChanged() ) ); connect( mRedMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mRedMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mGreenMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mGreenMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mBlueMaxLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); connect( mBlueMinLineEdit, SIGNAL( textChanged( QString ) ), this, SIGNAL( widgetChanged() ) ); } }