Added QgsRasterIdentifyResult

This commit is contained in:
Radim Blazek 2013-04-08 18:25:44 +02:00
parent 51fc960b42
commit a3de4c4e0a
19 changed files with 299 additions and 42 deletions

View File

@ -24,6 +24,7 @@
%Include qgsdatasourceuri.sip
%Include qgsdbfilterproxymodel.sip
%Include qgsdistancearea.sip
%Include qgserror.sip
%Include qgsexpression.sip
%Include qgsfeature.sip
%Include qgsfeatureiterator.sip
@ -141,6 +142,7 @@
%Include raster/qgsrasterdataprovider.sip
%Include raster/qgsrasterfilewriter.sip
%Include raster/qgsrasterhistogram.sip
%Include raster/qgsrasteridentifyresult.sip
%Include raster/qgsrasterinterface.sip
%Include raster/qgsrasteriterator.sip
%Include raster/qgsrasterlayer.sip

47
python/core/qgserror.sip Normal file
View File

@ -0,0 +1,47 @@
class QgsErrorMessage
{
%TypeHeaderCode
#include <qgserror.h>
%End
public:
enum Format
{
Text, // Plain text
Html
};
QgsErrorMessage();
QgsErrorMessage( const QString & theMessage, const QString & theTag = QString::null, const QString & theFile = QString::null, const QString & theFunction = QString::null, int theLine = 0 );
QString message() const;
QString tag() const;
QString file() const;
QString function() const;
int line() const;
};
class QgsError
{
%TypeHeaderCode
#include <qgserror.h>
%End
public:
QgsError();
QgsError( const QString & theMessage, const QString & theTag );
void append( const QString & theMessage, const QString & theTag );
void append( const QgsErrorMessage & theMessage );
bool isEmpty() const;
QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;
QString summary() const;
void clear();
};

View File

@ -11,6 +11,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
%TypeHeaderCode
#include <qgsrasterdataprovider.h>
#include <qgsrasterinterface.h>
#include <qgsrasteridentifyresult.h>
%End
public:
@ -193,7 +194,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
*/
virtual QString metadata() = 0;
virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
QMap<QString, QString> identify( const QgsPoint & thePoint, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );

View File

@ -0,0 +1,32 @@
class QgsRasterIdentifyResult
{
%TypeHeaderCode
#include <qgsrasteridentifyresult.h>
%End
public:
QgsRasterIdentifyResult();
QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormat theFormat, QMap<int, QVariant> theResults );
QgsRasterIdentifyResult( QgsError theError );
virtual ~QgsRasterIdentifyResult();
bool isValid() const;
QgsRasterDataProvider::IdentifyFormat format() const;
QMap<int, QVariant> results() const;
void setParams( const QMap<QString, QVariant> & theParams );
QMap<QString, QVariant> params() const;
QgsError error() const;
void setError( const QgsError & theError );
void appendError( const QgsErrorMessage & theMessage );
};

View File

@ -37,6 +37,7 @@
#include "qgsproject.h"
#include "qgsrasterbandstats.h"
#include "qgsrasterhistogramwidget.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterlayer.h"
#include "qgsrasterlayerproperties.h"
#include "qgsrasterpyramid.h"
@ -1456,7 +1457,7 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPoint& canvasPoint )
int myWidth = mMapCanvas->extent().width() / mapUnitsPerPixel;
int myHeight = mMapCanvas->extent().height() / mapUnitsPerPixel;
QMap<int, QVariant> myPixelMap = mRasterLayer->dataProvider()->identify( myPoint, QgsRasterDataProvider::IdentifyFormatValue, myExtent, myWidth, myHeight );
QMap<int, QVariant> myPixelMap = mRasterLayer->dataProvider()->identify( myPoint, QgsRasterDataProvider::IdentifyFormatValue, myExtent, myWidth, myHeight ).results();
QList<int> bands = renderer->usesBands();

View File

