Skip to content
Permalink
Browse files

Added raster identfy test

  • Loading branch information
timlinux committed Aug 12, 2012
1 parent 2fbc98e commit 1da65561199b7366184e989a353fd703a454c789
Showing with 46 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +45 −0 tests/src/python/test_qgsrasterlayer.py
@@ -2,3 +2,4 @@ INCLUDE(UsePythonTest)
ADD_PYTHON_TEST(PyQGisApp test_qgisapp.py)
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
ADD_PYTHON_TEST(PyQgsGeometry test_qgsgeometry.py)
ADD_PYTHON_TEST(PyQgsRasterLayer test_qgsrasterlayer.py)
@@ -0,0 +1,45 @@
import os
import unittest

from qgis.core import QgsRasterLayer, QgsPoint
from PyQt4.QtCore import QFileInfo, QString

# Convenience instances in case you may need them
# not used in this test
from utilities import getQgisTestApp
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

class TestQgsRasterLayer(unittest.TestCase):

def testIdentify(self):
myPath = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'testdata', 'landsat.tif'))
myFileInfo = QFileInfo(myPath)
myBaseName = myFileInfo.baseName()
myRasterLayer = QgsRasterLayer(myPath, myBaseName)
myMessage = 'Raster not loaded: %s' % myPath
assert myRasterLayer.isValid(), myMessage
myPoint = QgsPoint(786690, 3345803)
#print 'Extents: %s' % myRasterLayer.extent().toString()
myResult, myRasterValues = myRasterLayer.identify(myPoint)
assert myResult
# Get the name of the first band
myBandName = myRasterValues.keys()[0]
myExpectedName = QString('Band 1')
myMessage = 'Expected "%s" got "%s" for first raster band name' % (
myExpectedName, myBandName)
assert myExpectedName == myBandName, myMessage

# Convert each band value to a list of ints then to a string

myValues = myRasterValues.values()
myIntValues = []
for myValue in myValues:
myIntValues.append(int(str(myValue)))
myValues = str(myIntValues)
myExpectedValues = '[127, 141, 112, 72, 86, 126, 156, 211, 170]'
myMessage = 'Expected: %s\nGot: %s' % (myValues, myExpectedValues)
self.assertEquals(myValues, myExpectedValues, myMessage)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1da6556

Please sign in to comment.
You can’t perform that action at this time.