Skip to content

Commit a3de4c4

Browse files
committedApr 8, 2013
Added QgsRasterIdentifyResult
1 parent 51fc960 commit a3de4c4

19 files changed

+299
-42
lines changed
 

‎python/core/core.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
%Include qgsdatasourceuri.sip
2525
%Include qgsdbfilterproxymodel.sip
2626
%Include qgsdistancearea.sip
27+
%Include qgserror.sip
2728
%Include qgsexpression.sip
2829
%Include qgsfeature.sip
2930
%Include qgsfeatureiterator.sip
@@ -141,6 +142,7 @@
141142
%Include raster/qgsrasterdataprovider.sip
142143
%Include raster/qgsrasterfilewriter.sip
143144
%Include raster/qgsrasterhistogram.sip
145+
%Include raster/qgsrasteridentifyresult.sip
144146
%Include raster/qgsrasterinterface.sip
145147
%Include raster/qgsrasteriterator.sip
146148
%Include raster/qgsrasterlayer.sip

‎python/core/qgserror.sip

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class QgsErrorMessage
2+
{
3+
%TypeHeaderCode
4+
#include <qgserror.h>
5+
%End
6+
public:
7+
enum Format
8+
{
9+
Text, // Plain text
10+
Html
11+
};
12+
13+
QgsErrorMessage();
14+
15+
QgsErrorMessage( const QString & theMessage, const QString & theTag = QString::null, const QString & theFile = QString::null, const QString & theFunction = QString::null, int theLine = 0 );
16+
17+
QString message() const;
18+
QString tag() const;
19+
QString file() const;
20+
QString function() const;
21+
int line() const;
22+
};
23+
24+
class QgsError
25+
{
26+
%TypeHeaderCode
27+
#include <qgserror.h>
28+
%End
29+
public:
30+
31+
QgsError();
32+
33+
QgsError( const QString & theMessage, const QString & theTag );
34+
35+
void append( const QString & theMessage, const QString & theTag );
36+
37+
void append( const QgsErrorMessage & theMessage );
38+
39+
bool isEmpty() const;
40+
41+
QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;
42+
43+
QString summary() const;
44+
45+
void clear();
46+
};
47+

‎python/core/raster/qgsrasterdataprovider.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
1111
%TypeHeaderCode
1212
#include <qgsrasterdataprovider.h>
1313
#include <qgsrasterinterface.h>
14+
#include <qgsrasteridentifyresult.h>
1415
%End
1516

1617
public:
@@ -193,7 +194,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
193194
*/
194195
virtual QString metadata() = 0;
195196

196-
virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
197+
virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
197198

198199
QMap<QString, QString> identify( const QgsPoint & thePoint, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
199200

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class QgsRasterIdentifyResult
2+
{
3+
%TypeHeaderCode
4+
#include <qgsrasteridentifyresult.h>
5+
%End
6+
public:
7+
QgsRasterIdentifyResult();
8+
9+
QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormat theFormat, QMap<int, QVariant> theResults );
10+
11+
QgsRasterIdentifyResult( QgsError theError );
12+
13+
virtual ~QgsRasterIdentifyResult();
14+
15+
bool isValid() const;
16+
17+
QgsRasterDataProvider::IdentifyFormat format() const;
18+
19+
QMap<int, QVariant> results() const;
20+
21+
void setParams( const QMap<QString, QVariant> & theParams );
22+
23+
QMap<QString, QVariant> params() const;
24+
25+
QgsError error() const;
26+
27+
void setError( const QgsError & theError );
28+
29+
void appendError( const QgsErrorMessage & theMessage );
30+
31+
};
32+

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "qgsproject.h"
3838
#include "qgsrasterbandstats.h"
3939
#include "qgsrasterhistogramwidget.h"
40+
#include "qgsrasteridentifyresult.h"
4041
#include "qgsrasterlayer.h"
4142
#include "qgsrasterlayerproperties.h"
4243
#include "qgsrasterpyramid.h"
@@ -1456,7 +1457,7 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPoint& canvasPoint )
14561457
int myWidth = mMapCanvas->extent().width() / mapUnitsPerPixel;
14571458
int myHeight = mMapCanvas->extent().height() / mapUnitsPerPixel;
14581459

