Skip to content
Permalink
Browse files

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
  • Loading branch information
jef-n committed Feb 23, 2015
1 parent d62ac6c commit 06e2186d0f28422da4c3dfc8176248ab4a459d78
@@ -35,7 +35,8 @@ class QgsRasterCalcNode
opLE, // <=
opAND,
opOR,
opSIGN //change sign
opSIGN, // change sign
opNONE,
};

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

QgsRasterCalcNode();
@@ -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 );
@@ -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 )

0 comments on commit 06e2186

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