Skip to content

Commit 76115ec

Browse files
committed
Raster statistics and histogram moved from QgsRasterDataProvider to QgsRasterInterface
1 parent b662077 commit 76115ec

File tree

9 files changed

+865
-796
lines changed

9 files changed

+865
-796
lines changed

python/core/raster/qgsrasterdataprovider.sip

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
1515

1616
public:
1717

18-
//! If you add to this, please also add to capabilitiesString()
19-
enum Capability
20-
{
21-
NoCapabilities,
22-
Identify,
23-
ExactMinimumMaximum,
24-
ExactResolution,
25-
EstimatedMinimumMaximum,
26-
BuildPyramids,
27-
Histogram,
28-
Size,
29-
Create,
30-
Remove,
31-
IdentifyValue,
32-
IdentifyText,
33-
IdentifyHtml,
34-
IdentifyFeature
35-
};
36-
3718
// This is modified copy of GDALColorInterp
3819
enum ColorInterpretation
3920
{
@@ -104,23 +85,12 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
10485
*/
10586
virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;
10687

107-
/** Returns a bitmask containing the supported capabilities
108-
Note, some capabilities may change depending on whether
109-
a spatial filter is active on this provider, so it may
110-
be prudent to check this value per intended operation.
111-
*/
112-
virtual int capabilities() const;
113-
114-
/**
115-
* Returns the above in friendly format.
116-
*/
117-
QString capabilitiesString() const;
118-
119-
12088
// TODO: Get the supported formats by this provider
12189

12290
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
12391

92+
virtual QgsRectangle extent() = 0;
93+
12494
/** Returns data type for the band specified by number */
12595
virtual QGis::DataType dataType( int bandNo ) const = 0;
12696

@@ -162,7 +132,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
162132
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) / Factory /;
163133

164134
/* Read a value from a data block at a given index. */
165-
virtual double readValue( void *data, int type, int index );
135+
//virtual double readValue( void *data, int type, int index );
166136

167137
/* Return true if source band has no data value */
168138
virtual bool srcHasNoDataValue( int bandNo ) const;
@@ -198,50 +168,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
198168
/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
199169
virtual QStringList subLayers() const;
200170

201-
/** \brief Get histogram. Histograms are cached in providers.
202-
* @param theBandNo The band (number).
203-
* @param theBinCount Number of bins (intervals,buckets). If 0, the number of bins is decided automaticaly according to data type, raster size etc.
204-
* @param theMinimum Minimum value, if NaN, raster minimum value will be used.
205-
* @param theMaximum Maximum value, if NaN, raster minimum value will be used.
206-
* @param theExtent Extent used to calc histogram, if empty, whole raster extent is used.
207-
* @param theSampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
208-
* @param theIncludeOutOfRange include out of range values
209-
* @return Vector of non NULL cell counts for each bin.
210-
*/
211-
virtual QgsRasterHistogram histogram( int theBandNo,
212-
int theBinCount,
213-
double theMinimum,
214-
double theMaximum,
215-
const QgsRectangle & theExtent = QgsRectangle(),
216-
int theSampleSize = 0,
217-
bool theIncludeOutOfRange = false );
218-
219-
/** \brief Returns true if histogram is available (cached, already calculated), the parameters are the same as in histogram() */
220-
virtual bool hasHistogram( int theBandNo,
221-
int theBinCount,
222-
double theMinimum,
223-
double theMaximum,
224-
const QgsRectangle & theExtent = QgsRectangle(),
225-
int theSampleSize = 0,
226-
bool theIncludeOutOfRange = false );
227-
228-
/** \brief Find values for cumulative pixel count cut.
229-
* @param theBandNo The band (number).
230-
* @param theLowerCount The lower count as fraction of 1, e.g. 0.02 = 2%
231-
* @param theUpperCount The upper count as fraction of 1, e.g. 0.98 = 98%
232-
* @param theLowerValue Location into which the lower value will be set.
233-
* @param theUpperValue Location into which the upper value will be set.
234-
* @param theExtent Extent used to calc histogram, if empty, whole raster extent is used.
235-
* @param theSampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
236-
*/
237-
virtual void cumulativeCut( int theBandNo,
238-
double theLowerCount,
239-
double theUpperCount,
240-
double &theLowerValue,
241-
double &theUpperValue,
242-
const QgsRectangle & theExtent = QgsRectangle(),
243-
int theSampleSize = 0 );
244-
245171
/** \brief Create pyramid overviews */
246172
virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
247173
const QString & theResamplingMethod = "NEAREST",
@@ -259,32 +185,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
259185
/** \brief Returns true if raster has at least one populated histogram. */
260186
bool hasPyramids();
261187

