| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ); | ||
|
|
||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| class SilentProgress(): | ||
|
|
||
| def setText(self, text): | ||
| pass | ||
|
|
||
| def setPercentage(self, i): | ||
| pass | ||
|
|
||
| def setInfo(self, _): | ||
| pass | ||
|
|
||
| def setCommand(self, _): | ||
| pass | ||
|
|
||
| def setDebugInfo(self, _): | ||
| pass | ||
|
|
||
| def setConsoleInfo(self, _): | ||
| pass |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| ##[Test scripts]=group | ||
| ##number=output number | ||
| number = 10 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,18 @@ | ||
| import sextante | ||
| import unittest | ||
| from sextante.tests.TestData import points, points2, polygons, polygons2, lines, union,\ | ||
| table, polygonsGeoJson, raster | ||
| from sextante.core.QGisLayers import QGisLayers | ||
|
|
||
| class GeoAlgorithmTest(unittest.TestCase): | ||
| pass | ||
|
|
||
| def suite(): | ||
| suite = unittest.makeSuite(GeoAlgorithmTest, 'test') | ||
| return suite | ||
|
|
||
| def runtests(): | ||
| result = unittest.TestResult() | ||
| testsuite = suite() | ||
| testsuite.run(result) | ||
| return result |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| '''Convenience module to create a test suite will all SEXTANTE tests''' | ||
| import unittest | ||
| from sextante.tests import QgisAlgsTest | ||
| from sextante.tests import ParametersTest | ||
| from sextante.tests import ModelerAlgorithmTest | ||
| from sextante.tests import SextanteToolsTest | ||
| from sextante.tests import ScriptTest | ||
| from sextante.tests import SagaTest | ||
| from sextante.tests import GeoAlgorithmTest | ||
|
|
||
| def suite(): | ||
| suite = unittest.TestSuite() | ||
| suite.addTests(QgisAlgsTest.suite()) | ||
| suite.addTests(ModelerAlgorithmTest.suite()) | ||
| suite.addTests(SagaTest.suite()) | ||
| suite.addTests(ScriptTest.suite()) | ||
| suite.addTests(SextanteToolsTest.suite()) | ||
| #suite.addTests(ParametersTest.suite()) | ||
| suite.addTests(GeoAlgorithmTest.suite()) | ||
| return suite | ||
|
|
||
| def runtests(): | ||
| result = unittest.TestResult() | ||
| testsuite = suite() | ||
| testsuite.run(result) | ||
| return result |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import sextante | ||
| import unittest | ||
| from sextante.tests.TestData import points, points2, polygons, polygons2, lines, union,\ | ||
| table, polygonsGeoJson, raster | ||
| from sextante.core import Sextante | ||
| from sextante.tools.vector import getAttributeValues | ||
|
|
||
| class SextanteToolsTest(unittest.TestCase): | ||
| '''tests the method imported when doing an "import sextante", and also in sextante.tools. | ||
| They are mostly convenience tools''' | ||
|
|
||
| def test_getobject(self): | ||
| layer = sextante.getobject(points()); | ||
| self.assertIsNotNone(layer) | ||
| layer = sextante.getobject("points"); | ||
| self.assertIsNotNone(layer) | ||
|
|
||
| def test_runandload(self): | ||
| sextante.runandload("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS", None) | ||
| layer = Sextante.getObjectFromName("Result") | ||
| self.assertIsNotNone(layer) | ||
|
|
||
| def test_featuresWithoutSelection(self): | ||
| layer = sextante.getobject(points()) | ||
| features = sextante.getfeatures(layer) | ||
| self.assertEqual(12, len(features)) | ||
|
|
||
| def test_featuresWithSelection(self): | ||
| layer = sextante.getobject(points()) | ||
| feature = layer.getFeatures().next() | ||
| selected = [feature.id()] | ||
| layer.setSelectedFeatures(selected) | ||
| features = sextante.getfeatures(layer) | ||
| self.assertEqual(1, len(features)) | ||
| layer.setSelectedFeatures([]) | ||
|
|
||
| def test_attributeValues(self): | ||
| layer = sextante.getobject(points()) | ||
| values = getAttributeValues(layer, "ID") | ||
| i = 1 | ||
| for value in values['ID']: | ||
| self.assertEqual(int(i), int(value)) | ||
| i+=1 | ||
| self.assertEquals(13,i) | ||
|
|
||
| def test_extent(self): | ||
| pass | ||
|
|
||
|
|
||
|
|
||
| def suite(): | ||
| suite = unittest.makeSuite(SextanteToolsTest, 'test') | ||
| return suite | ||
|
|
||
| def runtests(): | ||
| result = unittest.TestResult() | ||
| testsuite = suite() | ||
| testsuite.run(result) | ||
| return result |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
|
||
|
|