Skip to content

Commit

Permalink
fix nightly build
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14445 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 29, 2010
1 parent fb48cc0 commit d1fe144
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 135 deletions.
2 changes: 1 addition & 1 deletion cmake/Bison.cmake
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions cmake/Flex.cmake
Expand Up @@ -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)
23 changes: 14 additions & 9 deletions src/analysis/raster/qgsrastercalcnode.cpp
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
}

3 changes: 3 additions & 0 deletions src/analysis/raster/qgsrastercalcnode.h
Expand Up @@ -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;
Expand All @@ -76,4 +78,5 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
Operator mOperator;
};


#endif // QGSRASTERCALCNODE_H
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsrastercalcparser.yy
Expand Up @@ -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);
Expand Down
78 changes: 38 additions & 40 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -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 )
{
}

Expand All @@ -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
}
Expand All @@ -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;
}
Expand All @@ -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()];
Expand All @@ -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() );
Expand All @@ -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
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 ];
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 ];
}
Expand All @@ -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;
}
Expand Down

0 comments on commit d1fe144

Please sign in to comment.