mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Merge branch 'master' of github.com:qgis/Quantum-GIS
This commit is contained in:
commit
8074edc334
@ -63,10 +63,15 @@
|
||||
%Include qgsproviderregistry.sip
|
||||
%Include qgsrasterbandstats.sip
|
||||
%Include qgsrasterdataprovider.sip
|
||||
%Include qgsrasterchecker.sip
|
||||
%Include qgsrasterfilewriter.sip
|
||||
%Include qgsrasterinterface.sip
|
||||
%Include qgsrasterlayer.sip
|
||||
%Include qgsrasterpipe.sip
|
||||
%Include qgsrasterpyramid.sip
|
||||
%Include qgsrasterprojector.sip
|
||||
%Include qgsrasterrenderer.sip
|
||||
%Include qgsrasterresamplefilter.sip
|
||||
%Include qgsrasterresampler.sip
|
||||
%Include qgsrastershader.sip
|
||||
%Include qgsrastershaderfunction.sip
|
||||
|
20
python/core/qgsrasterchecker.sip
Normal file
20
python/core/qgsrasterchecker.sip
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
/** Raster checker for tests in python */
|
||||
|
||||
class QgsRasterChecker
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsrasterchecker.h>
|
||||
%End
|
||||
public:
|
||||
|
||||
QgsRasterChecker();
|
||||
|
||||
~QgsRasterChecker();
|
||||
|
||||
QString report();
|
||||
|
||||
bool runTest( QString theVerifiedKey, QString theVerifiedUri,
|
||||
QString theExpectedKey, QString theExpectedUri );
|
||||
};
|
||||
|
@ -18,11 +18,63 @@ class QgsRasterDataProvider : QgsDataProvider
|
||||
//! If you add to this, please also add to capabilitiesString()
|
||||
enum Capability
|
||||
{
|
||||
NoCapabilities = 0,
|
||||
Identify = 1
|
||||
// Capability2 = 1 << 1, etc
|
||||
NoCapabilities,
|
||||
Identify,
|
||||
ExactMinimumMaximum,
|
||||
ExactResolution,
|
||||
EstimatedMinimumMaximum,
|
||||
BuildPyramids,
|
||||
Histogram,
|
||||
Size,
|
||||
Create,
|
||||
Remove
|
||||
};
|
||||
|
||||
// This is modified copy of GDALColorInterp
|
||||
enum ColorInterpretation
|
||||
{
|
||||
UndefinedColorInterpretation = 0,
|
||||
/*! Greyscale */ GrayIndex = 1,
|
||||
/*! Paletted (see associated color table) */ PaletteIndex = 2, // indexed color table
|
||||
/*! Red band of RGBA image */ RedBand = 3,
|
||||
/*! Green band of RGBA image */ GreenBand = 4,
|
||||
/*! Blue band of RGBA image */ BlueBand = 5,
|
||||
/*! Alpha (0=transparent, 255=opaque) */ AlphaBand = 6,
|
||||
/*! Hue band of HLS image */ HueBand = 7,
|
||||
/*! Saturation band of HLS image */ SaturationBand = 8,
|
||||
/*! Lightness band of HLS image */ LightnessBand = 9,
|
||||
/*! Cyan band of CMYK image */ CyanBand = 10,
|
||||
/*! Magenta band of CMYK image */ MagentaBand = 11,
|
||||
/*! Yellow band of CMYK image */ YellowBand = 12,
|
||||
/*! Black band of CMLY image */ BlackBand = 13,
|
||||
/*! Y Luminance */ YCbCr_YBand = 14,
|
||||
/*! Cb Chroma */ YCbCr_CbBand = 15,
|
||||
/*! Cr Chroma */ YCbCr_CrBand = 16,
|
||||
/*! Continuous palette, QGIS addition, GRASS */ ContinuousPalette = 17,
|
||||
/*! Max current value */ ColorInterpretationMax = 17
|
||||
};
|
||||
|
||||
// Progress types
|
||||
enum RasterProgressType
|
||||
{
|
||||
ProgressHistogram = 0,
|
||||
ProgressPyramids = 1,
|
||||
ProgressStatistics = 2
|
||||
};
|
||||
|
||||
enum RasterBuildPyramids
|
||||
{
|
||||
PyramidsFlagNo = 0,
|
||||
PyramidsFlagYes = 1,
|
||||
CopyExisting = 2
|
||||
};
|
||||
|
||||
enum RasterPyramidsFormat
|
||||
{
|
||||
PyramidsGTiff = 0,
|
||||
PyramidsInternal = 1,
|
||||
PyramidsErdas = 2
|
||||
};
|
||||
|
||||
QgsRasterDataProvider();
|
||||
|
||||
@ -179,6 +231,14 @@ class QgsRasterDataProvider : QgsDataProvider
|
||||
@note: this method was added in version 1.2*/
|
||||
void setDpi( int dpi );
|
||||
|
||||
/** Get block size */
|
||||
int xBlockSize() const;
|
||||
int yBlockSize() const;
|
||||
|
||||
/** Get raster size */
|
||||
int xSize() const;
|
||||
int ySize() const;
|
||||
|
||||
/** read block of data using give extent and size */
|
||||
/*virtual void readBlock( int bandNo,
|
||||
QgsRectangle const & viewExtent,
|
||||
|
56
python/core/qgsrasterfilewriter.sip
Normal file
56
python/core/qgsrasterfilewriter.sip
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
/** Raster file writer */
|
||||
|
||||
class QgsRasterFileWriter
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsrasterfilewriter.h>
|
||||
#include <qgsrasterdataprovider.h>
|
||||
%End
|
||||
public:
|
||||
enum WriterError
|
||||
{
|
||||
NoError = 0,
|
||||
SourceProviderError = 1,
|
||||
DestProviderError = 2,
|
||||
CreateDatasourceError = 3,
|
||||
WriteError = 4,
|
||||
NoDataConflict = 5
|
||||
};
|
||||
|
||||
QgsRasterFileWriter( const QString& outputUrl );
|
||||
~QgsRasterFileWriter();
|
||||
WriterError writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, QgsRectangle outputExtent,
|
||||
const QgsCoordinateReferenceSystem& crs, QProgressDialog* p = 0 );
|
||||
|
||||
void setOutputFormat( const QString& format );
|
||||
QString outputFormat() const;
|
||||
|
||||
void setOutputProviderKey( const QString& key );
|
||||
QString outputProviderKey() const;
|
||||
|
||||
void setTiledMode( bool t );
|
||||
bool tiledMode() const;
|
||||
|
||||
void setMaxTileWidth( int w );
|
||||
int maxTileWidth() const;
|
||||
|
||||
QgsRasterDataProvider::RasterBuildPyramids buildPyramidsFlag() const;
|
||||
void setBuildPyramidsFlag( QgsRasterDataProvider::RasterBuildPyramids f );
|
||||
|
||||
QList< int > pyramidsList() const;
|
||||
void setPyramidsList( const QList< int > & list );
|
||||
|
||||
QString pyramidsResampling() const;
|
||||
void setPyramidsResampling( const QString & str );
|
||||
|
||||
QgsRasterDataProvider::RasterPyramidsFormat pyramidsFormat() const;
|
||||
void setPyramidsFormat( QgsRasterDataProvider::RasterPyramidsFormat f );
|
||||
|
||||
void setMaxTileHeight( int h );
|
||||
int maxTileHeight() const;
|
||||
|
||||
void setCreateOptions( const QStringList& list );
|
||||
QStringList createOptions() const;
|
||||
};
|
||||
|
51
python/core/qgsrasterpipe.sip
Normal file
51
python/core/qgsrasterpipe.sip
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
/** Raster pipe */
|
||||
|
||||
class QgsRasterPipe
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsrasterpipe.h>
|
||||
#include <qgsrasterresamplefilter.h>
|
||||
#include <qgsrasterprojector.h>
|
||||
%End
|
||||
public:
|
||||
enum Role
|
||||
{
|
||||
UnknownRole = 0,
|
||||
ProviderRole = 1,
|
||||
RendererRole = 2,
|
||||
ResamplerRole = 3,
|
||||
ProjectorRole = 4
|
||||
};
|
||||
|
||||
QgsRasterPipe();
|
||||
QgsRasterPipe( const QgsRasterPipe& thePipe );
|
||||
|
||||
~QgsRasterPipe();
|
||||
|
||||
bool insert( int idx, QgsRasterInterface* theInterface );
|
||||
|
||||
bool replace( int idx, QgsRasterInterface* theInterface );
|
||||
|
||||
bool set( QgsRasterInterface * theInterface );
|
||||
|
||||
bool remove( int idx );
|
||||
|
||||
bool remove( QgsRasterInterface * theInterface );
|
||||
|
||||
int size() const;
|
||||
QgsRasterInterface * at( int idx ) const;
|
||||
QgsRasterInterface * last() const;
|
||||
|
||||
bool setOn( int idx, bool on );
|
||||
|
||||
bool canSetOn( int idx, bool on );
|
||||
|
||||
QgsRasterDataProvider * provider() const;
|
||||
QgsRasterRenderer * renderer() const;
|
||||
QgsRasterResampleFilter * resampleFilter() const;
|
||||
QgsRasterProjector * projector() const;
|
||||
|
||||
void setStatsOn( bool on );
|
||||
};
|
||||
|
57
python/core/qgsrasterprojector.sip
Normal file
57
python/core/qgsrasterprojector.sip
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
/** Raster projector */
|
||||
|
||||
class QgsRasterProjector
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsrasterprojector.h>
|
||||
#include <qgscoordinatereferencesystem.h>
|
||||
%End
|
||||
public:
|
||||
QgsRasterProjector(
|
||||
QgsCoordinateReferenceSystem theSrcCRS,
|
||||
QgsCoordinateReferenceSystem theDestCRS,
|
||||
QgsRectangle theDestExtent,
|
||||
int theDestRows, int theDestCols,
|
||||
double theMaxSrcXRes, double theMaxSrcYRes,
|
||||
QgsRectangle theExtent
|
||||
);
|
||||
QgsRasterProjector(
|
||||
QgsCoordinateReferenceSystem theSrcCRS,
|
||||
QgsCoordinateReferenceSystem theDestCRS,
|
||||
double theMaxSrcXRes, double theMaxSrcYRes,
|
||||
QgsRectangle theExtent
|
||||
);
|
||||
QgsRasterProjector();
|
||||
|
||||
~QgsRasterProjector();
|
||||
|
||||
QgsRasterInterface * clone() const;
|
||||
|
||||
int bandCount() const;
|
||||
|
||||
QgsRasterInterface::DataType dataType( int bandNo ) const;
|
||||
|
||||
void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS );
|
||||
|
||||
QgsCoordinateReferenceSystem srcCrs() const;
|
||||
|
||||
QgsCoordinateReferenceSystem destCrs() const;
|
||||
|
||||
void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes );
|
||||
|
||||
QgsRectangle srcExtent();
|
||||
|
||||
int srcRows();
|
||||
int srcCols();
|
||||
void setSrcRows( int theRows );
|
||||
void setSrcCols( int theCols );
|
||||
|
||||
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
|
||||
|
||||
int dstRows() const;
|
||||
int dstCols() const;
|
||||
|
||||
void * readBlock( int bandNo, const QgsRectangle & extent, int width, int height );
|
||||
};
|
||||
|
@ -1,29 +1,37 @@
|
||||
|
||||
/** Raster resample filter */
|
||||
|
||||
class QgsRasterResampleFilter
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include "qgsrasterresamplefilter.h"
|
||||
#include <qgsrasterresamplefilter.h>
|
||||
%End
|
||||
QgsRasterResampleFilter();
|
||||
QgsRasterResampleFilter( const QgsRasterResampleFilter& thePipe );
|
||||
|
||||
public:
|
||||
QgsRasterResampleFilter( QgsRasterFace* input = 0 );
|
||||
~QgsRasterResampleFilter();
|
||||
|
||||
QgsRasterInterface * clone() const;
|
||||
|
||||
int bandCount() const;
|
||||
|
||||
QgsRasterInterface::DataType dataType( int bandNo ) const;
|
||||
|
||||
bool setInput( QgsRasterInterface* input );
|
||||
|
||||
void * readBlock( int bandNo, const QgsRectangle & extent, int width, int height );
|
||||
|
||||
/**Set resampler for zoomed in scales. Takes ownership of the object*/
|
||||
void setZoomedInResampler( QgsRasterResampler* r );
|
||||
const QgsRasterResampler* zoomedInResampler();
|
||||
const QgsRasterResampler* zoomedInResampler() const;
|
||||
|
||||
/**Set resampler for zoomed out scales. Takes ownership of the object*/
|
||||
void setZoomedOutResampler( QgsRasterResampler* r );
|
||||
const QgsRasterResampler* zoomedOutResampler() const;
|
||||
|
||||
void setMaxOversampling( double os );
|
||||
double maxOversampling() const;
|
||||
|
||||
virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const = 0;
|
||||
void writeXML( QDomDocument& doc, QDomElement& parentElem );
|
||||
|
||||
/**Sets base class members from xml. Usually called from create() methods of subclasses*/
|
||||
void readXML( const QDomElement& rendererElem );
|
||||
void readXML( const QDomElement& resamplefilterElem );
|
||||
};
|
||||
|
||||
|
@ -66,6 +66,32 @@ QgsRasterProjector::QgsRasterProjector()
|
||||
QgsDebugMsg( "Entered" );
|
||||
}
|
||||
|
||||
QgsRasterProjector::QgsRasterProjector( const QgsRasterProjector &projector )
|
||||
{
|
||||
mSrcCRS = projector.mSrcCRS;
|
||||
mDestCRS = projector.mDestCRS;
|
||||
mMaxSrcXRes = projector.mMaxSrcXRes;
|
||||
mMaxSrcYRes = projector.mMaxSrcYRes;
|
||||
mExtent = projector.mExtent;
|
||||
mCoordinateTransform.setSourceCrs( mSrcCRS );
|
||||
mCoordinateTransform.setDestCRS( mDestCRS );
|
||||
}
|
||||
|
||||
QgsRasterProjector & QgsRasterProjector::operator=( const QgsRasterProjector & projector )
|
||||
{
|
||||
if ( &projector != this )
|
||||
{
|
||||
mSrcCRS = projector.mSrcCRS;
|
||||
mDestCRS = projector.mDestCRS;
|
||||
mMaxSrcXRes = projector.mMaxSrcXRes;
|
||||
mMaxSrcYRes = projector.mMaxSrcYRes;
|
||||
mExtent = projector.mExtent;
|
||||
mCoordinateTransform.setSourceCrs( mSrcCRS );
|
||||
mCoordinateTransform.setDestCRS( mDestCRS );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
QgsRasterInterface * QgsRasterProjector::clone() const
|
||||
{
|
||||
QgsDebugMsg( "Entered" );
|
||||
@ -93,7 +119,7 @@ QgsRasterInterface::DataType QgsRasterProjector::dataType( int bandNo ) const
|
||||
return QgsRasterInterface::UnknownDataType;
|
||||
}
|
||||
|
||||
void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
|
||||
void QgsRasterProjector::setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS )
|
||||
{
|
||||
mSrcCRS = theSrcCRS;
|
||||
mDestCRS = theDestCRS;
|
||||
|
@ -57,10 +57,14 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
QgsRectangle theExtent
|
||||
);
|
||||
QgsRasterProjector();
|
||||
// * copy constructor to avoid synthesized which fails on copy of QgsCoordinateTransform (QObject child) in Python bindings
|
||||
QgsRasterProjector( const QgsRasterProjector &projector );
|
||||
|
||||
/** \brief The destructor */
|
||||
~QgsRasterProjector();
|
||||
|
||||
QgsRasterProjector & operator=( const QgsRasterProjector &projector );
|
||||
|
||||
QgsRasterInterface * clone() const;
|
||||
|
||||
int bandCount() const;
|
||||
@ -68,7 +72,7 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
QgsRasterInterface::DataType dataType( int bandNo ) const;
|
||||
|
||||
/** \brief set source and destination CRS */
|
||||
void setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS );
|
||||
void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS );
|
||||
|
||||
/** \brief Get source CRS */
|
||||
QgsCoordinateReferenceSystem srcCrs() const { return mSrcCRS; }
|
||||
@ -82,6 +86,25 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
|
||||
}
|
||||
|
||||
/** get source extent */
|
||||
QgsRectangle srcExtent() { return mSrcExtent; }
|
||||
|
||||
/** get/set source width/height */
|
||||
int srcRows() { return mSrcRows; }
|
||||
int srcCols() { return mSrcCols; }
|
||||
void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
|
||||
void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
|
||||
|
||||
/** \brief Get source row and column indexes for current source extent and resolution */
|
||||
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
|
||||
|
||||
int dstRows() const { return mDestRows; }
|
||||
int dstCols() const { return mDestCols; }
|
||||
|
||||
void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );
|
||||
|
||||
|
||||
private:
|
||||
/** \brief get destination point for _current_ destination position */
|
||||
void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );
|
||||
|
||||
@ -98,9 +121,6 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
/** \brief Get approximate source row and column indexes for current source extent and resolution */
|
||||
inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
|
||||
|
||||
/** \brief Get source row and column indexes for current source extent and resolution */
|
||||
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
|
||||
|
||||
/** \brief Calculate matrix */
|
||||
void calc();
|
||||
|
||||
@ -139,24 +159,9 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
/** Calc / switch helper */
|
||||
void nextHelper();
|
||||
|
||||
/** get source extent */
|
||||
QgsRectangle srcExtent() { return mSrcExtent; }
|
||||
|
||||
/** get/set source width/height */
|
||||
int srcRows() { return mSrcRows; }
|
||||
int srcCols() { return mSrcCols; }
|
||||
void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
|
||||
void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }
|
||||
|
||||
/** get mCPMatrix as string */
|
||||
QString cpToString();
|
||||
|
||||
int dstRows() const { return mDestRows; }
|
||||
int dstCols() const { return mDestCols; }
|
||||
|
||||
void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );
|
||||
|
||||
private:
|
||||
/** Source CRS */
|
||||
QgsCoordinateReferenceSystem mSrcCRS;
|
||||
|
||||
|
@ -35,8 +35,6 @@ class CORE_EXPORT QgsRasterChecker
|
||||
//! Destructor
|
||||
~QgsRasterChecker() {};
|
||||
|
||||
QString controlImagePath() const;
|
||||
|
||||
QString report() { return mReport; };
|
||||
/**
|
||||
* Test using renderer to generate the image to be compared.
|
||||
@ -45,7 +43,7 @@ class CORE_EXPORT QgsRasterChecker
|
||||
* @param theExpectedKey expected provider key
|
||||
* @param theExpectedUri URI of the expected (control) raster
|
||||
*/
|
||||
bool runTest( QString theVerifiedKey, QString theVerifiedUri,
|
||||
bool runTest( QString theVerifiedKey, QString theVerifiedUri,
|
||||
QString theExpectedKey, QString theExpectedUri );
|
||||
private:
|
||||
QString mReport;
|
||||
|
@ -195,34 +195,34 @@ bool QgsRasterPipe::set( QgsRasterInterface* theInterface )
|
||||
return insert( idx, theInterface ); // insert may still fail and return false
|
||||
}
|
||||
|
||||
QgsRasterInterface * QgsRasterPipe::iface( Role role ) const
|
||||
{
|
||||
QgsDebugMsg( QString( "role = %1" ).arg( role ) );
|
||||
if ( mRoleMap.contains( role ) )
|
||||
QgsRasterInterface * QgsRasterPipe::interface( Role role ) const
|
||||
{
|
||||
return mInterfaces.value( mRoleMap.value( role ) );
|
||||
QgsDebugMsg( QString( "role = %1" ).arg( role ) );
|
||||
if ( mRoleMap.contains( role ) )
|
||||
{
|
||||
return mInterfaces.value( mRoleMap.value( role ) );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QgsRasterDataProvider * QgsRasterPipe::provider() const
|
||||
{
|
||||
return dynamic_cast<QgsRasterDataProvider *>( iface( ProviderRole ) );
|
||||
return dynamic_cast<QgsRasterDataProvider *>( interface( ProviderRole ) );
|
||||
}
|
||||
|
||||
QgsRasterRenderer * QgsRasterPipe::renderer() const
|
||||
{
|
||||
return dynamic_cast<QgsRasterRenderer *>( iface( RendererRole ) );
|
||||
return dynamic_cast<QgsRasterRenderer *>( interface( RendererRole ) );
|
||||
}
|
||||
|
||||
QgsRasterResampleFilter * QgsRasterPipe::resampleFilter() const
|
||||
{
|
||||
return dynamic_cast<QgsRasterResampleFilter *>( iface( ResamplerRole ) );
|
||||
return dynamic_cast<QgsRasterResampleFilter *>( interface( ResamplerRole ) );
|
||||
}
|
||||
|
||||
QgsRasterProjector * QgsRasterPipe::projector() const
|
||||
{
|
||||
return dynamic_cast<QgsRasterProjector*>( iface( ProjectorRole ) );
|
||||
return dynamic_cast<QgsRasterProjector*>( interface( ProjectorRole ) );
|
||||
}
|
||||
|
||||
bool QgsRasterPipe::remove( int idx )
|
||||
|
@ -47,11 +47,7 @@ class CORE_EXPORT QgsRasterPipe
|
||||
QgsRasterPipe( );
|
||||
QgsRasterPipe( const QgsRasterPipe& thePipe );
|
||||
|
||||
virtual ~QgsRasterPipe();
|
||||
|
||||
/** \brief Try to connect interfaces in pipe and to the provider at beginning.
|
||||
Returns true if connected or false if connection failed */
|
||||
bool connect( QVector<QgsRasterInterface*> theInterfaces );
|
||||
~QgsRasterPipe();
|
||||
|
||||
/** Try to insert interface at specified index and connect
|
||||
* if connection would fail, the interface is not inserted and false is returned */
|
||||
@ -69,9 +65,6 @@ class CORE_EXPORT QgsRasterPipe
|
||||
*/
|
||||
bool set( QgsRasterInterface * theInterface );
|
||||
|
||||
/** Get known interface by role */
|
||||
QgsRasterInterface * iface( Role role ) const;
|
||||
|
||||
/** Remove and delete interface at given index if possible */
|
||||
bool remove( int idx );
|
||||
|
||||
@ -115,6 +108,13 @@ class CORE_EXPORT QgsRasterPipe
|
||||
|
||||
// Check if index is in bounds
|
||||
bool checkBounds( int idx ) const;
|
||||
|
||||
/** Get known interface by role */
|
||||
QgsRasterInterface * interface( Role role ) const;
|
||||
|
||||
/** \brief Try to connect interfaces in pipe and to the provider at beginning.
|
||||
Returns true if connected or false if connection failed */
|
||||
bool connect( QVector<QgsRasterInterface*> theInterfaces );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -47,8 +47,8 @@ class TestQgsRasterFileWriter: public QObject
|
||||
void writeTest();
|
||||
private:
|
||||
bool writeTest( QString rasterName );
|
||||
void log ( QString msg );
|
||||
void logError ( QString msg );
|
||||
void log( QString msg );
|
||||
void logError( QString msg );
|
||||
QString mTestDataDir;
|
||||
QString mReport;
|
||||
};
|
||||
@ -85,7 +85,7 @@ void TestQgsRasterFileWriter::cleanupTestCase()
|
||||
void TestQgsRasterFileWriter::writeTest()
|
||||
{
|
||||
QDir dir( mTestDataDir + "/raster" );
|
||||
|
||||
|
||||
QStringList filters;
|
||||
filters << "*.tif";
|
||||
QStringList rasterNames = dir.entryList( filters, QDir::Files );
|
||||
@ -108,7 +108,7 @@ bool TestQgsRasterFileWriter::writeTest( QString theRasterName )
|
||||
QFileInfo myRasterFileInfo( myFileName );
|
||||
|
||||
QgsRasterLayer * mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
|
||||
myRasterFileInfo.completeBaseName() );
|
||||
myRasterFileInfo.completeBaseName() );
|
||||
qDebug() << theRasterName << " metadata: " << mpRasterLayer->dataProvider()->metadata();
|
||||
|
||||
if ( !mpRasterLayer->isValid() ) return false;
|
||||
@ -122,7 +122,7 @@ bool TestQgsRasterFileWriter::writeTest( QString theRasterName )
|
||||
QString tmpName = tmpFile.fileName();
|
||||
tmpFile.close();
|
||||
// do not remove when class is destroyd so that we can read the file and see difference
|
||||
tmpFile.setAutoRemove ( false );
|
||||
tmpFile.setAutoRemove( false );
|
||||
qDebug() << "temporary output file: " << tmpName;
|
||||
mReport += "temporary output file: " + tmpName + "<br>";
|
||||
|
||||
@ -130,7 +130,7 @@ bool TestQgsRasterFileWriter::writeTest( QString theRasterName )
|
||||
QgsRasterPipe* pipe = new QgsRasterPipe();
|
||||
if ( !pipe->set( provider->clone() ) )
|
||||
{
|
||||
logError ( "Cannot set pipe provider" );
|
||||
logError( "Cannot set pipe provider" );
|
||||
return false;
|
||||
}
|
||||
qDebug() << "provider set";
|
||||
@ -145,7 +145,7 @@ bool TestQgsRasterFileWriter::writeTest( QString theRasterName )
|
||||
}
|
||||
qDebug() << "nuller set";
|
||||
|
||||
// Reprojection not really done
|
||||
// Reprojection not really done
|
||||
QgsRasterProjector *projector = new QgsRasterProjector;
|
||||
projector->setCRS( provider->crs(), provider->crs() );
|
||||
if ( !pipe->insert( 2, projector ) )
|
||||
@ -155,26 +155,26 @@ bool TestQgsRasterFileWriter::writeTest( QString theRasterName )
|
||||
}
|
||||
qDebug() << "projector set";
|
||||
|
||||
fileWriter.writeRaster( pipe, provider->xSize() + 1, provider->ySize(), provider->extent(), provider->crs() );
|
||||
fileWriter.writeRaster( pipe, provider->xSize(), provider->ySize(), provider->extent(), provider->crs() );
|
||||
|
||||
delete pipe;
|
||||
|
||||
QgsRasterChecker checker;
|
||||
bool ok = checker.runTest( "gdal", tmpName, "gdal", myRasterFileInfo.filePath() );
|
||||
bool ok = checker.runTest( "gdal", tmpName, "gdal", myRasterFileInfo.filePath() );
|
||||
mReport += checker.report();
|
||||
|
||||
// All OK, we can delete the file
|
||||
tmpFile.setAutoRemove ( ok );
|
||||
tmpFile.setAutoRemove( ok );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestQgsRasterFileWriter::log ( QString msg )
|
||||
void TestQgsRasterFileWriter::log( QString msg )
|
||||
{
|
||||
mReport += msg + "<br>";
|
||||
}
|
||||
|
||||
void TestQgsRasterFileWriter::logError ( QString msg )
|
||||
void TestQgsRasterFileWriter::logError( QString msg )
|
||||
{
|
||||
mReport += "Error:<font color='red'>" + msg + "</font><br>";
|
||||
qDebug() << msg;
|
||||
|
@ -4,6 +4,7 @@ ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
|
||||
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
|
||||
ADD_PYTHON_TEST(PyQgsGeometry test_qgsgeometry.py)
|
||||
ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
|
||||
ADD_PYTHON_TEST(PyQgsRasterFileWriter test_qgsrasterfilewriter.py)
|
||||
ADD_PYTHON_TEST(PyQgsMemoryProvider test_qgsmemoryprovider.py)
|
||||
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
|
||||
ADD_PYTHON_TEST(PyQgsCoordinateTransform test_qgscoordinatetransform.py)
|
||||
|
79
tests/src/python/test_qgsrasterfilewriter.py
Normal file
79
tests/src/python/test_qgsrasterfilewriter.py
Normal file
@ -0,0 +1,79 @@
|
||||
import os, glob
|
||||
import unittest
|
||||
|
||||
from qgis.core import QgsRasterLayer, QgsRasterChecker, QgsRasterPipe, QgsRasterFileWriter, QgsRasterProjector
|
||||
from PyQt4.QtCore import QFileInfo, QString, QStringList, QTemporaryFile, QDir
|
||||
|
||||
# Convenience instances in case you may need them
|
||||
# not used in this test
|
||||
from utilities import getQgisTestApp
|
||||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
||||
|
||||
class TestQgsRasterFileWriter(unittest.TestCase):
|
||||
def __init__(self,methodName):
|
||||
unittest.TestCase.__init__(self,methodName)
|
||||
self.testDataDir = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'testdata'))
|
||||
self.report = "<h1>Python Raster File Writer Tests</h1>\n"
|
||||
|
||||
def write(self, theRasterName):
|
||||
print theRasterName
|
||||
|
||||
path = "%s/%s" % ( self.testDataDir, theRasterName )
|
||||
#myFileInfo = QFileInfo( path )
|
||||
#myBaseName = myFileInfo.baseName()
|
||||
rasterLayer = QgsRasterLayer(path, "test")
|
||||
if not rasterLayer.isValid(): return False
|
||||
provider = rasterLayer.dataProvider()
|
||||
|
||||
tmpFile = QTemporaryFile()
|
||||
tmpFile.open() # fileName is no avialable until open
|
||||
tmpName = tmpFile.fileName()
|
||||
tmpFile.close();
|
||||
# do not remove when class is destroyd so that we can read the file and see difference
|
||||
tmpFile.setAutoRemove ( False )
|
||||
|
||||
fileWriter = QgsRasterFileWriter ( tmpName )
|
||||
pipe = QgsRasterPipe()
|
||||
if not pipe.set( provider.clone() ):
|
||||
print "Cannot set pipe provider"
|
||||
return False
|
||||
|
||||
#nuller = QgsRasterNuller()
|
||||
#nuller.setNoData( ... )
|
||||
#if not pipe.insert( 1, nuller ):
|
||||
# print "Cannot set pipe nuller"
|
||||
# return False
|
||||
|
||||
projector = QgsRasterProjector()
|
||||
projector.setCRS( provider.crs(), provider.crs() )
|
||||
if not pipe.insert( 2, projector.clone() ):
|
||||
print "Cannot set pipe projector"
|
||||
return False
|
||||
|
||||
fileWriter.writeRaster( pipe, provider.xSize(), provider.ySize(), provider.extent(), provider.crs() )
|
||||
|
||||
checker = QgsRasterChecker()
|
||||
ok = checker.runTest( "gdal", tmpName, "gdal", path );
|
||||
self.report += checker.report();
|
||||
|
||||
# All OK, we can delete the file
|
||||
tmpFile.setAutoRemove ( ok );
|
||||
|
||||
return ok
|
||||
|
||||
def testWrite(self):
|
||||
for name in glob.glob( "%s/raster/*.tif" % self.testDataDir ):
|
||||
baseName = os.path.basename ( name )
|
||||
allOk = True
|
||||
ok = self.write( "raster/%s" % baseName )
|
||||
if not ok: allOk = False
|
||||
|
||||
reportFilePath = "%s/qgistest.html" % QDir.tempPath()
|
||||
reportFile = open(reportFilePath,'a')
|
||||
reportFile.write( self.report )
|
||||
reportFile.close()
|
||||
|
||||
assert allOk, "Raster file writer test failed"
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user