Skip to content

Commit ea86b93

Browse files
committed
more raster Python bindings, raster write test in Python
1 parent e690048 commit ea86b93

15 files changed

+432
-66
lines changed

python/core/core.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@
6363
%Include qgsproviderregistry.sip
6464
%Include qgsrasterbandstats.sip
6565
%Include qgsrasterdataprovider.sip
66+
%Include qgsrasterchecker.sip
67+
%Include qgsrasterfilewriter.sip
6668
%Include qgsrasterinterface.sip
6769
%Include qgsrasterlayer.sip
70+
%Include qgsrasterpipe.sip
6871
%Include qgsrasterpyramid.sip
72+
%Include qgsrasterprojector.sip
6973
%Include qgsrasterrenderer.sip
74+
%Include qgsrasterresamplefilter.sip
7075
%Include qgsrasterresampler.sip
7176
%Include qgsrastershader.sip
7277
%Include qgsrastershaderfunction.sip

python/core/qgsrasterchecker.sip

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
/** Raster checker for tests in python */
3+
4+
class QgsRasterChecker
5+
{
6+
%TypeHeaderCode
7+
#include <qgsrasterchecker.h>
8+
%End
9+
public:
10+
11+
QgsRasterChecker();
12+
13+
~QgsRasterChecker();
14+
15+
QString report();
16+
17+
bool runTest( QString theVerifiedKey, QString theVerifiedUri,
18+
QString theExpectedKey, QString theExpectedUri );
19+
};
20+

python/core/qgsrasterdataprovider.sip

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,63 @@ class QgsRasterDataProvider : QgsDataProvider
1818
//! If you add to this, please also add to capabilitiesString()
1919
enum Capability
2020
{
21-
NoCapabilities = 0,
22-
Identify = 1
23-
// Capability2 = 1 << 1, etc
21+
NoCapabilities,
22+
Identify,
23+
ExactMinimumMaximum,
24+
ExactResolution,
25+
EstimatedMinimumMaximum,
26+
BuildPyramids,
27+
Histogram,
28+
Size,
29+
Create,
30+
Remove
2431
};
2532

33+
// This is modified copy of GDALColorInterp
34+
enum ColorInterpretation
35+
{
36+
UndefinedColorInterpretation = 0,
37+
/*! Greyscale */ GrayIndex = 1,
38+
/*! Paletted (see associated color table) */ PaletteIndex = 2, // indexed color table
39+
/*! Red band of RGBA image */ RedBand = 3,
40+
/*! Green band of RGBA image */ GreenBand = 4,
41+
/*! Blue band of RGBA image */ BlueBand = 5,
42+
/*! Alpha (0=transparent, 255=opaque) */ AlphaBand = 6,
43+
/*! Hue band of HLS image */ HueBand = 7,
44+
/*! Saturation band of HLS image */ SaturationBand = 8,
45+
/*! Lightness band of HLS image */ LightnessBand = 9,
46+
/*! Cyan band of CMYK image */ CyanBand = 10,
47+
/*! Magenta band of CMYK image */ MagentaBand = 11,
48+
/*! Yellow band of CMYK image */ YellowBand = 12,
49+
/*! Black band of CMLY image */ BlackBand = 13,
50+
/*! Y Luminance */ YCbCr_YBand = 14,
51+
/*! Cb Chroma */ YCbCr_CbBand = 15,
52+
/*! Cr Chroma */ YCbCr_CrBand = 16,
53+
/*! Continuous palette, QGIS addition, GRASS */ ContinuousPalette = 17,
54+
/*! Max current value */ ColorInterpretationMax = 17
55+
};
56+
57+
// Progress types
58+
enum RasterProgressType
59+
{
60+
ProgressHistogram = 0,
61+
ProgressPyramids = 1,
62+
ProgressStatistics = 2
63+
};
64+
65+
enum RasterBuildPyramids
66+
{
67+
PyramidsFlagNo = 0,
68+
PyramidsFlagYes = 1,
69+
CopyExisting = 2
70+
};
71+
72+
enum RasterPyramidsFormat
73+
{
74+
PyramidsGTiff = 0,
75+
PyramidsInternal = 1,
76+
PyramidsErdas = 2
77+
};
2678

2779
QgsRasterDataProvider();
2880

@@ -179,6 +231,14 @@ class QgsRasterDataProvider : QgsDataProvider
179231
@note: this method was added in version 1.2*/
180232
void setDpi( int dpi );
181233

