@@ -71,6 +71,8 @@ static QString WCS_DESCRIPTION = "OGC Web Coverage Service version 1.0/1.1 data
7171
7272static 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+
7476QgsWcsProvider::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+
494543void 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+
688760void QgsWcsProvider::clearCache ()
689761{
690762 QgsDebugMsg ( " Entered" );
0 commit comments