Skip to content

Commit cbdcd77

Browse files
committedJul 3, 2012
wcs null values, enabled statistics
1 parent 49ca5f5 commit cbdcd77

File tree

4 files changed

+95
-11
lines changed

4 files changed

+95
-11
lines changed
 

‎src/core/qgsrasterdataprovider.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ QByteArray QgsRasterDataProvider::noValueBytes( int theBandNo )
243243

244244
QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
245245
{
246+
QgsDebugMsg( QString( "theBandNo = %1" ).arg( theBandNo ) );
246247
double myNoDataValue = noDataValue();
247248
QgsRasterBandStats myRasterBandStats;
248249
myRasterBandStats.elementCount = 0; // because we'll be counting only VALID pixels later
@@ -255,7 +256,7 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
255256
myXBlockSize = xBlockSize();
256257
myYBlockSize = yBlockSize();
257258

258-
if ( myXBlockSize == 0 || myYBlockSize == 0 )
259+
if ( !( capabilities() & QgsRasterDataProvider::Size ) || xSize() == 0 || ySize() == 0 || myXBlockSize == 0 || myYBlockSize == 0 )
259260
{
260261
return QgsRasterBandStats(); //invalid raster band stats
261262
}
@@ -295,7 +296,7 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
295296
for ( int iX = 0; iX < nXValid; iX++ )
296297
{
297298
double myValue = readValue( myData, myDataType, iX + ( iY * myXBlockSize ) );
298-
//QgsDebugMsg ( QString ( "%1 %2 value %3" ).arg (iX).arg(iY).arg( myValue ) );
299+
QgsDebugMsgLevel( QString( "%1 %2 value %3" ).arg( iX ).arg( iY ).arg( myValue ), 10 );
299300

300301
if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
301302
{
@@ -381,14 +382,13 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
381382
( myRasterBandStats.elementCount - 1 ) ) );
382383

383384
#ifdef QGISDEBUG
384-
QgsLogger::debug( "************ STATS **************", 1, __FILE__, __FUNCTION__, __LINE__ );
385-
QgsLogger::debug( "VALID NODATA", mValidNoDataValue, 1, __FILE__, __FUNCTION__, __LINE__ );
386-
QgsLogger::debug( "NULL", noDataValue() , 1, __FILE__, __FUNCTION__, __LINE__ );
387-
QgsLogger::debug( "MIN", myRasterBandStats.minimumValue, 1, __FILE__, __FUNCTION__, __LINE__ );
388-
QgsLogger::debug( "MAX", myRasterBandStats.maximumValue, 1, __FILE__, __FUNCTION__, __LINE__ );
389-
QgsLogger::debug( "RANGE", myRasterBandStats.range, 1, __FILE__, __FUNCTION__, __LINE__ );
390-
QgsLogger::debug( "MEAN", myRasterBandStats.mean, 1, __FILE__, __FUNCTION__, __LINE__ );
391-
QgsLogger::debug( "STDDEV", myRasterBandStats.stdDev, 1, __FILE__, __FUNCTION__, __LINE__ );
385+
QgsDebugMsg( "************ STATS **************" );
386+
QgsDebugMsg( QString( "VALID NODATA %1" ).arg( mValidNoDataValue ) );
387+
QgsDebugMsg( QString( "MIN %1" ).arg( myRasterBandStats.minimumValue ) );
388+
QgsDebugMsg( QString( "MAX %1" ).arg( myRasterBandStats.maximumValue ) );
389+
QgsDebugMsg( QString( "RANGE %1" ).arg( myRasterBandStats.range ) );
390+
QgsDebugMsg( QString( "MEAN %1" ).arg( myRasterBandStats.mean ) );
391+
QgsDebugMsg( QString( "STDDEV %1" ).arg( myRasterBandStats.stdDev ) );
392392
#endif
393393

394394
CPLFree( myData );

‎src/gui/qgsowssourceselect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,15 @@ void QgsOWSSourceSelect::populateFormats()
221221
QgsDebugMsg( QString( "format %1 not supported." ).arg( format ) );
222222
//btn->setEnabled( false );
223223
btn->setEnabled( true );
224+
if ( firstEnabled < 0 ) { firstEnabled = i; }
224225
tip += " " + tr( "is not supported by GDAL" );
225226
}
226227
btn->setText( label );
227228
btn->setToolTip( tip );
228229
}
229230
// Set prefered
230231
// TODO: all enabled for now, see above
231-
//prefered = prefered >= 0 ? prefered : firstEnabled;
232+
prefered = prefered >= 0 ? prefered : firstEnabled;
232233
if ( prefered >= 0 )
233234
{
234235
mImageFormatGroup->button( prefered )->setChecked( true );

‎src/providers/wcs/qgswcsprovider.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ static QString WCS_DESCRIPTION = "OGC Web Coverage Service version 1.0/1.1 data
7171

7272
static QString DEFAULT_LATLON_CRS = "CRS:84";
7373

74+
// TODO: colortable - use comon baseclass with gdal, mapserver does not support http://trac.osgeo.org/mapserver/ticket/1671
75+
7476
QgsWcsProvider::QgsWcsProvider( QString const &uri )
7577
: QgsRasterDataProvider( uri )
7678
, mHttpUri( QString::null )
@@ -88,6 +90,8 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
8890
, mCachedMemFile( 0 )
8991
, mWidth( 0 )
9092
, mHeight( 0 )
93+
, mXBlockSize( 0 )
94+
, mYBlockSize( 0 )
9195
, mHasSize( false )
9296
, mBandCount( 0 )
9397
{
@@ -174,6 +178,12 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
174178
mSrcGdalDataType.append( myGdalDataType );
175179
// TODO: This could be shared with GDAL provider
176180
int isValid = false;
181+
182+
// UMN Mapserver does not automaticaly set null value, METADATA wcs_rangeset_nullvalue must be used
183+
// http://lists.osgeo.org/pipermail/mapserver-users/2010-April/065328.html
184+
185+
// TODO:
186+
177187
double myNoDataValue = GDALGetRasterNoDataValue( gdalBand, &isValid );
178188
if ( isValid )
179189
{
@@ -216,6 +226,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
216226
}
217227
}
218228
mNoDataValue.append( myNoDataValue );
229+
mValidNoDataValue = true;
219230

220231
QgsDebugMsg( QString( "mSrcGdalDataType[%1] = %2" ).arg( i - 1 ).arg( mSrcGdalDataType[i-1] ) );
221232
QgsDebugMsg( QString( "mGdalDataType[%1] = %2" ).arg( i - 1 ).arg( mGdalDataType[i-1] ) );
@@ -224,6 +235,18 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
224235

225236
clearCache();
226237

238+
// Block size is used for for statistics
239+
// TODO: How to find maximum block size supported by server?
240+
if ( mHasSize )
241+
{
242+
// This is taken from GDAL, how they come to these numbers?
243+
if ( mWidth > 1800 ) mXBlockSize = 1024;
244+
else mXBlockSize = mWidth;
245+
246+
if ( mHeight > 900 ) mYBlockSize = 512;
247+
else mYBlockSize = mHeight;
248+
}
249+
227250
mValid = true;
228251
QgsDebugMsg( "Constructed ok, provider valid." );
229252
}
@@ -491,6 +514,32 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const & viewExtent, int
491514

