Skip to content

Commit a3de4c4

Browse files
committed
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+

0 commit comments

Comments
 (0)