Skip to content
Permalink
Browse files

fix nightly build

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14445 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Oct 29, 2010
1 parent 91e805f commit 4d7c419a5f6a3003d70de18d77dc232de720154a
@@ -93,4 +93,4 @@ MACRO(ADD_BISON_FILES_PREFIX _sources prefix)

SET(${_sources} ${${_sources}} ${_out} )
ENDFOREACH (_current_FILE)
ENDMACRO(ADD_BISON_FILES)
ENDMACRO(ADD_BISON_FILES_PREFIX)
@@ -65,12 +65,12 @@ MACRO(ADD_FLEX_FILES_PREFIX _sources prefix )
OUTPUT ${_out}
COMMAND ${FLEX_EXECUTABLE}
ARGS
-P ${prefix}
-P${prefix}
-o${_out} -d
${_in}
DEPENDS ${_in}
)

SET(${_sources} ${${_sources}} ${_out} )
ENDFOREACH (_current_FILE)
ENDFOREACH (_current_FILE)
ENDMACRO(ADD_FLEX_FILES_PREFIX)
@@ -18,11 +18,11 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName ): mType( tRaste

QgsRasterCalcNode::~QgsRasterCalcNode()
{
if( mLeft )
if ( mLeft )
{
delete mLeft;
}
if( mRight )
if ( mRight )
{
delete mRight;
}
@@ -33,10 +33,10 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
//if type is raster ref: return a copy of the corresponding matrix

//if type is operator, call the proper matrix operations
if( mType == tRasterRef )
if ( mType == tRasterRef )
{
QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find( mRasterName );
if( it == rasterData.end() )
if ( it == rasterData.end() )
{
return false;
}
@@ -47,20 +47,20 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
result.setData(( *it )->nColumns(), ( *it )->nRows(), data );
return true;
}
else if( mType == tOperator )
else if ( mType == tOperator )
{
QgsRasterMatrix leftMatrix, rightMatrix;
QgsRasterMatrix resultMatrix;
if( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
if ( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
{
return false;
}
if( mRight && !mRight->calculate( rasterData, rightMatrix ) )
if ( mRight && !mRight->calculate( rasterData, rightMatrix ) )
{
return false;
}

switch( mOperator )
switch ( mOperator )
{
case opPLUS:
leftMatrix.add( rightMatrix );
@@ -106,7 +106,7 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
result.setData( newNColumns, newNRows, leftMatrix.takeData() );
return true;
}
else if( mType == tNumber )
else if ( mType == tNumber )
{
float* data = new float[1];
data[0] = mNumber;
@@ -116,4 +116,9 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
return false;
}

QgsRasterCalcNode* QgsRasterCalcNode::parseRasterCalcString( const QString& str, QString& parserErrorMsg )
{
extern QgsRasterCalcNode* localParseRasterCalcString( const QString& str, QString& parserErrorMsg );
return localParseRasterCalcString( str, parserErrorMsg );
}

@@ -66,6 +66,8 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
/**Calculates result (might be real matrix or single number)*/
bool calculate( QMap<QString, QgsRasterMatrix*>& rasterData, QgsRasterMatrix& result ) const;

static QgsRasterCalcNode* parseRasterCalcString( const QString& str, QString& parserErrorMsg );

private:
Type mType;
QgsRasterCalcNode* mLeft;
@@ -76,4 +78,5 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
Operator mOperator;
};


#endif // QGSRASTERCALCNODE_H
@@ -104,7 +104,7 @@ void joinTmpNodes(QgsRasterCalcNode* parent, QgsRasterCalcNode* left, QgsRasterC
}


QgsRasterCalcNode* parseRasterCalcString(const QString& str, QString& parserErrorMsg)
QgsRasterCalcNode* localParseRasterCalcString(const QString& str, QString& parserErrorMsg)
{
// list should be empty when starting
Q_ASSERT(gTmpNodes.count() == 0);
@@ -22,11 +22,9 @@
#include "cpl_string.h"
#include <QProgressDialog>

extern QgsRasterCalcNode* parseRasterCalcString( const QString& str, QString& parserErrorMsg );

QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries ): mFormulaString( formulaString ), mOutputFile( outputFile ), mOutputFormat( outputFormat ),
mOutputRectangle( outputExtent ), mNumOutputColumns( nOutputColumns ), mNumOutputRows( nOutputRows ), mRasterEntries( rasterEntries )
mOutputRectangle( outputExtent ), mNumOutputColumns( nOutputColumns ), mNumOutputRows( nOutputRows ), mRasterEntries( rasterEntries )
{
}

@@ -38,8 +36,8 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
{
//prepare search string / tree
QString errorString;
QgsRasterCalcNode* calcNode = parseRasterCalcString( mFormulaString, errorString );
if( !calcNode )
QgsRasterCalcNode* calcNode = QgsRasterCalcNode::parseRasterCalcString( mFormulaString, errorString );
if ( !calcNode )
{
//error
}
@@ -53,19 +51,19 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
QVector< GDALDatasetH > mInputDatasets; //raster references and corresponding dataset

QVector<QgsRasterCalculatorEntry>::const_iterator it = mRasterEntries.constBegin();
for( ; it != mRasterEntries.constEnd(); ++it )
for ( ; it != mRasterEntries.constEnd(); ++it )
{
if( !it->raster ) // no raster layer in entry
if ( !it->raster ) // no raster layer in entry
{
return 2;
}
GDALDatasetH inputDataset = GDALOpen( it->raster->source().toLocal8Bit().data(), GA_ReadOnly );
if( inputDataset == NULL )
if ( inputDataset == NULL )
{
return 2;
}
GDALRasterBandH inputRasterBand = GDALGetRasterBand( inputDataset, it->bandNumber );
if( inputRasterBand == NULL )
if ( inputRasterBand == NULL )
{
return 2;
}
@@ -77,37 +75,37 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )

//open output dataset for writing
GDALDriverH outputDriver = openOutputDriver();
if( outputDriver == NULL )
if ( outputDriver == NULL )
{
return 1;
}
GDALDatasetH outputDataset = openOutputFile( outputDriver );
GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
float* resultScanLine = ( float * ) CPLMalloc( sizeof( float ) * mNumOutputColumns );

if( p )
if ( p )
{
p->setMaximum( mNumOutputRows );
}

QgsRasterMatrix resultMatrix;

//read / write line by line
for( int i = 0; i < mNumOutputRows; ++i )
for ( int i = 0; i < mNumOutputRows; ++i )
{
if( p )
if ( p )
{
p->setValue( i );
}

if( p && p->wasCanceled() )
if ( p && p->wasCanceled() )
{
break;
}

//fill buffers
QMap< QString, QgsRasterMatrix* >::iterator bufferIt = inputScanLineData.begin();
for( ; bufferIt != inputScanLineData.end(); ++bufferIt )
for ( ; bufferIt != inputScanLineData.end(); ++bufferIt )
{
double sourceTransformation[6];
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
@@ -116,38 +114,38 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
readRasterPart( targetGeoTransform, 0, i, mNumOutputColumns, 1, sourceTransformation, sourceRasterBand, bufferIt.value()->data() );
}

if( calcNode->calculate( inputScanLineData, resultMatrix ) )
if ( calcNode->calculate( inputScanLineData, resultMatrix ) )
{
//write scanline to the dataset
if( GDALRasterIO( outputRasterBand, GF_Write, 0, i, mNumOutputColumns, 1, resultMatrix.data(), mNumOutputColumns, 1, GDT_Float32, 0, 0 ) != CE_None )
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, mNumOutputColumns, 1, resultMatrix.data(), mNumOutputColumns, 1, GDT_Float32, 0, 0 ) != CE_None )
{
qWarning( "RasterIO error!" );
}
}

}

if( p )
if ( p )
{
p->setValue( mNumOutputRows );
}

//close datasets and release memory
delete calcNode;
QMap< QString, QgsRasterMatrix* >::iterator bufferIt = inputScanLineData.begin();
for( ; bufferIt != inputScanLineData.end(); ++bufferIt )
for ( ; bufferIt != inputScanLineData.end(); ++bufferIt )
{
delete bufferIt.value();
}
inputScanLineData.clear();

QVector< GDALDatasetH >::iterator datasetIt = mInputDatasets.begin();
for( ; datasetIt != mInputDatasets.end(); ++ datasetIt )
for ( ; datasetIt != mInputDatasets.end(); ++ datasetIt )
{
GDALClose( *datasetIt );
}

if( p && p->wasCanceled() )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
@@ -169,13 +167,13 @@ GDALDriverH QgsRasterCalculator::openOutputDriver()
//open driver
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );

if( outputDriver == NULL )
if ( outputDriver == NULL )
{
return outputDriver; //return NULL, driver does not exist
}

driverMetadata = GDALGetMetadata( outputDriver, NULL );
if( !CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
if ( !CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
{
return NULL; //driver exist, but it does not support the create operation
}
@@ -188,7 +186,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
//open output file
char **papszOptions = NULL;
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
if( outputDataset == NULL )
if ( outputDataset == NULL )
{
return outputDataset;
}
@@ -204,7 +202,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffset, int yOffset, int nCols, int nRows, double* sourceTransform, GDALRasterBandH sourceBand, float* rasterBuffer )
{
//If dataset transform is the same as the requested transform, do a normal GDAL raster io
if( transformationsEqual( targetGeotransform, sourceTransform ) )
if ( transformationsEqual( targetGeotransform, sourceTransform ) )
{
GDALRasterIO( sourceBand, GF_Read, xOffset, yOffset, nCols, nRows, rasterBuffer, nCols, nRows, GDT_Float32, 0, 0 );
return;
@@ -219,10 +217,10 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
QgsRectangle intersection = targetRect.intersect( &sourceRect );

//no intersection, fill all the pixels with nodata values
if( intersection.isEmpty() )
if ( intersection.isEmpty() )
{
int nPixels = nCols * nRows;
for( int i = 0; i < nPixels; ++i )
for ( int i = 0; i < nPixels; ++i )
{
rasterBuffer[i] = nodataValue;
}
@@ -248,17 +246,17 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
double targetPixelY = targetGeotransform[3] + targetGeotransform[5] * yOffset + targetGeotransform[5] / 2.0; //coordinates of current target pixel
int sourceIndexX, sourceIndexY; //current raster index in source pixels
double sx, sy;
for( int i = 0; i < nRows; ++i )
for ( int i = 0; i < nRows; ++i )
{
targetPixelX = targetPixelXMin;
for( int j = 0; j < nCols; ++j )
for ( int j = 0; j < nCols; ++j )
{
sx = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
sourceIndexX = sx > 0 ? sx : floor( sx );
sy = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
sourceIndexY = sy > 0 ? sy : floor( sy );
if( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
if ( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
{
rasterBuffer[j + i*nRows] = sourceRaster[ sourceIndexX + nSourcePixelsX * sourceIndexY ];
}
@@ -276,7 +274,7 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse

#if 0
//If dataset transform is the same as the requested transform, do a normal GDAL raster io
if( transformationsEqual( targetGeotransform, sourceTransform ) )
if ( transformationsEqual( targetGeotransform, sourceTransform ) )
{
GDALRasterIO( sourceBand, GF_Read, xOffset, yOffset, nCols, nRows, rasterBuffer, nCols, nRows, GDT_Float32, 0, 0 );
return;
@@ -294,10 +292,10 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
QgsRectangle intersection = targetRect.intersect( &sourceRect );

//no intersection, fill all the pixels with nodata values
if( intersection.isEmpty() )
if ( intersection.isEmpty() )
{
int nPixels = nCols * nRows;
for( int i = 0; i < nPixels; ++i )
for ( int i = 0; i < nPixels; ++i )
{
rasterBuffer[i] = 0;
}
@@ -322,15 +320,15 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
double targetPixelXMin = targetGeotransform[0] + targetGeotransform[1] * xOffset + targetGeotransform[1] / 2.0;
double targetPixelY = targetGeotransform[3] + targetGeotransform[5] * yOffset + targetGeotransform[5] / 2.0; //coordinates of current target pixel
int sourceIndexX, sourceIndexY; //current raster index in source pixels
for( int i = 0; i < nRows; ++i )
for ( int i = 0; i < nRows; ++i )
{
targetPixelX = targetPixelXMin;
for( int j = 0; j < nCols; ++j )
for ( int j = 0; j < nCols; ++j )
{
sourceIndexX = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
sourceIndexY = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
if( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
if ( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
{
rasterBuffer[j + i*nCols] = sourceRaster[ sourceIndexX + nSourcePixelsX * sourceIndexY ];
}
@@ -350,9 +348,9 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse

bool QgsRasterCalculator::transformationsEqual( double* t1, double* t2 ) const
{
for( int i = 0; i < 6; ++i )
for ( int i = 0; i < 6; ++i )
{
if( !doubleNear( t1[i], t2[i] ) )
if ( !doubleNear( t1[i], t2[i] ) )
{
return false;
}

0 comments on commit 4d7c419

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