Skip to content

Commit

Permalink
raster calculator fixes (fixes #12238)
Browse files Browse the repository at this point in the history
* 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 06e2186
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
3 changes: 2 additions & 1 deletion python/analysis/raster/qgsrastercalcnode.sip
Expand Up @@ -35,7 +35,8 @@ class QgsRasterCalcNode
opLE, // <=
opAND,
opOR,
opSIGN //change sign
opSIGN, // change sign
opNONE,
};

QgsRasterCalcNode();
Expand Down
8 changes: 5 additions & 3 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -20,7 +20,7 @@ QgsRasterCalcNode::QgsRasterCalcNode()
, mLeft( 0 )
, mRight( 0 )
, mNumber( 0 )
, mOperator( opPLUS ) //not used
, mOperator( opNONE )
{
}

Expand All @@ -29,7 +29,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( double number )
, mLeft( 0 )
, mRight( 0 )
, mNumber( number )
, mOperator( opPLUS ) //not used
, mOperator( opNONE )
{
}

Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/raster/qgsrastercalcnode.h
Expand Up @@ -57,7 +57,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
opLE, // <=
opAND,
opOR,
opSIGN //change sign
opSIGN, // change sign
opNONE,
};

QgsRasterCalcNode();
Expand Down
11 changes: 5 additions & 6 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -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 )
Expand All @@ -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() );
}
Expand Down Expand Up @@ -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 );
Expand Down
13 changes: 5 additions & 8 deletions src/app/qgsrastercalcdialog.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit 06e2186

Please sign in to comment.