262-
/** If the provider supports it, return band stats for the
263-
given band. Default behaviour is to blockwise read the data
264-
and generate the stats unless the provider overloads this function. */
265-
//virtual QgsRasterBandStats bandStatistics( int theBandNo );
266-
267-
/** \brief Get band statistics.
268-
* @param theBandNo The band (number).
269-
* @param theStats Requested statistics
270-
* @param theExtent Extent used to calc histogram, if empty, whole raster extent is used.
271-
* @param theSampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
272-
* @return Band statistics.
273-
*/
274-
virtual QgsRasterBandStats bandStatistics( int theBandNo,
275-
int theStats = QgsRasterBandStats::All,
276-
const QgsRectangle & theExtent = QgsRectangle(),
277-
int theSampleSize = 0 );
278-
279-
/** \brief Returns true if histogram is available (cached, already calculated), the parameters are the same as in histogram() */
280-
virtual bool hasStatistics( int theBandNo,
281-
int theStats = QgsRasterBandStats::All,
282-
const QgsRectangle & theExtent = QgsRectangle(),
283-
int theSampleSize = 0 );
284-
285-
/** \brief helper function to create zero padded band names */
286-
QString generateBandName( int theBandNumber ) const;
287-
288188
/**
289189
* Get metadata in a format suitable for feeding directly
290190
* into a subset of the GUI raster properties "Metadata" tab.

python/core/raster/qgsrasterinterface.sip

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ class QgsRasterInterface
4141
%End
4242

4343
public:
44+
enum Capability
45+
{
46+
NoCapabilities,
47+
Identify,
48+
ExactMinimumMaximum,
49+
ExactResolution,
50+
EstimatedMinimumMaximum,
51+
BuildPyramids,
52+
Histogram,
53+
Size,
54+
Create,
55+
Remove,
56+
IdentifyValue,
57+
IdentifyText,
58+
IdentifyHtml,
59+
IdentifyFeature
60+
};
4461

4562
QgsRasterInterface( QgsRasterInterface * input = 0 );
4663

@@ -49,6 +66,14 @@ class QgsRasterInterface
4966
/** Clone itself, create deep copy */
5067
virtual QgsRasterInterface *clone() const = 0 /Factory/;
5168

69+
/** Returns a bitmask containing the supported capabilities */
70+
virtual int capabilities() const;
71+
72+
/**
73+
* Returns the above in friendly format.
74+
*/
75+
QString capabilitiesString() const;
76+
5277
/** Returns data type for the band specified by number */
5378
virtual QGis::DataType dataType( int bandNo ) const = 0;
5479

@@ -57,6 +82,14 @@ class QgsRasterInterface
5782
/** Get number of bands */
5883
virtual int bandCount() const = 0;
5984