1459-
QMap<int, QVariant> myPixelMap = mRasterLayer->dataProvider()->identify( myPoint, QgsRasterDataProvider::IdentifyFormatValue, myExtent, myWidth, myHeight );
1460+
QMap<int, QVariant> myPixelMap = mRasterLayer->dataProvider()->identify( myPoint, QgsRasterDataProvider::IdentifyFormatValue, myExtent, myWidth, myHeight ).results();
14601461

14611462
QList<int> bands = renderer->usesBands();
14621463

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ SET(QGIS_CORE_SRCS
190190
raster/qgspseudocolorshader.cpp
191191
raster/qgsrasterprojector.cpp
192192
raster/qgsrasterchecker.cpp
193+
raster/qgsrasteridentifyresult.cpp
193194
raster/qgsrasterinterface.cpp
194195
raster/qgsrasteriterator.cpp
195196
raster/qgsrasterlayer.cpp
@@ -470,6 +471,7 @@ SET(QGIS_CORE_HDRS
470471
raster/qgsrasterpyramid.h
471472
raster/qgsrasterbandstats.h
472473
raster/qgsrasterhistogram.h
474+
raster/qgsrasteridentifyresult.h
473475
raster/qgsrasterinterface.h
474476
raster/qgsrasterlayer.h
475477
raster/qgsrastertransparency.h

‎src/core/raster/qgsrasterdataprovider.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgsproviderregistry.h"
1919
#include "qgsrasterdataprovider.h"
20+
#include "qgsrasteridentifyresult.h"
2021
#include "qgsrasterprojector.h"
2122
#include "qgslogger.h"
2223

@@ -27,6 +28,9 @@
2728

2829
#include <qmath.h>
2930

31+
#define ERRMSG(message) QGS_ERROR_MESSAGE(message, "Raster provider")
32+
#define ERR(message) QgsError(message, "Raster provider")
33+
3034
void QgsRasterDataProvider::setUseSrcNoDataValue( int bandNo, bool use )
3135
{
3236
if ( mUseSrcNoDataValue.size() < bandNo )
@@ -265,15 +269,16 @@ QString QgsRasterDataProvider::metadata()
265269
}
266270

267271
// Default implementation for values
268-
QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
272+
//QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
273+
QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
269274
{
270275
QgsDebugMsg( "Entered" );
271276
QMap<int, QVariant> results;
272277

273278
if ( theFormat != IdentifyFormatValue || !( capabilities() & IdentifyValue ) )
274279
{
275280
QgsDebugMsg( "Format not supported" );
276-
return results;
281+
return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) );
277282
}
278283

279284
if ( !extent().contains( thePoint ) )
@@ -283,7 +288,7 @@ QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint,
283288
{
284289
results.insert( bandNo, noDataValue( bandNo ) );
285290
}
286-
return results;
291+
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
287292
}
288293

289294
QgsRectangle myExtent = theExtent;
@@ -320,7 +325,7 @@ QMap<int, QVariant> QgsRasterDataProvider::identify( const QgsPoint & thePoint,
320325

321326
results.insert( i, value );
322327
}
323-
return results;
328+
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
324329
}
325330

326331
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
345350
return results;
346351
}
347352

348-
QMap<int, QVariant> myResults = identify( thePoint, identifyFormat, theExtent, theWidth, theHeight );
353+
QgsRasterIdentifyResult myResult = identify( thePoint, identifyFormat, theExtent, theWidth, theHeight );
354+
QMap<int, QVariant> myResults = myResult.results();
349355