234+
/** Get block size */
235+
int xBlockSize() const;
236+
int yBlockSize() const;
237+
238+
/** Get raster size */
239+
int xSize() const;
240+
int ySize() const;
241+
182242
/** read block of data using give extent and size */
183243
/*virtual void readBlock( int bandNo,
184244
QgsRectangle const & viewExtent,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
/** Raster file writer */
3+
4+
class QgsRasterFileWriter
5+
{
6+
%TypeHeaderCode
7+
#include <qgsrasterfilewriter.h>
8+
#include <qgsrasterdataprovider.h>
9+
%End
10+
public:
11+
enum WriterError
12+
{
13+
NoError = 0,
14+
SourceProviderError = 1,
15+
DestProviderError = 2,
16+
CreateDatasourceError = 3,
17+
WriteError = 4,
18+
NoDataConflict = 5
19+
};
20+
21+
QgsRasterFileWriter( const QString& outputUrl );
22+
~QgsRasterFileWriter();
23+
WriterError writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, QgsRectangle outputExtent,
24+
const QgsCoordinateReferenceSystem& crs, QProgressDialog* p = 0 );
25+
26+
void setOutputFormat( const QString& format );
27+
QString outputFormat() const;
28+
29+
void setOutputProviderKey( const QString& key );
30+
QString outputProviderKey() const;
31+
32+
void setTiledMode( bool t );
33+
bool tiledMode() const;
34+
35+
void setMaxTileWidth( int w );
36+
int maxTileWidth() const;
37+
38+
QgsRasterDataProvider::RasterBuildPyramids buildPyramidsFlag() const;
39+
void setBuildPyramidsFlag( QgsRasterDataProvider::RasterBuildPyramids f );
40+
41+
QList< int > pyramidsList() const;
42+
void setPyramidsList( const QList< int > & list );
43+
44+
QString pyramidsResampling() const;
45+
void setPyramidsResampling( const QString & str );
46+
47+
QgsRasterDataProvider::RasterPyramidsFormat pyramidsFormat() const;
48+
void setPyramidsFormat( QgsRasterDataProvider::RasterPyramidsFormat f );
49+
50+
void setMaxTileHeight( int h );
51+
int maxTileHeight() const;
52+
53+
void setCreateOptions( const QStringList& list );
54+
QStringList createOptions() const;
55+
};
56+

python/core/qgsrasterpipe.sip

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
/** Raster pipe */
3+
4+
class QgsRasterPipe
5+
{
6+
%TypeHeaderCode
7+
#include <qgsrasterpipe.h>
8+
#include <qgsrasterresamplefilter.h>
9+
#include <qgsrasterprojector.h>
10+
%End
11+
public:
12+
enum Role
13+
{
14+
UnknownRole = 0,
15+
ProviderRole = 1,
16+
RendererRole = 2,
17+
ResamplerRole = 3,
18+
ProjectorRole = 4
19+
};
20+
21+
QgsRasterPipe();
22+
QgsRasterPipe( const QgsRasterPipe& thePipe );
23+
24+
~QgsRasterPipe();
25+
26+
bool insert( int idx, QgsRasterInterface* theInterface );
27+
28+
bool replace( int idx, QgsRasterInterface* theInterface );
29+
30+
bool set( QgsRasterInterface * theInterface );
31+
32+
bool remove( int idx );
33+
34+
bool remove( QgsRasterInterface * theInterface );
35+
36+
int size() const;
37+
QgsRasterInterface * at( int idx ) const;
38+
QgsRasterInterface * last() const;
39+
40+
bool setOn( int idx, bool on );
41+
42+
bool canSetOn( int idx, bool on );
43+
44+
QgsRasterDataProvider * provider() const;
45+
QgsRasterRenderer * renderer() const;
46+
QgsRasterResampleFilter * resampleFilter() const;
47+
QgsRasterProjector * projector() const;
48+
49+
void setStatsOn( bool on );
50+
};
51+