85+
/** Get block size */
86+
virtual int xBlockSize() const;
87+
virtual int yBlockSize() const;
88+
89+
/** Get raster size */
90+
virtual int xSize() const;
91+
virtual int ySize() const;
92+
6093
/** Return no data value for specific band. Each band/provider must have
6194
* no data value, if there is no one set in original data, provider decides one
6295
* possibly using wider data type.
@@ -90,5 +123,74 @@ class QgsRasterInterface
90123
* resampling etc.
91124
*/
92125
virtual QgsRasterInterface *srcInput();
126+
127+
/** \brief Get band statistics.
128+
* @param theBandNo The band (number).
129+
* @param theStats Requested statistics
130+
* @param theExtent Extent used to calc statistics, if empty, whole raster extent is used.
131+
* @param theSampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
132+
* @return Band statistics.
133+
*/
134+
virtual QgsRasterBandStats bandStatistics( int theBandNo,
135+
int theStats = QgsRasterBandStats::All,
136+
const QgsRectangle & theExtent = QgsRectangle(),
137+
int theSampleSize = 0 );
138+
139+
/** \brief Returns true if histogram is available (cached, already calculated). * The parameters are the same as in bandStatistics()
140+
* @return true if statistics are available (ready to use)
141+
*/
142+
virtual bool hasStatistics( int theBandNo,
143+
int theStats = QgsRasterBandStats::All,
144+
const QgsRectangle & theExtent = QgsRectangle(),
145+
int theSampleSize = 0 );
146+
147+
148+
/** \brief Get histogram. Histograms are cached in providers.
149+
* @param theBandNo The band (number).
150+
* @param theBinCount Number of bins (intervals,buckets). If 0, the number of bins is decided automaticaly according to data type, raster size etc.
151+
* @param theMinimum Minimum value, if NaN, raster minimum value will be used.
152+
* @param theMaximum Maximum value, if NaN, raster minimum value will be used.
153+
* @param theExtent Extent used to calc histogram, if empty, whole raster extent is used.
154+
* @param theSampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
155+
* @param theIncludeOutOfRange include out of range values
156+
* @return Vector of non NULL cell counts for each bin.
157+
* @note theBinCount, theMinimun and theMaximum not optional in python bindings
158+
*/
159+
virtual QgsRasterHistogram histogram( int theBandNo,
160+
int theBinCount,
161+
double theMinimum,
162+
double theMaximum,
163+
const QgsRectangle & theExtent,
164+
int theSampleSize,
165+
bool theIncludeOutOfRange );
166+
167+
/** \brief Returns true if histogram is available (cached, already calculated), the parameters are the same as in histogram()
168+
* @note theBinCount, theMinimun and theMaximum not optional in python bindings
169+
*/
170+
virtual bool hasHistogram( int theBandNo,
171+
int theBinCount,
172+
double theMinimum,
173+
double theMaximum,
174+
const QgsRectangle & theExtent,
175+
int theSampleSize,
176+
bool theIncludeOutOfRange );
177+
178+
/** \brief Find values for cumulative pixel count cut.
179+
* @param theBandNo The band (number).
180+
* @param theLowerCount The lower count as fraction of 1, e.g. 0.02 = 2%
181+
* @param theUpperCount The upper count as fraction of 1, e.g. 0.98 = 98%
182+
* @param theLowerValue Location into which the lower value will be set.
183+
* @param theUpperValue Location into which the upper value will be set.
184+
* @param theExtent Extent used to calc histogram, if empty, whole raster extent is used.
185+
* @param theSampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
186+
*/
187+
virtual void cumulativeCut( int theBandNo,
188+
double theLowerCount,
189+
double theUpperCount,
190+
double &theLowerValue,
191+
double &theUpperValue,
192+
const QgsRectangle & theExtent = QgsRectangle(),
193+
int theSampleSize = 0 );
194+
93195
};
94196

src/core/raster/qgsrasterchecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ bool QgsRasterChecker::runTest( QString theVerifiedKey, QString theVerifiedUri,
159159
for ( int col = 0; col < width; col ++ )
160160
{
161161
bool cellOk = true;
162-
double verifiedVal = verifiedProvider->readValue( verifiedData, verifiedProvider->dataType( band ), row * width + col );
163-
double expectedVal = expectedProvider->readValue( expectedData, expectedProvider->dataType( band ), row * width + col );
162+
double verifiedVal = QgsRasterBlock::readValue( verifiedData, verifiedProvider->dataType( band ), row * width + col );
163+
double expectedVal = QgsRasterBlock::readValue( expectedData, expectedProvider->dataType( band ), row * width + col );
164164

165165
QString valStr;
166166
if ( compare( verifiedVal, expectedVal, 0 ) )

0 commit comments

Comments
 (0)