@ -190,6 +190,7 @@ SET(QGIS_CORE_SRCS
raster/qgspseudocolorshader.cpp
raster/qgsrasterprojector.cpp
raster/qgsrasterchecker.cpp
raster/qgsrasteridentifyresult.cpp
raster/qgsrasterinterface.cpp
raster/qgsrasteriterator.cpp
raster/qgsrasterlayer.cpp
@ -470,6 +471,7 @@ SET(QGIS_CORE_HDRS
raster/qgsrasterpyramid.h
raster/qgsrasterbandstats.h
raster/qgsrasterhistogram.h
raster/qgsrasteridentifyresult.h
raster/qgsrasterinterface.h
raster/qgsrasterlayer.h
raster/qgsrastertransparency.h

View File

@ -17,6 +17,7 @@
#include "qgsproviderregistry.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterprojector.h"
#include "qgslogger.h"
@ -27,6 +28,9 @@
#include <qmath.h>
#define ERRMSG(message) QGS_ERROR_MESSAGE(message, "Raster provider")
#define ERR(message) QgsError(message, "Raster provider")
void QgsRasterDataProvider::setUseSrcNoDataValue( int bandNo, bool use )
{
if ( mUseSrcNoDataValue.size() < bandNo )
@ -265,7 +269,8 @@ QString QgsRasterDataProvider::metadata()
}
// Default implementation for values
QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
//QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
QgsDebugMsg( "Entered" );
QMap<int, QVariant> results;
@ -273,7 +278,7 @@ QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint,
if ( theFormat != IdentifyFormatValue || !( capabilities() & IdentifyValue ) )
{
QgsDebugMsg( "Format not supported" );
return results;
return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) );
}
if ( !extent().contains( thePoint ) )
@ -283,7 +288,7 @@ QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint,
{
results.insert( bandNo, noDataValue( bandNo ) );
}
return results;
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
}
QgsRectangle myExtent = theExtent;
@ -320,7 +325,7 @@ QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint,
results.insert( i, value );
}
return results;
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
}
QMap<QString, QString> QgsRasterDataProvider::identify( const QgsPoint & thePoint, const QgsRectangle &theExtent, int theWidth, int theHeight )
@ -345,7 +350,8 @@ QMap<QString, QString> QgsRasterDataProvider::identify( const QgsPoint & thePoin
return results;
}
QMap<int, QVariant> myResults = identify( thePoint, identifyFormat, theExtent, theWidth, theHeight );
QgsRasterIdentifyResult myResult = identify( thePoint, identifyFormat, theExtent, theWidth, theHeight );
QMap<int, QVariant> myResults = myResult.results();
if ( identifyFormat == QgsRasterDataProvider::IdentifyFormatValue )
{

View File

@ -21,6 +21,7 @@
#define QGSRASTERDATAPROVIDER_H
#include <QDateTime>
#include <QVariant>
#include "qgslogger.h"
#include "qgsrectangle.h"
@ -39,9 +40,10 @@
#include <cmath>
class QImage;
class QgsPoint;
class QByteArray;
#include <QVariant>
class QgsPoint;
class QgsRasterIdentifyResult;
#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20
#define RASTER_HISTOGRAM_BINS 256
@ -344,9 +346,10 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
* IdentifyFormatHtml: map of HTML strings for each sublayer (WMS).
* Empty if failed or there are no results (TODO: better error reporting).
*/
virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
//virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
// TODO: remove in 2.0
QMap<QString, QString> identify( const QgsPoint & thePoint, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
/**

View File

@ -0,0 +1,47 @@
/***************************************************************************
qgsrasteridentifyresult.cpp
--------------------------------------
Date : Apr 8, 2013
Copyright : (C) 2013 by Radim Blazek
email : radim dot blazek at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
//#include <QTime>
#include "qgis.h"
#include "qgslogger.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterdataprovider.h"
QgsRasterIdentifyResult::QgsRasterIdentifyResult()
: mValid(false)
, mFormat(QgsRasterDataProvider::IdentifyFormatUndefined)
{
}
QgsRasterIdentifyResult::QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormat theFormat, QMap<int, QVariant> theResults )
: mValid(true)
, mFormat(theFormat)
, mResults(theResults)
{
}
QgsRasterIdentifyResult::QgsRasterIdentifyResult( QgsError theError )
: mValid(false)
, mFormat(QgsRasterDataProvider::IdentifyFormatUndefined)
, mError(theError)
{
}
QgsRasterIdentifyResult::~QgsRasterIdentifyResult()
{
}

View File

@ -0,0 +1,94 @@
/***************************************************************************
qgsrasteridentifyresult.h
--------------------------------------
Date : Apr 8, 2013
Copyright : (C) 2013 by Radim Blazek
email : radim dot blazek at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSRASTERIDENTIFYRESULT_H
#define QGSRASTERIDENTIFYRESULT_H
#include "qgis.h"
#include "qgslogger.h"
#include "qgsrasterdataprovider.h"
/** \ingroup core
* Raster identify results container.
*/
class CORE_EXPORT QgsRasterIdentifyResult
{
public:
QgsRasterIdentifyResult();
/** \brief Constructor. Creates valid result.
* @param theResults results
*/
QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormat theFormat, QMap<int, QVariant> theResults );
/** \brief Constructor. Creates invalid result with error.
* @param theResults results
*/
QgsRasterIdentifyResult( QgsError theError );
virtual ~QgsRasterIdentifyResult();
/** \brief Returns true if valid */
bool isValid() const { return mValid; }
/** \brief Get results format */
QgsRasterDataProvider::IdentifyFormat format() const { return mFormat; }
/** \brief Get results. Results are different for each format:
* IdentifyFormatValue: map of values for each band, keys are band numbers (from 1).
* IdentifyFormatFeature: map of QgsRasterFeatureList for each sublayer (WMS)
* IdentifyFormatHtml: map of HTML strings for each sublayer (WMS).
*/
QMap<int, QVariant> results() const { return mResults; }
/** Set map of optional parameters */
void setParams( const QMap<QString, QVariant> & theParams ) { mParams = theParams; }
/** Get map of optional parameters */
QMap<QString, QVariant> params() const { return mParams; }
/** \brief Get error */
QgsError error() const { return mError; }
/** \brief Set error */
void setError( const QgsError & theError ) { mError = theError;}
/** \brief Add error message */
void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
private:
/** \brief Is valid */
bool mValid;
/** \brief Results format */
QgsRasterDataProvider::IdentifyFormat mFormat;
/** \brief Results */
// TODO: better hierarchy (sublayer multiple feature sets)?
// TODO?: results are not consistent for different formats (per band x per sublayer)
QMap<int, QVariant> mResults;
/** \brief Additional params (e.g. request url used by WMS) */
QMap<QString, QVariant> mParams;
/** \brief Error */
QgsError mError;
};
#endif

View File

@ -26,6 +26,7 @@
#include "qgsmessageviewer.h"
#include "qgsmaplayer.h"
#include "qgsrasterlayer.h"
#include "qgsrasteridentifyresult.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
@ -392,7 +393,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
if ( mCanvas->hasCrsTransformEnabled() && dprovider->crs() != mCanvas->mapRenderer()->destinationCrs() )
{
viewExtent = toLayerCoordinates( layer, viewExtent );
values = dprovider->identify( point, format );
values = dprovider->identify( point, format ).results();
}
else
{
@ -415,7 +416,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( width ).arg( height ) );
QgsDebugMsg( QString( "xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.width() / width ).arg( viewExtent.height() / height ).arg( mapUnitsPerPixel ) );
values = dprovider->identify( point, format, viewExtent, width, height );
values = dprovider->identify( point, format, viewExtent, width, height ).results();
}
derivedAttributes.insert( tr( "(clicked coordinate)" ), point.toString() );

View File

@ -29,6 +29,7 @@
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsrasterbandstats.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterlayer.h"
#include "qgsrasterpyramid.h"
@ -52,7 +53,8 @@
#include "cpl_conv.h"
#include "cpl_string.h"
#define ERR(message) QGS_ERROR_MESSAGE(message,"GDAL provider")
#define ERRMSG(message) QGS_ERROR_MESSAGE(message,"GDAL provider")
#define ERR(message) QgsError(message,"GDAL provider")
static QString PROVIDER_KEY = "gdal";
static QString PROVIDER_DESCRIPTION = "GDAL provider";
@ -142,7 +144,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri, bool update )
if ( !mGdalBaseDataset )
{
QString msg = QString( "Cannot open GDAL dataset %1:\n%2" ).arg( dataSourceUri() ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
appendError( ERR( msg ) );
appendError( ERRMSG( msg ) );
return;
}
@ -867,13 +869,16 @@ int QgsGdalProvider::yBlockSize() const
int QgsGdalProvider::xSize() const { return mWidth; }
int QgsGdalProvider::ySize() const { return mHeight; }
QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) );
QMap<int, QVariant> results;
if ( theFormat != IdentifyFormatValue ) return results;
if ( theFormat != IdentifyFormatValue )
{
return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) );
}
if ( !extent().contains( thePoint ) )
{
@ -882,7 +887,7 @@ QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, Identi
{
results.insert( bandNo, noDataValue( bandNo ) );
}
return results;
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
}
QgsRectangle myExtent = theExtent;
@ -945,15 +950,14 @@ QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, Identi
if ( !myBlock )
{
results.clear();
return results;
return QgsRasterIdentifyResult( ERR( tr( "Cannot read data" ) ) );
}
double value = myBlock->value( r, c );
results.insert( i, value );
}
return results;
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
}
int QgsGdalProvider::capabilities() const
@ -2313,7 +2317,7 @@ void QgsGdalProvider::initBaseDataset()
// if there are no subdatasets, then close the dataset
if ( mSubLayers.size() == 0 )
{
appendError( ERR( tr( "Cannot get GDAL raster band: %1" ).arg( msg ) ) );
appendError( ERRMSG( tr( "Cannot get GDAL raster band: %1" ).arg( msg ) ) );
GDALDereferenceDataset( mGdalBaseDataset );
mGdalBaseDataset = NULL;

View File

@ -124,7 +124,7 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
*/
bool isValid();
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
/**
* \brief Returns the caption error text for the last error in this provider

View File

@ -19,6 +19,7 @@
#include "qgslogger.h"
#include "qgsgrass.h"
#include "qgsrasteridentifyresult.h"
#include "qgsgrassrasterprovider.h"
#include "qgsconfig.h"
@ -39,6 +40,7 @@
#include <QHash>
#define ERR(message) QGS_ERROR_MESSAGE(message,"GRASS provider")
#define ERROR(message) QgsError(message,"GRASS provider")
static QString PROVIDER_KEY = "grassraster";
static QString PROVIDER_DESCRIPTION = "GRASS raster provider";
@ -432,7 +434,7 @@ int QgsGrassRasterProvider::yBlockSize() const
int QgsGrassRasterProvider::xSize() const { return mCols; }
int QgsGrassRasterProvider::ySize() const { return mRows; }
QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
QgsRasterIdentifyResult QgsGrassRasterProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
Q_UNUSED( theExtent );
Q_UNUSED( theWidth );
@ -440,12 +442,15 @@ QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint,
QgsDebugMsg( "Entered" );
QMap<int, QVariant> results;
if ( theFormat != IdentifyFormatValue ) return results;
if ( theFormat != IdentifyFormatValue )
{
return QgsRasterIdentifyResult( ERROR( tr( "Format not supported" ) ) );
}
if ( !extent().contains( thePoint ) )
{
results.insert( 1, noDataValue( 1 ) );
return results;
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
}
// TODO: use doubles instead of strings
@ -455,7 +460,10 @@ QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint,
bool ok;
double value = mRasterValue.value( thePoint.x(), thePoint.y(), &ok );
if ( !ok ) return results;
if ( !ok )
{
return QgsRasterIdentifyResult( ERROR( tr( "Cannot read data" ) ) );
}
if ( qIsNaN( value ) ) value = noDataValue( 1 );
@ -468,7 +476,7 @@ QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint,
results.insert( 1, value );
return results;
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
}
int QgsGrassRasterProvider::capabilities() const

View File

@ -141,7 +141,7 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
*/
bool isValid();
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
/**
* \brief Returns the caption error text for the last error in this provider

View File

@ -28,6 +28,7 @@
#include "qgswcsprovider.h"
#include "qgscoordinatetransform.h"
#include "qgsdatasourceuri.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterlayer.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
@ -71,6 +72,7 @@
#define ERR(message) QGS_ERROR_MESSAGE(message,"WCS provider")
#define SRVERR(message) QGS_ERROR_MESSAGE(message,"WCS server")
#define ERROR(message) QgsError(message,"WCS provider")
static QString WCS_KEY = "wcs";
static QString WCS_DESCRIPTION = "OGC Web Coverage Service version 1.0/1.1 data provider";
@ -1593,14 +1595,17 @@ QString QgsWcsProvider:: htmlRow( const QString &text1, const QString &text2 )
return "<tr>" + htmlCell( text1 ) + htmlCell( text2 ) + "</tr>";
}
QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
QgsRasterIdentifyResult QgsWcsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) );
QgsDebugMsg( QString( "theWidth = %1 theHeight = %2" ).arg( theWidth ).arg( theHeight ) );
QgsDebugMsg( "theExtent = " + theExtent.toString() );
QMap<int, QVariant> results;
if ( theFormat != IdentifyFormatValue ) return results;
if ( theFormat != IdentifyFormatValue )
{
return QgsRasterIdentifyResult( ERROR( tr( "Format not supported" ) ) );
}
if ( !extent().contains( thePoint ) )
{
@ -1609,7 +1614,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
{
results.insert( i, noDataValue( i ) );
}
return results;
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
}
QgsRectangle myExtent = theExtent;
@ -1659,7 +1664,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
if ( !mCachedGdalDataset ||
!mCachedViewExtent.contains( thePoint ) )
{
return results; // should not happen
return QgsRasterIdentifyResult( ERROR( tr( "Read data error" ) ) );
}
double x = thePoint.x();
@ -1686,8 +1691,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
if ( err != CPLE_None )
{
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
results.clear();
return results;
return QgsRasterIdentifyResult( ERROR( tr( "RasterIO error: " ) + QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
}
// Apply user no data
@ -1700,7 +1704,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
results.insert( i, value );
}
return results;
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
}
QgsCoordinateReferenceSystem QgsWcsProvider::crs()

View File

@ -146,7 +146,7 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
int xSize() const;
int ySize() const;
QString metadata();
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
QString lastErrorTitle();
QString lastError();
QString lastErrorFormat();

View File

@ -30,6 +30,7 @@
#include "qgscoordinatetransform.h"
#include "qgsdatasourceuri.h"
#include "qgsfeaturestore.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterlayer.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
@ -72,6 +73,7 @@
#define ERR(message) QGS_ERROR_MESSAGE(message,"WMS provider")
#define SRVERR(message) QGS_ERROR_MESSAGE(message,"WMS server")
#define ERROR(message) QgsError(message,"WMS provider")
static QString WMS_KEY = "wms";
static QString WMS_DESCRIPTION = "OGC Web Map Service version 1.3 data provider";
@ -3871,7 +3873,7 @@ QString QgsWmsProvider::metadata()
return metadata;
}
QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
QgsDebugMsg( QString( "theFormat = %1" ).arg( theFormat ) );
QStringList resultStrings;
@ -3879,14 +3881,17 @@ QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, Identif
QString format;
format = mIdentifyFormats.value( theFormat );
if ( format.isEmpty() ) return results;
if ( format.isEmpty() )
{
return QgsRasterIdentifyResult( ERROR( tr( "Format not supported" ) ) );
}
QgsDebugMsg( QString( "theFormat = %1 format = %2" ).arg( theFormat ).arg( format ) );
if ( !extent().contains( thePoint ) )
{
results.insert( 1, "" );
return results;
return QgsRasterIdentifyResult( theFormat, results );
}
QgsRectangle myExtent = theExtent;
@ -4252,7 +4257,7 @@ QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, Identif
}
#endif
return results;
return QgsRasterIdentifyResult( theFormat, results );
}
void QgsWmsProvider::identifyReplyFinished()

View File

@ -656,7 +656,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
*/
QString metadata();
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
/**
* \brief Returns the caption error text for the last error in this provider