Skip to content
Permalink
Browse files

raster stats for providers without block size fixed

  • Loading branch information
blazek committed Aug 14, 2012
1 parent 0c67fdd commit da5609c839803b31039b4d671005d80c2d434f1b
@@ -538,15 +538,21 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
double myNoDataValue = noDataValue();
int myDataType = dataType( theBandNo );

if ( xBlockSize() == 0 || yBlockSize() == 0 ) // should not happen
int myXBlockSize = xBlockSize();
int myYBlockSize = yBlockSize();
if ( myXBlockSize == 0 ) // should not happen, but happens
{
return myRasterBandStats;
myXBlockSize = 500;
}
if ( myYBlockSize == 0 ) // should not happen, but happens
{
myYBlockSize = 500;
}

int myNXBlocks = ( myWidth + xBlockSize() - 1 ) / xBlockSize();
int myNYBlocks = ( myHeight + yBlockSize() - 1 ) / yBlockSize();
int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;

void *myData = CPLMalloc( xBlockSize() * yBlockSize() * ( dataTypeSize( theBandNo ) / 8 ) );
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( dataTypeSize( theBandNo ) / 8 ) );

double myXRes = myExtent.width() / myWidth;
double myYRes = myExtent.height() / myHeight;
@@ -561,12 +567,13 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
{
for ( int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
{
int myBlockWidth = qMin( xBlockSize(), myWidth - myXBlock * xBlockSize() );
int myBlockHeight = qMin( yBlockSize(), myHeight - myYBlock * yBlockSize() );
QgsDebugMsg( QString( "myYBlock = %1 myXBlock = %2" ).arg( myYBlock ).arg( myXBlock ) );
int myBlockWidth = qMin( myXBlockSize, myWidth - myXBlock * myXBlockSize );
int myBlockHeight = qMin( myYBlockSize, myHeight - myYBlock * myYBlockSize );

double xmin = myExtent.xMinimum() + myXBlock * xBlockSize() * myXRes;
double xmin = myExtent.xMinimum() + myXBlock * myXBlockSize * myXRes;
double xmax = xmin + myBlockWidth * myXRes;
double ymin = myExtent.yMaximum() - myYBlock * yBlockSize() * myYRes;
double ymin = myExtent.yMaximum() - myYBlock * myYBlockSize * myYRes;
double ymax = ymin - myBlockHeight * myYRes;

QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );
@@ -808,15 +815,21 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
double myNoDataValue = noDataValue();
int myDataType = dataType( theBandNo );

if ( xBlockSize() == 0 || yBlockSize() == 0 ) // should not happen
int myXBlockSize = xBlockSize();
int myYBlockSize = yBlockSize();
if ( myXBlockSize == 0 ) // should not happen, but happens
{
return myHistogram;
myXBlockSize = 500;
}
if ( myYBlockSize == 0 ) // should not happen, but happens
{
myYBlockSize = 500;
}

int myNXBlocks = ( myWidth + xBlockSize() - 1 ) / xBlockSize();
int myNYBlocks = ( myHeight + yBlockSize() - 1 ) / yBlockSize();
int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;

void *myData = CPLMalloc( xBlockSize() * yBlockSize() * ( dataTypeSize( theBandNo ) / 8 ) );
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( dataTypeSize( theBandNo ) / 8 ) );

double myXRes = myExtent.width() / myWidth;
double myYRes = myExtent.height() / myHeight;
@@ -839,12 +852,12 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
{
for ( int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
{
int myBlockWidth = qMin( xBlockSize(), myWidth - myXBlock * xBlockSize() );
int myBlockHeight = qMin( yBlockSize(), myHeight - myYBlock * yBlockSize() );
int myBlockWidth = qMin( myXBlockSize, myWidth - myXBlock * myXBlockSize );
int myBlockHeight = qMin( myYBlockSize, myHeight - myYBlock * myYBlockSize );

double xmin = myExtent.xMinimum() + myXBlock * xBlockSize() * myXRes;
double xmin = myExtent.xMinimum() + myXBlock * myXBlockSize * myXRes;
double xmax = xmin + myBlockWidth * myXRes;
double ymin = myExtent.yMaximum() - myYBlock * yBlockSize() * myYRes;
double ymin = myExtent.yMaximum() - myYBlock * myYBlockSize * myYRes;
double ymax = ymin - myBlockHeight * myYRes;

QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );
@@ -750,6 +750,12 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom10( QByteArray const &xml, QgsW
gridElement = domElement( coverageOfferingElement, "domainSet.spatialDomain.Grid" );
}

// If supportedCRSs.nativeCRSs is not defined we try to get it from RectifiedGrid
if ( coverage->nativeCrs.isEmpty() )
{
coverage->nativeCrs = gridElement.attribute( "srsName" );
}

if ( !gridElement.isNull() )
{
QList<int> low = parseInts( domElementText( gridElement, "limits.GridEnvelope.low" ) );
@@ -166,8 +166,10 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
}
}
QgsDebugMsg( "mCoverageCrs = " + mCoverageCrs );
// We cannot continue without CRS
if ( mCoverageCrs.isEmpty() ) return;

// It may happen that coverage CRS is not given or it is unknown
// in that case we continue without CRS and user is asked for it
//if ( mCoverageCrs.isEmpty() ) return;

mWidth = mCoverageSummary.width;
mHeight = mCoverageSummary.height;
@@ -1460,12 +1462,19 @@ QString QgsWcsProvider::metadata()
metadata += tr( "Coverages" );
metadata += "</th></tr>";

// Dialog takes too long to open if there are too many coverages (1000 for example)
int count = 0;
foreach ( QgsWcsCoverageSummary c, mCapabilities.coverages() )
{
metadata += coverageMetadata( c );
count++;
if ( count >= 100 ) break;
}

metadata += "</table>";
if ( count < mCapabilities.coverages().size() )
{
metadata += tr( "And %1 more coverages" ).arg( mCapabilities.coverages().size() - count );
}

QgsDebugMsg( "exiting with '" + metadata + "'." );

@@ -70,10 +70,14 @@ void TestQgsWcsPublicServers::test( )
// It may happen that server supports 1.1.1, but does not accept 1.1 (http://zeus.pin.unifi.it/gi-wcs/http)
versions << "" << "1.0.0" << "1.1.0"; // empty for default
QStringList servers;
// Some (first) coverages do not advertize any supportedCRS and sever gives
// error both with native CRS (EPSG::561005) and EPSG:4326
// MOD* coverages work OK
servers << "http://argon.geogr.uni-jena.de:8080/geoserver/ows";
servers << "http://demo.geonode.org/geoserver/wcs";
servers << "http://demo.mapserver.org/cgi-bin/wcs";
servers << "http://demo.opengeo.org/geoserver/wcs";
// geobrain.laits.gmu.edu servers are quite slow
servers << "http://geobrain.laits.gmu.edu/cgi-bin/gbwcs-dem";
servers << "http://geobrain.laits.gmu.edu/cgi-bin/ows8/wcseo";
servers << "http://geobrain.laits.gmu.edu/cgi-bin/wcs110";
@@ -146,11 +150,25 @@ void TestQgsWcsPublicServers::test( )
}

int myCoverageCount = 0;
int myStep = myCoverages.size() / mMaxCoverages;
int myStepCount = -1;
foreach ( QgsWcsCoverageSummary myCoverage, myCoverages )
{
QgsDebugMsg( "coverage: " + myCoverage.identifier );
// Go in steps to get more success/errors
if ( myStepCount == -1 || myStepCount > myStep )
{
myStepCount = 0;
}
else
{
myStepCount++;
continue;
}

myCoverageCount++;
if ( myCoverageCount > mMaxCoverages ) continue;
if ( myCoverageCount > mMaxCoverages ) break;

QString myPath = myServerDir.absolutePath() + QDir::separator() + myCoverage.identifier;

if ( !version.isEmpty() )

0 comments on commit da5609c

Please sign in to comment.
You can’t perform that action at this time.