mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
fix nightly build
git-svn-id: http://svn.osgeo.org/qgis/trunk@14445 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
fb48cc0cc3
commit
d1fe144899
@ -93,4 +93,4 @@ MACRO(ADD_BISON_FILES_PREFIX _sources prefix)
|
|||||||
|
|
||||||
SET(${_sources} ${${_sources}} ${_out} )
|
SET(${_sources} ${${_sources}} ${_out} )
|
||||||
ENDFOREACH (_current_FILE)
|
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}
|
OUTPUT ${_out}
|
||||||
COMMAND ${FLEX_EXECUTABLE}
|
COMMAND ${FLEX_EXECUTABLE}
|
||||||
ARGS
|
ARGS
|
||||||
-P ${prefix}
|
-P${prefix}
|
||||||
-o${_out} -d
|
-o${_out} -d
|
||||||
${_in}
|
${_in}
|
||||||
DEPENDS ${_in}
|
DEPENDS ${_in}
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(${_sources} ${${_sources}} ${_out} )
|
SET(${_sources} ${${_sources}} ${_out} )
|
||||||
ENDFOREACH (_current_FILE)
|
ENDFOREACH (_current_FILE)
|
||||||
ENDMACRO(ADD_FLEX_FILES_PREFIX)
|
ENDMACRO(ADD_FLEX_FILES_PREFIX)
|
||||||
|
@ -18,11 +18,11 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName ): mType( tRaste
|
|||||||
|
|
||||||
QgsRasterCalcNode::~QgsRasterCalcNode()
|
QgsRasterCalcNode::~QgsRasterCalcNode()
|
||||||
{
|
{
|
||||||
if( mLeft )
|
if ( mLeft )
|
||||||
{
|
{
|
||||||
delete mLeft;
|
delete mLeft;
|
||||||
}
|
}
|
||||||
if( mRight )
|
if ( mRight )
|
||||||
{
|
{
|
||||||
delete 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 raster ref: return a copy of the corresponding matrix
|
||||||
|
|
||||||
//if type is operator, call the proper matrix operations
|
//if type is operator, call the proper matrix operations
|
||||||
if( mType == tRasterRef )
|
if ( mType == tRasterRef )
|
||||||
{
|
{
|
||||||
QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find( mRasterName );
|
QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find( mRasterName );
|
||||||
if( it == rasterData.end() )
|
if ( it == rasterData.end() )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -47,20 +47,20 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
|
|||||||
result.setData(( *it )->nColumns(), ( *it )->nRows(), data );
|
result.setData(( *it )->nColumns(), ( *it )->nRows(), data );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if( mType == tOperator )
|
else if ( mType == tOperator )
|
||||||
{
|
{
|
||||||
QgsRasterMatrix leftMatrix, rightMatrix;
|
QgsRasterMatrix leftMatrix, rightMatrix;
|
||||||
QgsRasterMatrix resultMatrix;
|
QgsRasterMatrix resultMatrix;
|
||||||
if( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
|
if ( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( mRight && !mRight->calculate( rasterData, rightMatrix ) )
|
if ( mRight && !mRight->calculate( rasterData, rightMatrix ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( mOperator )
|
switch ( mOperator )
|
||||||
{
|
{
|
||||||
case opPLUS:
|
case opPLUS:
|
||||||
leftMatrix.add( rightMatrix );
|
leftMatrix.add( rightMatrix );
|
||||||
@ -106,7 +106,7 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
|
|||||||
result.setData( newNColumns, newNRows, leftMatrix.takeData() );
|
result.setData( newNColumns, newNRows, leftMatrix.takeData() );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if( mType == tNumber )
|
else if ( mType == tNumber )
|
||||||
{
|
{
|
||||||
float* data = new float[1];
|
float* data = new float[1];
|
||||||
data[0] = mNumber;
|
data[0] = mNumber;
|
||||||
@ -116,4 +116,9 @@ bool QgsRasterCalcNode::calculate( QMap<QString, QgsRasterMatrix*>& rasterData,
|
|||||||
return false;
|
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)*/
|
/**Calculates result (might be real matrix or single number)*/
|
||||||
bool calculate( QMap<QString, QgsRasterMatrix*>& rasterData, QgsRasterMatrix& result ) const;
|
bool calculate( QMap<QString, QgsRasterMatrix*>& rasterData, QgsRasterMatrix& result ) const;
|
||||||
|
|
||||||
|
static QgsRasterCalcNode* parseRasterCalcString( const QString& str, QString& parserErrorMsg );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type mType;
|
Type mType;
|
||||||
QgsRasterCalcNode* mLeft;
|
QgsRasterCalcNode* mLeft;
|
||||||
@ -76,4 +78,5 @@ class ANALYSIS_EXPORT QgsRasterCalcNode
|
|||||||
Operator mOperator;
|
Operator mOperator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // QGSRASTERCALCNODE_H
|
#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
|
// list should be empty when starting
|
||||||
Q_ASSERT(gTmpNodes.count() == 0);
|
Q_ASSERT(gTmpNodes.count() == 0);
|
||||||
|
@ -22,11 +22,9 @@
|
|||||||
#include "cpl_string.h"
|
#include "cpl_string.h"
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
|
||||||
extern QgsRasterCalcNode* parseRasterCalcString( const QString& str, QString& parserErrorMsg );
|
|
||||||
|
|
||||||
QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
|
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 ),
|
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
|
//prepare search string / tree
|
||||||
QString errorString;
|
QString errorString;
|
||||||
QgsRasterCalcNode* calcNode = parseRasterCalcString( mFormulaString, errorString );
|
QgsRasterCalcNode* calcNode = QgsRasterCalcNode::parseRasterCalcString( mFormulaString, errorString );
|
||||||
if( !calcNode )
|
if ( !calcNode )
|
||||||
{
|
{
|
||||||
//error
|
//error
|
||||||
}
|
}
|
||||||
@ -53,19 +51,19 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
QVector< GDALDatasetH > mInputDatasets; //raster references and corresponding dataset
|
QVector< GDALDatasetH > mInputDatasets; //raster references and corresponding dataset
|
||||||
|
|
||||||
QVector<QgsRasterCalculatorEntry>::const_iterator it = mRasterEntries.constBegin();
|
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;
|
return 2;
|
||||||
}
|
}
|
||||||
GDALDatasetH inputDataset = GDALOpen( it->raster->source().toLocal8Bit().data(), GA_ReadOnly );
|
GDALDatasetH inputDataset = GDALOpen( it->raster->source().toLocal8Bit().data(), GA_ReadOnly );
|
||||||
if( inputDataset == NULL )
|
if ( inputDataset == NULL )
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
GDALRasterBandH inputRasterBand = GDALGetRasterBand( inputDataset, it->bandNumber );
|
GDALRasterBandH inputRasterBand = GDALGetRasterBand( inputDataset, it->bandNumber );
|
||||||
if( inputRasterBand == NULL )
|
if ( inputRasterBand == NULL )
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
@ -77,7 +75,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
|
|
||||||
//open output dataset for writing
|
//open output dataset for writing
|
||||||
GDALDriverH outputDriver = openOutputDriver();
|
GDALDriverH outputDriver = openOutputDriver();
|
||||||
if( outputDriver == NULL )
|
if ( outputDriver == NULL )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -85,7 +83,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
|
GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
|
||||||
float* resultScanLine = ( float * ) CPLMalloc( sizeof( float ) * mNumOutputColumns );
|
float* resultScanLine = ( float * ) CPLMalloc( sizeof( float ) * mNumOutputColumns );
|
||||||
|
|
||||||
if( p )
|
if ( p )
|
||||||
{
|
{
|
||||||
p->setMaximum( mNumOutputRows );
|
p->setMaximum( mNumOutputRows );
|
||||||
}
|
}
|
||||||
@ -93,21 +91,21 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
QgsRasterMatrix resultMatrix;
|
QgsRasterMatrix resultMatrix;
|
||||||
|
|
||||||
//read / write line by line
|
//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 );
|
p->setValue( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( p && p->wasCanceled() )
|
if ( p && p->wasCanceled() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//fill buffers
|
//fill buffers
|
||||||
QMap< QString, QgsRasterMatrix* >::iterator bufferIt = inputScanLineData.begin();
|
QMap< QString, QgsRasterMatrix* >::iterator bufferIt = inputScanLineData.begin();
|
||||||
for( ; bufferIt != inputScanLineData.end(); ++bufferIt )
|
for ( ; bufferIt != inputScanLineData.end(); ++bufferIt )
|
||||||
{
|
{
|
||||||
double sourceTransformation[6];
|
double sourceTransformation[6];
|
||||||
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
|
GDALRasterBandH sourceRasterBand = mInputRasterBands[bufferIt.key()];
|
||||||
@ -116,10 +114,10 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
readRasterPart( targetGeoTransform, 0, i, mNumOutputColumns, 1, sourceTransformation, sourceRasterBand, bufferIt.value()->data() );
|
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
|
//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!" );
|
qWarning( "RasterIO error!" );
|
||||||
}
|
}
|
||||||
@ -127,7 +125,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( p )
|
if ( p )
|
||||||
{
|
{
|
||||||
p->setValue( mNumOutputRows );
|
p->setValue( mNumOutputRows );
|
||||||
}
|
}
|
||||||
@ -135,19 +133,19 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
|
|||||||
//close datasets and release memory
|
//close datasets and release memory
|
||||||
delete calcNode;
|
delete calcNode;
|
||||||
QMap< QString, QgsRasterMatrix* >::iterator bufferIt = inputScanLineData.begin();
|
QMap< QString, QgsRasterMatrix* >::iterator bufferIt = inputScanLineData.begin();
|
||||||
for( ; bufferIt != inputScanLineData.end(); ++bufferIt )
|
for ( ; bufferIt != inputScanLineData.end(); ++bufferIt )
|
||||||
{
|
{
|
||||||
delete bufferIt.value();
|
delete bufferIt.value();
|
||||||
}
|
}
|
||||||
inputScanLineData.clear();
|
inputScanLineData.clear();
|
||||||
|
|
||||||
QVector< GDALDatasetH >::iterator datasetIt = mInputDatasets.begin();
|
QVector< GDALDatasetH >::iterator datasetIt = mInputDatasets.begin();
|
||||||
for( ; datasetIt != mInputDatasets.end(); ++ datasetIt )
|
for ( ; datasetIt != mInputDatasets.end(); ++ datasetIt )
|
||||||
{
|
{
|
||||||
GDALClose( *datasetIt );
|
GDALClose( *datasetIt );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( p && p->wasCanceled() )
|
if ( p && p->wasCanceled() )
|
||||||
{
|
{
|
||||||
//delete the dataset without closing (because it is faster)
|
//delete the dataset without closing (because it is faster)
|
||||||
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
|
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
|
||||||
@ -169,13 +167,13 @@ GDALDriverH QgsRasterCalculator::openOutputDriver()
|
|||||||
//open driver
|
//open driver
|
||||||
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );
|
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );
|
||||||
|
|
||||||
if( outputDriver == NULL )
|
if ( outputDriver == NULL )
|
||||||
{
|
{
|
||||||
return outputDriver; //return NULL, driver does not exist
|
return outputDriver; //return NULL, driver does not exist
|
||||||
}
|
}
|
||||||
|
|
||||||
driverMetadata = GDALGetMetadata( outputDriver, NULL );
|
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
|
return NULL; //driver exist, but it does not support the create operation
|
||||||
}
|
}
|
||||||
@ -188,7 +186,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
|
|||||||
//open output file
|
//open output file
|
||||||
char **papszOptions = NULL;
|
char **papszOptions = NULL;
|
||||||
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
|
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
|
||||||
if( outputDataset == NULL )
|
if ( outputDataset == NULL )
|
||||||
{
|
{
|
||||||
return outputDataset;
|
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 )
|
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 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 );
|
GDALRasterIO( sourceBand, GF_Read, xOffset, yOffset, nCols, nRows, rasterBuffer, nCols, nRows, GDT_Float32, 0, 0 );
|
||||||
return;
|
return;
|
||||||
@ -219,10 +217,10 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
|
|||||||
QgsRectangle intersection = targetRect.intersect( &sourceRect );
|
QgsRectangle intersection = targetRect.intersect( &sourceRect );
|
||||||
|
|
||||||
//no intersection, fill all the pixels with nodata values
|
//no intersection, fill all the pixels with nodata values
|
||||||
if( intersection.isEmpty() )
|
if ( intersection.isEmpty() )
|
||||||
{
|
{
|
||||||
int nPixels = nCols * nRows;
|
int nPixels = nCols * nRows;
|
||||||
for( int i = 0; i < nPixels; ++i )
|
for ( int i = 0; i < nPixels; ++i )
|
||||||
{
|
{
|
||||||
rasterBuffer[i] = nodataValue;
|
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
|
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
|
int sourceIndexX, sourceIndexY; //current raster index in source pixels
|
||||||
double sx, sy;
|
double sx, sy;
|
||||||
for( int i = 0; i < nRows; ++i )
|
for ( int i = 0; i < nRows; ++i )
|
||||||
{
|
{
|
||||||
targetPixelX = targetPixelXMin;
|
targetPixelX = targetPixelXMin;
|
||||||
for( int j = 0; j < nCols; ++j )
|
for ( int j = 0; j < nCols; ++j )
|
||||||
{
|
{
|
||||||
sx = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
|
sx = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
|
||||||
sourceIndexX = sx > 0 ? sx : floor( sx );
|
sourceIndexX = sx > 0 ? sx : floor( sx );
|
||||||
sy = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
|
sy = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
|
||||||
sourceIndexY = sy > 0 ? sy : floor( sy );
|
sourceIndexY = sy > 0 ? sy : floor( sy );
|
||||||
if( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
|
if ( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
|
||||||
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
|
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
|
||||||
{
|
{
|
||||||
rasterBuffer[j + i*nRows] = sourceRaster[ sourceIndexX + nSourcePixelsX * sourceIndexY ];
|
rasterBuffer[j + i*nRows] = sourceRaster[ sourceIndexX + nSourcePixelsX * sourceIndexY ];
|
||||||
}
|
}
|
||||||
@ -276,7 +274,7 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//If dataset transform is the same as the requested transform, do a normal GDAL raster io
|
//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 );
|
GDALRasterIO( sourceBand, GF_Read, xOffset, yOffset, nCols, nRows, rasterBuffer, nCols, nRows, GDT_Float32, 0, 0 );
|
||||||
return;
|
return;
|
||||||
@ -294,10 +292,10 @@ void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffse
|
|||||||
QgsRectangle intersection = targetRect.intersect( &sourceRect );
|
QgsRectangle intersection = targetRect.intersect( &sourceRect );
|
||||||
|
|
||||||
//no intersection, fill all the pixels with nodata values
|
//no intersection, fill all the pixels with nodata values
|
||||||
if( intersection.isEmpty() )
|
if ( intersection.isEmpty() )
|
||||||
{
|
{
|
||||||
int nPixels = nCols * nRows;
|
int nPixels = nCols * nRows;
|
||||||
for( int i = 0; i < nPixels; ++i )
|
for ( int i = 0; i < nPixels; ++i )
|
||||||
{
|
{
|
||||||
rasterBuffer[i] = 0;
|
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 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
|
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
|
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;
|
targetPixelX = targetPixelXMin;
|
||||||
for( int j = 0; j < nCols; ++j )
|
for ( int j = 0; j < nCols; ++j )
|
||||||
{
|
{
|
||||||
sourceIndexX = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
|
sourceIndexX = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
|
||||||
sourceIndexY = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
|
sourceIndexY = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
|
||||||
if( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
|
if ( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
|
||||||
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
|
&& sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
|
||||||
{
|
{
|
||||||
rasterBuffer[j + i*nCols] = sourceRaster[ sourceIndexX + nSourcePixelsX * sourceIndexY ];
|
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
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ QgsRasterMatrix::~QgsRasterMatrix()
|
|||||||
delete[] mData;
|
delete[] mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRasterMatrix& QgsRasterMatrix::operator=( const QgsRasterMatrix& m )
|
QgsRasterMatrix& QgsRasterMatrix::operator=( const QgsRasterMatrix & m )
|
||||||
{
|
{
|
||||||
delete[] mData;
|
delete[] mData;
|
||||||
mColumns = m.nColumns();
|
mColumns = m.nColumns();
|
||||||
@ -95,16 +95,16 @@ bool QgsRasterMatrix::power( const QgsRasterMatrix& other )
|
|||||||
|
|
||||||
bool QgsRasterMatrix::squareRoot()
|
bool QgsRasterMatrix::squareRoot()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
double value = mData[i];
|
double value = mData[i];
|
||||||
if( value >= 0 )
|
if ( value >= 0 )
|
||||||
{
|
{
|
||||||
mData[i] = sqrt( value );
|
mData[i] = sqrt( value );
|
||||||
}
|
}
|
||||||
@ -118,13 +118,13 @@ bool QgsRasterMatrix::squareRoot()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::sinus()
|
bool QgsRasterMatrix::sinus()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = sin( mData[i] );
|
mData[i] = sin( mData[i] );
|
||||||
}
|
}
|
||||||
@ -133,13 +133,13 @@ bool QgsRasterMatrix::sinus()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::asinus()
|
bool QgsRasterMatrix::asinus()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = asin( mData[i] );
|
mData[i] = asin( mData[i] );
|
||||||
}
|
}
|
||||||
@ -148,13 +148,13 @@ bool QgsRasterMatrix::asinus()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::cosinus()
|
bool QgsRasterMatrix::cosinus()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = cos( mData[i] );
|
mData[i] = cos( mData[i] );
|
||||||
}
|
}
|
||||||
@ -163,13 +163,13 @@ bool QgsRasterMatrix::cosinus()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::acosinus()
|
bool QgsRasterMatrix::acosinus()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = acos( mData[i] );
|
mData[i] = acos( mData[i] );
|
||||||
}
|
}
|
||||||
@ -178,13 +178,13 @@ bool QgsRasterMatrix::acosinus()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::tangens()
|
bool QgsRasterMatrix::tangens()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = tan( mData[i] );
|
mData[i] = tan( mData[i] );
|
||||||
}
|
}
|
||||||
@ -193,13 +193,13 @@ bool QgsRasterMatrix::tangens()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::atangens()
|
bool QgsRasterMatrix::atangens()
|
||||||
{
|
{
|
||||||
if( !mData )
|
if ( !mData )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = atan( mData[i] );
|
mData[i] = atan( mData[i] );
|
||||||
}
|
}
|
||||||
@ -208,9 +208,9 @@ bool QgsRasterMatrix::atangens()
|
|||||||
|
|
||||||
bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMatrix& other )
|
bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMatrix& other )
|
||||||
{
|
{
|
||||||
if( isNumber() && other.isNumber() )
|
if ( isNumber() && other.isNumber() )
|
||||||
{
|
{
|
||||||
switch( op )
|
switch ( op )
|
||||||
{
|
{
|
||||||
case opPLUS:
|
case opPLUS:
|
||||||
mData[0] = number() + other.number();
|
mData[0] = number() + other.number();
|
||||||
@ -222,7 +222,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
mData[0] = number() * other.number();
|
mData[0] = number() * other.number();
|
||||||
break;
|
break;
|
||||||
case opDIV:
|
case opDIV:
|
||||||
if( other.number() == 0 )
|
if ( other.number() == 0 )
|
||||||
{
|
{
|
||||||
mData[0] = -10000;
|
mData[0] = -10000;
|
||||||
}
|
}
|
||||||
@ -232,47 +232,47 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opPOW:
|
case opPOW:
|
||||||
if( !testPowerValidity( mData[0], other.number() ) )
|
if ( !testPowerValidity( mData[0], ( float ) other.number() ) )
|
||||||
{
|
{
|
||||||
mData[0] = -10000;
|
mData[0] = -10000;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mData[0] = pow( mData[0], other.number() );
|
mData[0] = pow( mData[0], ( float ) other.number() );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//two matrices
|
//two matrices
|
||||||
if( !isNumber() && !other.isNumber() )
|
if ( !isNumber() && !other.isNumber() )
|
||||||
{
|
{
|
||||||
float* matrix = other.mData;
|
float* matrix = other.mData;
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
switch( op )
|
switch ( op )
|
||||||
{
|
{
|
||||||
case opPLUS:
|
case opPLUS:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] + matrix[i];
|
mData[i] = mData[i] + matrix[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opMINUS:
|
case opMINUS:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] - matrix[i];
|
mData[i] = mData[i] - matrix[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opMUL:
|
case opMUL:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] * matrix[i];
|
mData[i] = mData[i] * matrix[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opDIV:
|
case opDIV:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
if( matrix[i] == 0 )
|
if ( matrix[i] == 0 )
|
||||||
{
|
{
|
||||||
mData[i] = -10000;
|
mData[i] = -10000;
|
||||||
}
|
}
|
||||||
@ -283,9 +283,9 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opPOW:
|
case opPOW:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
if( !testPowerValidity( mData[i], matrix[i] ) )
|
if ( !testPowerValidity( mData[i], matrix[i] ) )
|
||||||
{
|
{
|
||||||
mData[i] = -10000;
|
mData[i] = -10000;
|
||||||
}
|
}
|
||||||
@ -299,7 +299,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double value = 0;
|
double value = 0;
|
||||||
if( isNumber() )
|
if ( isNumber() )
|
||||||
{
|
{
|
||||||
float* matrix = other.mData;
|
float* matrix = other.mData;
|
||||||
int nEntries = other.nColumns() * other.nRows();
|
int nEntries = other.nColumns() * other.nRows();
|
||||||
@ -307,30 +307,30 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
delete[] mData;
|
delete[] mData;
|
||||||
mData = new float[nEntries]; mColumns = other.nColumns(); mRows = other.nRows();
|
mData = new float[nEntries]; mColumns = other.nColumns(); mRows = other.nRows();
|
||||||
|
|
||||||
switch( op )
|
switch ( op )
|
||||||
{
|
{
|
||||||
case opPLUS:
|
case opPLUS:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = value + matrix[i];
|
mData[i] = value + matrix[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opMINUS:
|
case opMINUS:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = value - matrix[i];
|
mData[i] = value - matrix[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opMUL:
|
case opMUL:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = value * matrix[i];
|
mData[i] = value * matrix[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opDIV:
|
case opDIV:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
if( matrix[i] == 0 )
|
if ( matrix[i] == 0 )
|
||||||
{
|
{
|
||||||
mData[i] = -10000;
|
mData[i] = -10000;
|
||||||
}
|
}
|
||||||
@ -341,15 +341,15 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opPOW:
|
case opPOW:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
if( !testPowerValidity( value, matrix[i] ) )
|
if ( !testPowerValidity( value, matrix[i] ) )
|
||||||
{
|
{
|
||||||
mData[i] = -10000;
|
mData[i] = -10000;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mData[i] = pow( value, matrix[i] );
|
mData[i] = pow(( float ) value, matrix[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -359,52 +359,52 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
{
|
{
|
||||||
value = other.number();
|
value = other.number();
|
||||||
int nEntries = mColumns * mRows;
|
int nEntries = mColumns * mRows;
|
||||||
switch( op )
|
switch ( op )
|
||||||
{
|
{
|
||||||
case opPLUS:
|
case opPLUS:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] + value;
|
mData[i] = mData[i] + value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opMINUS:
|
case opMINUS:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] - value;
|
mData[i] = mData[i] - value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opMUL:
|
case opMUL:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] * value;
|
mData[i] = mData[i] * value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opDIV:
|
case opDIV:
|
||||||
if( value == 0 )
|
if ( value == 0 )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = -10000;
|
mData[i] = -10000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
mData[i] = mData[i] / value;
|
mData[i] = mData[i] / value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case opPOW:
|
case opPOW:
|
||||||
for( int i = 0; i < nEntries; ++i )
|
for ( int i = 0; i < nEntries; ++i )
|
||||||
{
|
{
|
||||||
if( !testPowerValidity( mData[i], value ) )
|
if ( !testPowerValidity( mData[i], value ) )
|
||||||
{
|
{
|
||||||
mData[i] = -10000;
|
mData[i] = -10000;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mData[i] = pow( mData[i], value );
|
mData[i] = pow( mData[i], ( float ) value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -415,7 +415,7 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa
|
|||||||
|
|
||||||
bool QgsRasterMatrix::testPowerValidity( double base, double power )
|
bool QgsRasterMatrix::testPowerValidity( double base, double power )
|
||||||
{
|
{
|
||||||
if(( base == 0 && power < 0 ) || ( power < 0 && ( power - floor( power ) ) > 0 ) )
|
if (( base == 0 && power < 0 ) || ( power < 0 && ( power - floor( power ) ) > 0 ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
extern QgsRasterCalcNode* parseRasterCalcString( const QString& str, QString& parserErrorMsg );
|
|
||||||
|
|
||||||
QgsRasterCalcDialog::QgsRasterCalcDialog( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
|
QgsRasterCalcDialog::QgsRasterCalcDialog( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
@ -50,21 +48,21 @@ QString QgsRasterCalcDialog::outputFile() const
|
|||||||
QString outputFileName = mOutputLayerLineEdit->text();
|
QString outputFileName = mOutputLayerLineEdit->text();
|
||||||
QFileInfo fileInfo( outputFileName );
|
QFileInfo fileInfo( outputFileName );
|
||||||
QString suffix = fileInfo.suffix();
|
QString suffix = fileInfo.suffix();
|
||||||
if( !suffix.isEmpty() )
|
if ( !suffix.isEmpty() )
|
||||||
{
|
{
|
||||||
return outputFileName;
|
return outputFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the file format extension if the user did not specify it
|
//add the file format extension if the user did not specify it
|
||||||
int index = mOutputFormatComboBox->currentIndex();
|
int index = mOutputFormatComboBox->currentIndex();
|
||||||
if( index == -1 )
|
if ( index == -1 )
|
||||||
{
|
{
|
||||||
return outputFileName;
|
return outputFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString driverShortName = mOutputFormatComboBox->itemData( index ).toString();
|
QString driverShortName = mOutputFormatComboBox->itemData( index ).toString();
|
||||||
QMap<QString, QString>::const_iterator it = mDriverExtensionMap.find( driverShortName );
|
QMap<QString, QString>::const_iterator it = mDriverExtensionMap.find( driverShortName );
|
||||||
if( it == mDriverExtensionMap.constEnd() )
|
if ( it == mDriverExtensionMap.constEnd() )
|
||||||
{
|
{
|
||||||
return outputFileName;
|
return outputFileName;
|
||||||
}
|
}
|
||||||
@ -75,7 +73,7 @@ QString QgsRasterCalcDialog::outputFile() const
|
|||||||
QString QgsRasterCalcDialog::outputFormat() const
|
QString QgsRasterCalcDialog::outputFormat() const
|
||||||
{
|
{
|
||||||
int index = mOutputFormatComboBox->currentIndex();
|
int index = mOutputFormatComboBox->currentIndex();
|
||||||
if( index == -1 )
|
if ( index == -1 )
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -93,9 +91,9 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalcDialog::rasterEntries() const
|
|||||||
QString expressionString = mExpressionTextEdit->toPlainText();
|
QString expressionString = mExpressionTextEdit->toPlainText();
|
||||||
|
|
||||||
QList<QgsRasterCalculatorEntry>::const_iterator bandIt = mAvailableRasterBands.constBegin();
|
QList<QgsRasterCalculatorEntry>::const_iterator bandIt = mAvailableRasterBands.constBegin();
|
||||||
for( ; bandIt != mAvailableRasterBands.constEnd(); ++bandIt )
|
for ( ; bandIt != mAvailableRasterBands.constEnd(); ++bandIt )
|
||||||
{
|
{
|
||||||
if( expressionString.contains( bandIt->ref ) )
|
if ( expressionString.contains( bandIt->ref ) )
|
||||||
{
|
{
|
||||||
entries.push_back( *bandIt );
|
entries.push_back( *bandIt );
|
||||||
}
|
}
|
||||||
@ -110,12 +108,12 @@ void QgsRasterCalcDialog::insertAvailableRasterBands()
|
|||||||
QMap<QString, QgsMapLayer*>::const_iterator layerIt = layers.constBegin();
|
QMap<QString, QgsMapLayer*>::const_iterator layerIt = layers.constBegin();
|
||||||
|
|
||||||
bool firstLayer = true;
|
bool firstLayer = true;
|
||||||
for( ; layerIt != layers.constEnd(); ++layerIt )
|
for ( ; layerIt != layers.constEnd(); ++layerIt )
|
||||||
{
|
{
|
||||||
QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>( layerIt.value() );
|
QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>( layerIt.value() );
|
||||||
if( rlayer && !rlayer->usesProvider() )
|
if ( rlayer && !rlayer->usesProvider() )
|
||||||
{
|
{
|
||||||
if( firstLayer ) //set bounding box / resolution of output to the values of the first possible input layer
|
if ( firstLayer ) //set bounding box / resolution of output to the values of the first possible input layer
|
||||||
{
|
{
|
||||||
mNColumnsSpinBox->setValue( rlayer->width() );
|
mNColumnsSpinBox->setValue( rlayer->width() );
|
||||||
mNRowsSpinBox->setValue( rlayer->height() );
|
mNRowsSpinBox->setValue( rlayer->height() );
|
||||||
@ -127,7 +125,7 @@ void QgsRasterCalcDialog::insertAvailableRasterBands()
|
|||||||
firstLayer = false;
|
firstLayer = false;
|
||||||
}
|
}
|
||||||
//get number of bands
|
//get number of bands
|
||||||
for( int i = 0; i < rlayer->bandCount(); ++i )
|
for ( unsigned int i = 0; i < rlayer->bandCount(); ++i )
|
||||||
{
|
{
|
||||||
QgsRasterCalculatorEntry entry;
|
QgsRasterCalculatorEntry entry;
|
||||||
entry.raster = rlayer;
|
entry.raster = rlayer;
|
||||||
@ -145,30 +143,30 @@ void QgsRasterCalcDialog::insertAvailableOutputFormats()
|
|||||||
GDALAllRegister();
|
GDALAllRegister();
|
||||||
|
|
||||||
int nDrivers = GDALGetDriverCount();
|
int nDrivers = GDALGetDriverCount();
|
||||||
for( int i = 0; i < nDrivers; ++i )
|
for ( int i = 0; i < nDrivers; ++i )
|
||||||
{
|
{
|
||||||
GDALDriverH driver = GDALGetDriver( i );
|
GDALDriverH driver = GDALGetDriver( i );
|
||||||
if( driver != NULL )
|
if ( driver != NULL )
|
||||||
{
|
{
|
||||||
char** driverMetadata = GDALGetMetadata( driver, NULL );
|
char** driverMetadata = GDALGetMetadata( driver, NULL );
|
||||||
if( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
|
if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
|
||||||
{
|
{
|
||||||
mOutputFormatComboBox->addItem( GDALGetDriverLongName( driver ), QVariant( GDALGetDriverShortName( driver ) ) );
|
mOutputFormatComboBox->addItem( GDALGetDriverLongName( driver ), QVariant( GDALGetDriverShortName( driver ) ) );
|
||||||
|
|
||||||
//store the driver shortnames and the corresponding extensions
|
//store the driver shortnames and the corresponding extensions
|
||||||
//(just in case the user does not give an extension for the output file name)
|
//(just in case the user does not give an extension for the output file name)
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while(( driverMetadata ) && driverMetadata[index] != 0 )
|
while (( driverMetadata ) && driverMetadata[index] != 0 )
|
||||||
{
|
{
|
||||||
QStringList metadataTokens = QString( driverMetadata[index] ).split( "=", QString::SkipEmptyParts );
|
QStringList metadataTokens = QString( driverMetadata[index] ).split( "=", QString::SkipEmptyParts );
|
||||||
if( metadataTokens.size() < 1 )
|
if ( metadataTokens.size() < 1 )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( metadataTokens[0] == "DMD_EXTENSION" )
|
if ( metadataTokens[0] == "DMD_EXTENSION" )
|
||||||
{
|
{
|
||||||
if( metadataTokens.size() < 2 )
|
if ( metadataTokens.size() < 2 )
|
||||||
{
|
{
|
||||||
++index;
|
++index;
|
||||||
continue;
|
continue;
|
||||||
@ -186,7 +184,7 @@ void QgsRasterCalcDialog::insertAvailableOutputFormats()
|
|||||||
QSettings s;
|
QSettings s;
|
||||||
QString lastUsedDriver = s.value( "/RasterCalculator/lastOutputFormat", "GeoTIFF" ).toString();
|
QString lastUsedDriver = s.value( "/RasterCalculator/lastOutputFormat", "GeoTIFF" ).toString();
|
||||||
int lastDriverIndex = mOutputFormatComboBox->findText( lastUsedDriver );
|
int lastDriverIndex = mOutputFormatComboBox->findText( lastUsedDriver );
|
||||||
if( lastDriverIndex != -1 )
|
if ( lastDriverIndex != -1 )
|
||||||
{
|
{
|
||||||
mOutputFormatComboBox->setCurrentIndex( lastDriverIndex );
|
mOutputFormatComboBox->setCurrentIndex( lastDriverIndex );
|
||||||
}
|
}
|
||||||
@ -219,7 +217,7 @@ void QgsRasterCalcDialog::on_mButtonBox_accepted()
|
|||||||
void QgsRasterCalcDialog::on_mOutputLayerPushButton_clicked()
|
void QgsRasterCalcDialog::on_mOutputLayerPushButton_clicked()
|
||||||
{
|
{
|
||||||
QString saveFileName = QFileDialog::getSaveFileName( 0, tr( "Enter result file" ) );
|
QString saveFileName = QFileDialog::getSaveFileName( 0, tr( "Enter result file" ) );
|
||||||
if( !saveFileName.isNull() )
|
if ( !saveFileName.isNull() )
|
||||||
{
|
{
|
||||||
mOutputLayerLineEdit->setText( saveFileName );
|
mOutputLayerLineEdit->setText( saveFileName );
|
||||||
}
|
}
|
||||||
@ -228,19 +226,19 @@ void QgsRasterCalcDialog::on_mOutputLayerPushButton_clicked()
|
|||||||
void QgsRasterCalcDialog::on_mCurrentLayerExtentButton_clicked()
|
void QgsRasterCalcDialog::on_mCurrentLayerExtentButton_clicked()
|
||||||
{
|
{
|
||||||
QListWidgetItem* currentLayerItem = mRasterBandsListWidget->currentItem();
|
QListWidgetItem* currentLayerItem = mRasterBandsListWidget->currentItem();
|
||||||
if( currentLayerItem )
|
if ( currentLayerItem )
|
||||||
{
|
{
|
||||||
QgsRasterLayer* rlayer = 0;
|
QgsRasterLayer* rlayer = 0;
|
||||||
QList<QgsRasterCalculatorEntry>::const_iterator rasterIt = mAvailableRasterBands.constBegin();
|
QList<QgsRasterCalculatorEntry>::const_iterator rasterIt = mAvailableRasterBands.constBegin();
|
||||||
for( ; rasterIt != mAvailableRasterBands.constEnd(); ++rasterIt )
|
for ( ; rasterIt != mAvailableRasterBands.constEnd(); ++rasterIt )
|
||||||
{
|
{
|
||||||
if( rasterIt->ref == currentLayerItem->text() )
|
if ( rasterIt->ref == currentLayerItem->text() )
|
||||||
{
|
{
|
||||||
rlayer = rasterIt->raster;
|
rlayer = rasterIt->raster;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !rlayer )
|
if ( !rlayer )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -257,10 +255,10 @@ void QgsRasterCalcDialog::on_mCurrentLayerExtentButton_clicked()
|
|||||||
|
|
||||||
void QgsRasterCalcDialog::on_mExpressionTextEdit_textChanged()
|
void QgsRasterCalcDialog::on_mExpressionTextEdit_textChanged()
|
||||||
{
|
{
|
||||||
if( expressionValid() )
|
if ( expressionValid() )
|
||||||
{
|
{
|
||||||
mExpressionValidLabel->setText( tr( "Expression valid" ) );
|
mExpressionValidLabel->setText( tr( "Expression valid" ) );
|
||||||
if( filePathValid() )
|
if ( filePathValid() )
|
||||||
{
|
{
|
||||||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
||||||
return;
|
return;
|
||||||
@ -280,7 +278,7 @@ void QgsRasterCalcDialog::on_mOutputLayerLineEdit_textChanged( const QString& te
|
|||||||
|
|
||||||
void QgsRasterCalcDialog::setAcceptButtonState()
|
void QgsRasterCalcDialog::setAcceptButtonState()
|
||||||
{
|
{
|
||||||
if( expressionValid() && filePathValid() )
|
if ( expressionValid() && filePathValid() )
|
||||||
{
|
{
|
||||||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
||||||
}
|
}
|
||||||
@ -293,8 +291,8 @@ void QgsRasterCalcDialog::setAcceptButtonState()
|
|||||||
bool QgsRasterCalcDialog::expressionValid() const
|
bool QgsRasterCalcDialog::expressionValid() const
|
||||||
{
|
{
|
||||||
QString errorString;
|
QString errorString;
|
||||||
QgsRasterCalcNode* testNode = parseRasterCalcString( mExpressionTextEdit->toPlainText(), errorString );
|
QgsRasterCalcNode* testNode = QgsRasterCalcNode::parseRasterCalcString( mExpressionTextEdit->toPlainText(), errorString );
|
||||||
if( testNode )
|
if ( testNode )
|
||||||
{
|
{
|
||||||
delete testNode;
|
delete testNode;
|
||||||
return true;
|
return true;
|
||||||
@ -305,7 +303,7 @@ bool QgsRasterCalcDialog::expressionValid() const
|
|||||||
bool QgsRasterCalcDialog::filePathValid() const
|
bool QgsRasterCalcDialog::filePathValid() const
|
||||||
{
|
{
|
||||||
QString outputPath = QFileInfo( mOutputLayerLineEdit->text() ).absolutePath();
|
QString outputPath = QFileInfo( mOutputLayerLineEdit->text() ).absolutePath();
|
||||||
if( QFileInfo( outputPath ).isWritable() )
|
if ( QFileInfo( outputPath ).isWritable() )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user