Skip to content

Commit

Permalink
Added QgsRasterIdentifyResult
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Apr 8, 2013
1 parent 51fc960 commit a3de4c4
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 42 deletions.
2 changes: 2 additions & 0 deletions python/core/core.sip
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions python/core/qgserror.sip
@@ -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();
};

3 changes: 2 additions & 1 deletion python/core/raster/qgsrasterdataprovider.sip
Expand Up @@ -11,6 +11,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
%TypeHeaderCode
#include <qgsrasterdataprovider.h>
#include <qgsrasterinterface.h>
#include <qgsrasteridentifyresult.h>
%End

public:
Expand Down Expand Up @@ -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 );

Expand Down
32 changes: 32 additions & 0 deletions python/core/raster/qgsrasteridentifyresult.sip
@@ -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 );

};

3 changes: 2 additions & 1 deletion src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/core/raster/qgsrasterdataprovider.cpp
Expand Up @@ -17,6 +17,7 @@

#include "qgsproviderregistry.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasteridentifyresult.h"
#include "qgsrasterprojector.h"
#include "qgslogger.h"

Expand All @@ -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 )
Expand Down Expand Up @@ -265,15 +269,16 @@ 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;

if ( theFormat != IdentifyFormatValue || !( capabilities() & IdentifyValue ) )
{
QgsDebugMsg( "Format not supported" );
return results;
return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) );
}

if ( !extent().contains( thePoint ) )
Expand All @@ -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;
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
{
Expand Down
11 changes: 7 additions & 4 deletions src/core/raster/qgsrasterdataprovider.h
Expand Up @@ -21,6 +21,7 @@
#define QGSRASTERDATAPROVIDER_H

#include <QDateTime>
#include <QVariant>

#include "qgslogger.h"
#include "qgsrectangle.h"
Expand All @@ -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
Expand Down Expand Up @@ -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 );

/**
Expand Down
47 changes: 47 additions & 0 deletions src/core/raster/qgsrasteridentifyresult.cpp
@@ -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()
{
}
94 changes: 94 additions & 0 deletions src/core/raster/qgsrasteridentifyresult.h
@@ -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


0 comments on commit a3de4c4

Please sign in to comment.