492515
}
493516

517+
// For stats only, maybe change QgsRasterDataProvider::bandStatistics() to
518+
// use standard readBlock with extent
519+
void QgsWcsProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *block )
520+
{
521+
QgsDebugMsg( "Entered" );
522+
523+
QgsDebugMsg( QString( "xBlock = %1 yBlock = %2" ).arg( xBlock ).arg( yBlock ) );
524+
525+
if ( !mHasSize ) return;
526+
527+
double xRes = mCoverageExtent.width() / mWidth;
528+
double yRes = mCoverageExtent.height() / mHeight;
529+
530+
// blocks on edges may run out of extent, that should not be problem (at least for
531+
// stats - there is a check for it)
532+
double xMin = mCoverageExtent.xMinimum() + xRes * xBlock * mXBlockSize;
533+
double xMax = xMin + xRes * mXBlockSize;
534+
double yMax = mCoverageExtent.yMaximum() - yRes * yBlock * mYBlockSize;
535+
double yMin = yMax - yRes * mYBlockSize;
536+
//QgsDebugMsg( QString("yMin = %1 yMax = %2").arg(yMin).arg(yMax) );
537+
538+
QgsRectangle extent( xMin, yMin, xMax, yMax );
539+
540+
readBlock( theBandNo, extent, mXBlockSize, mYBlockSize, block );
541+
}
542+
494543
void QgsWcsProvider::cacheReplyFinished()
495544
{
496545
if ( mCacheReply->error() == QNetworkReply::NoError )
@@ -685,6 +734,29 @@ int QgsWcsProvider::bandCount() const
685734
return mBandCount;
686735
}
687736

737+
double QgsWcsProvider::noDataValue() const
738+
{
739+
if ( mNoDataValue.size() > 0 )
740+
{
741+
return mNoDataValue[0];
742+
}
743+
return std::numeric_limits<int>::max(); // should not happen or be used
744+
}
745+
746+
// this is only called once when statistics are calculated
747+
// TODO
748+
int QgsWcsProvider::xBlockSize() const
749+
{
750+
return mXBlockSize;
751+
}
752+
int QgsWcsProvider::yBlockSize() const
753+
{
754+
return mYBlockSize;
755+
}
756+
757+
int QgsWcsProvider::xSize() const { return mWidth; }
758+
int QgsWcsProvider::ySize() const { return mHeight; }
759+
688760
void QgsWcsProvider::clearCache()
689761
{
690762
QgsDebugMsg( "Entered" );

‎src/providers/wcs/qgswcsprovider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class QgsWcsProvider : public QgsRasterDataProvider
118118

119119
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
120120

121+
void readBlock( int theBandNo, int xBlock, int yBlock, void *block );
122+
121123
/** Download cache */
122124
void getCache( int bandNo, QgsRectangle const & viewExtent, int width, int height );
123125

@@ -141,6 +143,11 @@ class QgsWcsProvider : public QgsRasterDataProvider
141143
int dataType( int bandNo ) const;
142144
int srcDataType( int bandNo ) const;
143145
int bandCount() const;
146+
double noDataValue() const;
147+
int xBlockSize() const;
148+
int yBlockSize() const;
149+
int xSize() const;
150+
int ySize() const;
144151
QString metadata();
145152
QString identifyAsHtml( const QgsPoint& point );
146153
QString identifyAsText( const QgsPoint& point );
@@ -266,6 +273,10 @@ class QgsWcsProvider : public QgsRasterDataProvider
266273
/** Coverage width, may be 0 if it could not be found in DescribeCoverage */
267274
int mHeight;
268275

276+
/** Block size */
277+
int mXBlockSize;
278+
int mYBlockSize;
279+
269280
/** Flag if size was parsed successfully */
270281
bool mHasSize;
271282

0 commit comments

Comments
 (0)
Please sign in to comment.