350356
if ( identifyFormat == QgsRasterDataProvider::IdentifyFormatValue )
351357
{

‎src/core/raster/qgsrasterdataprovider.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define QGSRASTERDATAPROVIDER_H
2222

2323
#include <QDateTime>
24+
#include <QVariant>
2425

2526
#include "qgslogger.h"
2627
#include "qgsrectangle.h"
@@ -39,9 +40,10 @@
3940
#include <cmath>
4041

4142
class QImage;
42-
class QgsPoint;
4343
class QByteArray;
44-
#include <QVariant>
44+
45+
class QgsPoint;
46+
class QgsRasterIdentifyResult;
4547

4648
#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20
4749
#define RASTER_HISTOGRAM_BINS 256
@@ -344,9 +346,10 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
344346
* IdentifyFormatHtml: map of HTML strings for each sublayer (WMS).
345347
* Empty if failed or there are no results (TODO: better error reporting).
346348
*/
347-
virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
348-
349+
//virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
350+
virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
349351

352+
// TODO: remove in 2.0
350353
QMap<QString, QString> identify( const QgsPoint & thePoint, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
351354

352355
/**
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
qgsrasteridentifyresult.cpp
3+
--------------------------------------
4+
Date : Apr 8, 2013
5+
Copyright : (C) 2013 by Radim Blazek
6+
email : radim dot blazek at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
//#include <QTime>
19+
20+
#include "qgis.h"
21+
#include "qgslogger.h"
22+
#include "qgsrasteridentifyresult.h"
23+
#include "qgsrasterdataprovider.h"
24+
25+
QgsRasterIdentifyResult::QgsRasterIdentifyResult()
26+
: mValid(false)
27+
, mFormat(QgsRasterDataProvider::IdentifyFormatUndefined)
28+
{
29+
}
30+
31+
QgsRasterIdentifyResult::QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormat theFormat, QMap<int, QVariant> theResults )
32+
: mValid(true)
33+
, mFormat(theFormat)
34+
, mResults(theResults)
35+
{
36+
}
37+
38+
QgsRasterIdentifyResult::QgsRasterIdentifyResult( QgsError theError )
39+
: mValid(false)
40+
, mFormat(QgsRasterDataProvider::IdentifyFormatUndefined)
41+
, mError(theError)
42+
{
43+
}
44+
45+
QgsRasterIdentifyResult::~QgsRasterIdentifyResult()
46+
{
47+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/***************************************************************************
2+
qgsrasteridentifyresult.h
3+
--------------------------------------
4+
Date : Apr 8, 2013
5+
Copyright : (C) 2013 by Radim Blazek
6+
email : radim dot blazek at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSRASTERIDENTIFYRESULT_H
19+
#define QGSRASTERIDENTIFYRESULT_H
20+
21+
#include "qgis.h"
22+
#include "qgslogger.h"
23+
#include "qgsrasterdataprovider.h"
24+
25+
/** \ingroup core
26+
* Raster identify results container.
27+
*/
28+
class CORE_EXPORT QgsRasterIdentifyResult
29+
{
30+
public:
31+
QgsRasterIdentifyResult();
32+
33+
/** \brief Constructor. Creates valid result.
34+
* @param theResults results
35+
*/
36+
QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormat theFormat, QMap<int, QVariant> theResults );
37+
38+
/** \brief Constructor. Creates invalid result with error.
39+
* @param theResults results
40+
*/
41+
QgsRasterIdentifyResult( QgsError theError );
42+
43+
virtual ~QgsRasterIdentifyResult();
44+
45+
/** \brief Returns true if valid */
46+
bool isValid() const { return mValid; }
47+
48+
/** \brief Get results format */
49+
QgsRasterDataProvider::IdentifyFormat format() const { return mFormat; }
50+
51+
/** \brief Get results. Results are different for each format:
52+
* IdentifyFormatValue: map of values for each band, keys are band numbers (from 1).
53+
* IdentifyFormatFeature: map of QgsRasterFeatureList for each sublayer (WMS)
54+
* IdentifyFormatHtml: map of HTML strings for each sublayer (WMS).
55+
*/
56+
QMap<int, QVariant> results() const { return mResults; }
57+
58+
/** Set map of optional parameters */
59+
void setParams( const QMap<QString, QVariant> & theParams ) { mParams = theParams; }
60+
61+
/** Get map of optional parameters */
62+
QMap<QString, QVariant> params() const { return mParams; }
63+
64+
/** \brief Get error */
65+
QgsError error() const { return mError; }
66+
67+
/** \brief Set error */
68+
void setError( const QgsError & theError ) { mError = theError;}
69+
70+
/** \brief Add error message */
71+
void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
72+
73+
private:
74+
/** \brief Is valid */
75+
bool mValid;
76+
77+
/** \brief Results format */
78+
QgsRasterDataProvider::IdentifyFormat mFormat;
79+
80+
/** \brief Results */
81+
// TODO: better hierarchy (sublayer multiple feature sets)?
82+
// TODO?: results are not consistent for different formats (per band x per sublayer)
83+
QMap<int, QVariant> mResults;
84+
85+
/** \brief Additional params (e.g. request url used by WMS) */
86+
QMap<QString, QVariant> mParams;
87+
88+
/** \brief Error */
89+
QgsError mError;
90+
};
91+
92+
#endif
93+
94+

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsmessageviewer.h"
2727
#include "qgsmaplayer.h"
2828
#include "qgsrasterlayer.h"
29+
#include "qgsrasteridentifyresult.h"
2930
#include "qgscoordinatereferencesystem.h"
3031
#include "qgsvectordataprovider.h"
3132
#include "qgsvectorlayer.h"
@@ -392,7 +393,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
392393
if ( mCanvas->hasCrsTransformEnabled() && dprovider->crs() != mCanvas->mapRenderer()->destinationCrs() )
393394
{
394395
viewExtent = toLayerCoordinates( layer, viewExtent );
395-
values = dprovider->identify( point, format );
396+
values = dprovider->identify( point, format ).results();
396397
}
397398
else
398399
{
@@ -415,7 +416,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
415416
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( width ).arg( height ) );
416417
QgsDebugMsg( QString( "xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.width() / width ).arg( viewExtent.height() / height ).arg( mapUnitsPerPixel ) );
417418

418-
values = dprovider->identify( point, format, viewExtent, width, height );
419+
values = dprovider->identify( point, format, viewExtent, width, height ).results();
419420
}
420421

421422
derivedAttributes.insert( tr( "(clicked coordinate)" ), point.toString() );

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgsrectangle.h"
3030
#include "qgscoordinatereferencesystem.h"
3131
#include "qgsrasterbandstats.h"
32+
#include "qgsrasteridentifyresult.h"
3233
#include "qgsrasterlayer.h"
3334
#include "qgsrasterpyramid.h"
3435

@@ -52,7 +53,8 @@
5253
#include "cpl_conv.h"
5354
#include "cpl_string.h"
5455

55-
#define ERR(message) QGS_ERROR_MESSAGE(message,"GDAL provider")
56+
#define ERRMSG(message) QGS_ERROR_MESSAGE(message,"GDAL provider")
57+
#define ERR(message) QgsError(message,"GDAL provider")
5658

5759
static QString PROVIDER_KEY = "gdal";
5860
static QString PROVIDER_DESCRIPTION = "GDAL provider";
@@ -142,7 +144,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri, bool update )
142144
if ( !mGdalBaseDataset )
143145
{
144146
QString msg = QString( "Cannot open GDAL dataset %1:\n%2" ).arg( dataSourceUri() ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
145-
appendError( ERR( msg ) );
147+
appendError( ERRMSG( msg ) );
146148
return;
147149
}
148150

@@ -867,13 +869,16 @@ int QgsGdalProvider::yBlockSize() const
867869
int QgsGdalProvider::xSize() const { return mWidth; }
868870
int QgsGdalProvider::ySize() const { return mHeight; }
869871

870-
QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
872+
QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
871873
{
872874
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) );
873875

874876
QMap<int, QVariant> results;
875877

876-
if ( theFormat != IdentifyFormatValue ) return results;
878+
if ( theFormat != IdentifyFormatValue )
879+
{
880+
return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) );
881+
}
877882

