Skip to content
Permalink
Browse files

Added QgsRasterIdentifyResult

  • Loading branch information
blazek committed Apr 8, 2013
1 parent 51fc960 commit a3de4c4e0a15f8096d772bfc4d9677a57ca9eb0c
@@ -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
@@ -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();
};

@@ -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 );

@@ -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 );

};

@@ -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();

@@ -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
@@ -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,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 ) )
@@ -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 )
{
@@ -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 );

/**
@@ -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()
{
}
@@ -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.
You can’t perform that action at this time.