python/core/qgsrasterprojector.sip

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
/** Raster projector */
3+
4+
class QgsRasterProjector
5+
{
6+
%TypeHeaderCode
7+
#include <qgsrasterprojector.h>
8+
#include <qgscoordinatereferencesystem.h>
9+
%End
10+
public:
11+
QgsRasterProjector(
12+
QgsCoordinateReferenceSystem theSrcCRS,
13+
QgsCoordinateReferenceSystem theDestCRS,
14+
QgsRectangle theDestExtent,
15+
int theDestRows, int theDestCols,
16+
double theMaxSrcXRes, double theMaxSrcYRes,
17+
QgsRectangle theExtent
18+
);
19+
QgsRasterProjector(
20+
QgsCoordinateReferenceSystem theSrcCRS,
21+
QgsCoordinateReferenceSystem theDestCRS,
22+
double theMaxSrcXRes, double theMaxSrcYRes,
23+
QgsRectangle theExtent
24+
);
25+
QgsRasterProjector();
26+
27+
~QgsRasterProjector();
28+
29+
QgsRasterInterface * clone() const;
30+
31+
int bandCount() const;
32+
33+
QgsRasterInterface::DataType dataType( int bandNo ) const;
34+
35+
void setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS );
36+
37+
QgsCoordinateReferenceSystem srcCrs() const;
38+
39+
QgsCoordinateReferenceSystem destCrs() const;
40+
41+
void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes );
42+
43+
QgsRectangle srcExtent();
44+
45+
int srcRows();
46+
int srcCols();
47+
void setSrcRows( int theRows );
48+
void setSrcCols( int theCols );
49+
50+
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
51+
52+
int dstRows() const;
53+
int dstCols() const;
54+
55+
void * readBlock( int bandNo, const QgsRectangle & extent, int width, int height );
56+
};
57+
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1+
2+
/** Raster resample filter */
3+
14
class QgsRasterResampleFilter
25
{
36
%TypeHeaderCode
4-
#include "qgsrasterresamplefilter.h"
7+
#include <qgsrasterresamplefilter.h>
58
%End
9+
QgsRasterResampleFilter();
10+
QgsRasterResampleFilter( const QgsRasterResampleFilter& thePipe );
611

7-
public:
8-
QgsRasterResampleFilter( QgsRasterFace* input = 0 );
912
~QgsRasterResampleFilter();
1013

14+
QgsRasterInterface * clone() const;
15+
16+
int bandCount() const;
17+
18+
QgsRasterInterface::DataType dataType( int bandNo ) const;
19+
20+
bool setInput( QgsRasterInterface* input );
21+
1122
void * readBlock( int bandNo, const QgsRectangle & extent, int width, int height );
1223

13-
/**Set resampler for zoomed in scales. Takes ownership of the object*/
1424
void setZoomedInResampler( QgsRasterResampler* r );
15-
const QgsRasterResampler* zoomedInResampler();
25+
const QgsRasterResampler* zoomedInResampler() const;
1626

17-
/**Set resampler for zoomed out scales. Takes ownership of the object*/
1827
void setZoomedOutResampler( QgsRasterResampler* r );
1928
const QgsRasterResampler* zoomedOutResampler() const;
2029

2130
void setMaxOversampling( double os );
2231
double maxOversampling() const;
2332

24-
virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const = 0;
33+
void writeXML( QDomDocument& doc, QDomElement& parentElem );
2534

26-
/**Sets base class members from xml. Usually called from create() methods of subclasses*/
27-
void readXML( const QDomElement& rendererElem );
35+
void readXML( const QDomElement& resamplefilterElem );
2836
};
2937

src/core/qgsrasterprojector.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ QgsRasterProjector::QgsRasterProjector()
6666
QgsDebugMsg( "Entered" );
6767
}
6868

69+
QgsRasterProjector::QgsRasterProjector( const QgsRasterProjector &projector )
70+
{
71+
mSrcCRS = projector.mSrcCRS;
72+
mDestCRS = projector.mDestCRS;
73+
mMaxSrcXRes = projector.mMaxSrcXRes;
74+
mMaxSrcYRes = projector.mMaxSrcYRes;
75+
mExtent = projector.mExtent;
76+
mCoordinateTransform.setSourceCrs( mSrcCRS );
77+
mCoordinateTransform.setDestCRS( mDestCRS );
78+
}
79+
80+
QgsRasterProjector & QgsRasterProjector::operator=( const QgsRasterProjector & projector )
81+
{
82+
if ( &projector != this )
83+
{
84+
mSrcCRS = projector.mSrcCRS;
85+
mDestCRS = projector.mDestCRS;
86+
mMaxSrcXRes = projector.mMaxSrcXRes;
87+
mMaxSrcYRes = projector.mMaxSrcYRes;
88+
mExtent = projector.mExtent;
89+
mCoordinateTransform.setSourceCrs( mSrcCRS );
90+
mCoordinateTransform.setDestCRS( mDestCRS );
91+
}
92+
return *this;
93+
}
94+
6995
QgsRasterInterface * QgsRasterProjector::clone() const
7096
{
7197
QgsDebugMsg( "Entered" );
@@ -93,7 +119,7 @@ QgsRasterInterface::DataType QgsRasterProjector::dataType( int bandNo ) const
93119
return QgsRasterInterface::UnknownDataType;
94120
}
95121

96-
void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
122+
void QgsRasterProjector::setCRS( const QgsCoordinateReferenceSystem & theSrcCRS, const QgsCoordinateReferenceSystem & theDestCRS )
97123
{
98124
mSrcCRS = theSrcCRS;
99125
mDestCRS = theDestCRS;

0 commit comments

Comments
 (0)