878883
if ( !extent().contains( thePoint ) )
879884
{
@@ -882,7 +887,7 @@ QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, Identi
882887
{
883888
results.insert( bandNo, noDataValue( bandNo ) );
884889
}
885-
return results;
890+
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
886891
}
887892

888893
QgsRectangle myExtent = theExtent;
@@ -945,15 +950,14 @@ QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, Identi
945950

946951
if ( !myBlock )
947952
{
948-
results.clear();
949-
return results;
953+
return QgsRasterIdentifyResult( ERR( tr( "Cannot read data" ) ) );
950954
}
951955

952956
double value = myBlock->value( r, c );
953957

954958
results.insert( i, value );
955959
}
956-
return results;
960+
return QgsRasterIdentifyResult( QgsRasterDataProvider::IdentifyFormatValue, results );
957961
}
958962

959963
int QgsGdalProvider::capabilities() const
@@ -2313,7 +2317,7 @@ void QgsGdalProvider::initBaseDataset()
23132317
// if there are no subdatasets, then close the dataset
23142318
if ( mSubLayers.size() == 0 )
23152319
{
2316-
appendError( ERR( tr( "Cannot get GDAL raster band: %1" ).arg( msg ) ) );
2320+
appendError( ERRMSG( tr( "Cannot get GDAL raster band: %1" ).arg( msg ) ) );
23172321

23182322
GDALDereferenceDataset( mGdalBaseDataset );
23192323
mGdalBaseDataset = NULL;

‎src/providers/gdal/qgsgdalprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class QgsGdalProvider : public QgsRasterDataProvider, QgsGdalProviderBase
124124
*/
125125
bool isValid();
126126

127-
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
127+
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
128128

129129
/**
130130
* \brief Returns the caption error text for the last error in this provider

‎src/providers/grass/qgsgrassrasterprovider.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "qgslogger.h"
2121
#include "qgsgrass.h"
22+
#include "qgsrasteridentifyresult.h"
2223
#include "qgsgrassrasterprovider.h"
2324
#include "qgsconfig.h"
2425

@@ -39,6 +40,7 @@
3940
#include <QHash>
4041

4142
#define ERR(message) QGS_ERROR_MESSAGE(message,"GRASS provider")
43+
#define ERROR(message) QgsError(message,"GRASS provider")
4244

4345
static QString PROVIDER_KEY = "grassraster";
4446
static QString PROVIDER_DESCRIPTION = "GRASS raster provider";
@@ -432,20 +434,23 @@ int QgsGrassRasterProvider::yBlockSize() const
432434
int QgsGrassRasterProvider::xSize() const { return mCols; }
433435
int QgsGrassRasterProvider::ySize() const { return mRows; }
434436

435-
QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
437+
QgsRasterIdentifyResult QgsGrassRasterProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
436438
{
437439
Q_UNUSED( theExtent );
438440
Q_UNUSED( theWidth );
439441
Q_UNUSED( theHeight );
440442
QgsDebugMsg( "Entered" );
441443
QMap<int, QVariant> results;
442444

443-
if ( theFormat != IdentifyFormatValue ) return results;
445+
if ( theFormat != IdentifyFormatValue )
446+
{
447+
return QgsRasterIdentifyResult( ERROR( tr( "Format not supported" ) ) );
448+
}
444449

445450
if ( !extent().contains( thePoint ) )
446451
{
447452
results.insert( 1, noDataValue( 1 ) );
448-
return results;
453+
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
449454
}
450455

451456
// TODO: use doubles instead of strings
@@ -455,7 +460,10 @@ QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint,
455460
bool ok;
456461
double value = mRasterValue.value( thePoint.x(), thePoint.y(), &ok );
457462

458-
if ( !ok ) return results;
463+
if ( !ok )
464+
{
465+
return QgsRasterIdentifyResult( ERROR( tr( "Cannot read data" ) ) );
466+
}
459467

460468
if ( qIsNaN( value ) ) value = noDataValue( 1 );
461469

@@ -468,7 +476,7 @@ QMap<int, QVariant> QgsGrassRasterProvider::identify( const QgsPoint & thePoint,
468476

469477
results.insert( 1, value );
470478

471-
return results;
479+
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
472480
}
473481

474482
int QgsGrassRasterProvider::capabilities() const

‎src/providers/grass/qgsgrassrasterprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
141141
*/
142142
bool isValid();
143143

144-
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
144+
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
145145

146146
/**
147147
* \brief Returns the caption error text for the last error in this provider

‎src/providers/wcs/qgswcsprovider.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgswcsprovider.h"
2929
#include "qgscoordinatetransform.h"
3030
#include "qgsdatasourceuri.h"
31+
#include "qgsrasteridentifyresult.h"
3132
#include "qgsrasterlayer.h"
3233
#include "qgsrectangle.h"
3334
#include "qgscoordinatereferencesystem.h"
@@ -71,6 +72,7 @@
7172

7273
#define ERR(message) QGS_ERROR_MESSAGE(message,"WCS provider")
7374
#define SRVERR(message) QGS_ERROR_MESSAGE(message,"WCS server")
75+
#define ERROR(message) QgsError(message,"WCS provider")
7476

7577
static QString WCS_KEY = "wcs";
7678
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 )
15931595
return "<tr>" + htmlCell( text1 ) + htmlCell( text2 ) + "</tr>";
15941596
}
15951597

1596-
QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
1598+
QgsRasterIdentifyResult QgsWcsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
15971599
{
15981600
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) );
15991601
QgsDebugMsg( QString( "theWidth = %1 theHeight = %2" ).arg( theWidth ).arg( theHeight ) );
16001602
QgsDebugMsg( "theExtent = " + theExtent.toString() );
16011603
QMap<int, QVariant> results;
16021604

1603-
if ( theFormat != IdentifyFormatValue ) return results;
1605+
if ( theFormat != IdentifyFormatValue )
1606+
{
1607+
return QgsRasterIdentifyResult( ERROR( tr( "Format not supported" ) ) );
1608+
}
16041609

16051610
if ( !extent().contains( thePoint ) )
16061611
{
@@ -1609,7 +1614,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
16091614
{
16101615
results.insert( i, noDataValue( i ) );
16111616
}
1612-
return results;
1617+
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
16131618
}
16141619

16151620
QgsRectangle myExtent = theExtent;
@@ -1659,7 +1664,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
16591664
if ( !mCachedGdalDataset ||
16601665
!mCachedViewExtent.contains( thePoint ) )
16611666
{
1662-
return results; // should not happen
1667+
return QgsRasterIdentifyResult( ERROR( tr( "Read data error" ) ) );
16631668
}
16641669

16651670
double x = thePoint.x();
@@ -1686,8 +1691,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
16861691
if ( err != CPLE_None )
16871692
{
16881693
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
1689-
results.clear();
1690-
return results;
1694+
return QgsRasterIdentifyResult( ERROR( tr( "RasterIO error: " ) + QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
16911695
}
16921696

16931697
// Apply user no data
@@ -1700,7 +1704,7 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
17001704
results.insert( i, value );
17011705
}
17021706

1703-
return results;
1707+
return QgsRasterIdentifyResult( IdentifyFormatValue, results );
17041708
}
17051709

17061710
QgsCoordinateReferenceSystem QgsWcsProvider::crs()

‎src/providers/wcs/qgswcsprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
146146
int xSize() const;
147147
int ySize() const;
148148
QString metadata();
149-
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
149+
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
150150
QString lastErrorTitle();
151151
QString lastError();
152152
QString lastErrorFormat();

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgscoordinatetransform.h"
3131
#include "qgsdatasourceuri.h"
3232
#include "qgsfeaturestore.h"
33+
#include "qgsrasteridentifyresult.h"
3334
#include "qgsrasterlayer.h"
3435
#include "qgsrectangle.h"
3536
#include "qgscoordinatereferencesystem.h"
@@ -72,6 +73,7 @@
7273

7374
#define ERR(message) QGS_ERROR_MESSAGE(message,"WMS provider")
7475
#define SRVERR(message) QGS_ERROR_MESSAGE(message,"WMS server")
76+
#define ERROR(message) QgsError(message,"WMS provider")
7577

7678
static QString WMS_KEY = "wms";
7779
static QString WMS_DESCRIPTION = "OGC Web Map Service version 1.3 data provider";
@@ -3871,22 +3873,25 @@ QString QgsWmsProvider::metadata()
38713873
return metadata;
38723874
}
38733875

3874-
QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
3876+
QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
38753877
{
38763878
QgsDebugMsg( QString( "theFormat = %1" ).arg( theFormat ) );
38773879
QStringList resultStrings;
38783880
QMap<int, QVariant> results;
38793881

38803882
QString format;
38813883
format = mIdentifyFormats.value( theFormat );
3882-
if ( format.isEmpty() ) return results;
3884+
if ( format.isEmpty() )
3885+
{
3886+
return QgsRasterIdentifyResult( ERROR( tr( "Format not supported" ) ) );
3887+
}
38833888

38843889
QgsDebugMsg( QString( "theFormat = %1 format = %2" ).arg( theFormat ).arg( format ) );
38853890

38863891
if ( !extent().contains( thePoint ) )
38873892
{
38883893
results.insert( 1, "" );
3889-
return results;
3894+
return QgsRasterIdentifyResult( theFormat, results );
38903895
}
38913896

38923897
QgsRectangle myExtent = theExtent;
@@ -4252,7 +4257,7 @@ QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, Identif
42524257
}
42534258
#endif
42544259

4255-
return results;
4260+
return QgsRasterIdentifyResult( theFormat, results );
42564261
}
42574262

42584263
void QgsWmsProvider::identifyReplyFinished()

‎src/providers/wms/qgswmsprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
656656
*/
657657
QString metadata();
658658

659-
QMap<int, QVariant> identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
659+
QgsRasterIdentifyResult identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
660660

661661
/**
662662
* \brief Returns the caption error text for the last error in this provider

0 commit comments

Comments
 (0)
Please sign in to comment.