Skip to content

Commit 0ccc07a

Browse files
committed
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
1 parent e04570c commit 0ccc07a

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

python/analysis/raster/qgsrastercalcnode.sip

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class QgsRasterCalcNode
3535
opLE, // <=
3636
opAND,
3737
opOR,
38-
opSIGN //change sign
38+
opSIGN, // change sign
39+
opNONE,
3940
};
4041

4142
QgsRasterCalcNode();

src/analysis/raster/qgsrastercalcnode.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ QgsRasterCalcNode::QgsRasterCalcNode()
2020
, mLeft( 0 )
2121
, mRight( 0 )
2222
, mNumber( 0 )
23-
, mOperator( opPLUS ) //not used
23+
, mOperator( opNONE )
2424
{
2525
}
2626

@@ -29,7 +29,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( double number )
2929
, mLeft( 0 )
3030
, mRight( 0 )
3131
, mNumber( number )
32-
, mOperator( opPLUS ) //not used
32+
, mOperator( opNONE )
3333
{
3434
}
3535

@@ -48,8 +48,10 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName )
4848
, mRight( 0 )
4949
, mNumber( 0 )
5050
, mRasterName( rasterName )
51-
, mOperator( opPLUS ) //not used
51+
, mOperator( opNONE )
5252
{
53+
if ( mRasterName.startsWith( '"' ) && mRasterName.endsWith( '"' ) )
54+
mRasterName = mRasterName.mid( 1, mRasterName.size() - 2 );
5355
}
5456

5557
QgsRasterCalcNode::~QgsRasterCalcNode()

src/analysis/raster/qgsrastercalcnode.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
5757
opLE, // <=
5858
opAND,
5959
opOR,
60-
opSIGN //change sign
60+
opSIGN, // change sign
61+
opNONE,
6162
};
6263

6364
QgsRasterCalcNode();

src/analysis/raster/qgsrastercalculator.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
160160
QgsRasterMatrix resultMatrix;
161161

162162
//read / write line by line
163-
bool encounteredError = false;
164163
for ( int i = 0; i < mNumOutputRows; ++i )
165164
{
166165
if ( p )
@@ -179,11 +178,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
179178
{
180179
double sourceTransformation[6];
181180
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
182-
if ( !GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation ) )
181+
if ( GDALGetGeoTransform( GDALGetBandDataset( sourceRasterBand ), sourceTransformation ) != CE_None )
183182
{
184-
encounteredError = true;
185-
break;
183+
qWarning( "GDALGetGeoTransform failed!" );
186184
}
185+
187186
//the function readRasterPart calls GDALRasterIO (and ev. does some conversion if raster transformations are not the same)
188187
readRasterPart( targetGeoTransform, 0, i, mNumOutputColumns, 1, sourceTransformation, sourceRasterBand, bufferIt.value()->data() );
189188
}
@@ -249,11 +248,11 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
249248
GDALClose( *datasetIt );
250249
}
251250

252-
if (( p && p->wasCanceled() ) || encounteredError )
251+
if ( p && p->wasCanceled() )
253252
{
254253
//delete the dataset without closing (because it is faster)
255254
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
256-
return encounteredError ? 1 : 3;
255+
return 3;
257256
}
258257
GDALClose( outputDataset );
259258
CPLFree( resultScanLine );

src/app/qgsrastercalcdialog.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,12 @@ bool QgsRasterCalcDialog::expressionValid() const
296296

297297
bool QgsRasterCalcDialog::filePathValid() const
298298
{
299-
QString outputPath = QFileInfo( mOutputLayerLineEdit->text() ).absolutePath();
300-
if ( QFileInfo( outputPath ).isWritable() )
301-
{
302-
return true;
303-
}
304-
else
305-
{
299+
QString outputPath = mOutputLayerLineEdit->text();
300+
if ( outputPath.isEmpty() )
306301
return false;
307-
}
302+
303+
outputPath = QFileInfo( outputPath ).absolutePath();
304+
return QFileInfo( outputPath ).isWritable();
308305
}
309306

310307
void QgsRasterCalcDialog::on_mRasterBandsListWidget_itemDoubleClicked( QListWidgetItem* item )

0 commit comments

Comments
 (0)