raster calculator fixes (fixes #12238)

* GDALGetGeoTransform failures can be ignored (partly reverts 0080f9e)
* handle quoted raster references
* don't complain if the output file is not yet set
This commit is contained in:
Juergen E. Fischer 2015-02-23 21:48:04 +01:00
parent e04570cc89
commit 0ccc07af0e
5 changed files with 19 additions and 19 deletions

View File

@ -35,7 +35,8 @@ class QgsRasterCalcNode
opLE, // <=
opAND,
opOR,
opSIGN //change sign
opSIGN, // change sign
opNONE,
};
QgsRasterCalcNode();

View File

@ -20,7 +20,7 @@ QgsRasterCalcNode::QgsRasterCalcNode()
, mLeft( 0 )
, mRight( 0 )
, mNumber( 0 )
, mOperator( opPLUS ) //not used
, mOperator( opNONE )
{
}
@ -29,7 +29,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( double number )
, mLeft( 0 )
, mRight( 0 )
, mNumber( number )
, mOperator( opPLUS ) //not used
, mOperator( opNONE )
{
}
@ -48,8 +48,10 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName )
, mRight( 0 )
, mNumber( 0 )
, mRasterName( rasterName )
, mOperator( opPLUS ) //not used
, mOperator( opNONE )
{
if ( mRasterName.startsWith( '"' ) && mRasterName.endsWith( '"' ) )
mRasterName = mRasterName.mid( 1, mRasterName.size() - 2 );
}
QgsRasterCalcNode::~QgsRasterCalcNode()

View File

@ -57,7 +57,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opLE, // <=
opAND,
opOR,
opSIGN //change sign
opSIGN, // change sign
opNONE,
};
QgsRasterCalcNode();

View File

@ -160,7 +160,6 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
QgsRasterMatrix resultMatrix;
//read / write line by line
bool encounteredError = false;
for ( int i = 0; i < mNumOutputRows; ++i )
{
if ( p )
@ -179,11 +178,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
{
double sourceTransformation[6];
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
if ( !GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation ) )
if ( GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation ) != CE_None )
{
encounteredError = true;
break;
qWarning( "GDALGetGeoTransform failed!" );
}
//the function readRasterPart calls GDALRasterIO (and ev. does some conversion if raster transformations are not the same)
readRasterPart( targetGeoTransform, 0, i, mNumOutputColumns, 1, sourceTransformation, sourceRasterBand, bufferIt.value()->data() );
}
@ -249,11 +248,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
GDALClose( *datasetIt );
}
if (( p && p->wasCanceled() ) || encounteredError )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
return encounteredError ? 1 : 3;
return 3;
}
GDALClose( outputDataset );
CPLFree( resultScanLine );

View File

@ -296,15 +296,12 @@ bool QgsRasterCalcDialog::expressionValid() const
bool QgsRasterCalcDialog::filePathValid() const
{
QString outputPath = QFileInfo( mOutputLayerLineEdit->text() ).absolutePath();
if ( QFileInfo( outputPath ).isWritable() )
{
return true;
}
else
{
QString outputPath = mOutputLayerLineEdit->text();
if ( outputPath.isEmpty() )
return false;
}
outputPath = QFileInfo( outputPath ).absolutePath();
return QFileInfo( outputPath ).isWritable();
}
void QgsRasterCalcDialog::on_mRasterBandsListWidget_itemDoubleClicked( QListWidgetItem* item )