|
@@ -36,120 +36,165 @@ class RasterRowImgTestCase(TestCase):
|
|
|
@classmethod
|
|
|
def tearDownClass(cls):
|
|
|
"""Remove the generated vector map, if exist"""
|
|
|
- cls.runModule("g.remove", flags='f', type='raster',
|
|
|
+ cls.runModule("g.remove", flags='f', type='raster',
|
|
|
name=cls.name)
|
|
|
cls.del_temp_region()
|
|
|
|
|
|
@unittest.skipIf(has_PyQt4 is False, "Require PyQt4")
|
|
|
def test_resampling_to_QImg_1(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.from_rast(self.name)
|
|
|
region.cols = 320
|
|
|
region.rows = 240
|
|
|
region.adjust()
|
|
|
-
|
|
|
+
|
|
|
tmpfile = tempfile(False)
|
|
|
tmpfile = tmpfile + ".png"
|
|
|
|
|
|
a = raster2numpy_img(self.name, region)
|
|
|
-
|
|
|
- image = QImage(a.data, region.cols, region.rows,
|
|
|
+
|
|
|
+ image = QImage(a.data, region.cols, region.rows,
|
|
|
QImage.Format_ARGB32)
|
|
|
#image.save("data/a.png")
|
|
|
image.save(tmpfile)
|
|
|
self.assertFilesEqualMd5(tmpfile, "data/a.png")
|
|
|
-
|
|
|
+
|
|
|
@unittest.skipIf(has_PyQt4 is False, "Require PyQt4")
|
|
|
def test_resampling_to_QImg_2(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.from_rast(self.name)
|
|
|
region.cols = 640
|
|
|
region.rows = 480
|
|
|
region.adjust()
|
|
|
-
|
|
|
+
|
|
|
tmpfile = tempfile(False)
|
|
|
tmpfile = tmpfile + ".png"
|
|
|
|
|
|
# With array as argument
|
|
|
array = np.ndarray((region.rows*region.cols*4), np.uint8)
|
|
|
|
|
|
- raster2numpy_img(rastname=self.name, region=region,
|
|
|
+ raster2numpy_img(rastname=self.name, region=region,
|
|
|
color="ARGB", array=array)
|
|
|
-
|
|
|
- image = QImage(array.data,
|
|
|
+
|
|
|
+ image = QImage(array.data,
|
|
|
region.cols, region.rows, QImage.Format_ARGB32)
|
|
|
#image.save("data/b.png")
|
|
|
image.save(tmpfile)
|
|
|
self.assertFilesEqualMd5(tmpfile, "data/b.png")
|
|
|
-
|
|
|
+
|
|
|
@unittest.skipIf(has_PyQt4 is False, "Require PyQt4")
|
|
|
def test_resampling_to_QImg_large(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.from_rast(self.name)
|
|
|
region.cols = 4000
|
|
|
region.rows = 3000
|
|
|
region.adjust()
|
|
|
-
|
|
|
+
|
|
|
tmpfile = tempfile(False)
|
|
|
tmpfile = tmpfile + ".png"
|
|
|
|
|
|
# With array as argument
|
|
|
array = np.ndarray((region.rows*region.cols*4), np.uint8)
|
|
|
|
|
|
- raster2numpy_img(rastname=self.name, region=region,
|
|
|
+ raster2numpy_img(rastname=self.name, region=region,
|
|
|
color="ARGB", array=array)
|
|
|
-
|
|
|
- image = QImage(array.data,
|
|
|
+
|
|
|
+ image = QImage(array.data,
|
|
|
region.cols, region.rows, QImage.Format_ARGB32)
|
|
|
#image.save("data/c.png")
|
|
|
image.save(tmpfile)
|
|
|
self.assertFilesEqualMd5(tmpfile, "data/c.png")
|
|
|
-
|
|
|
+
|
|
|
+ @unittest.skipIf(has_PyQt4 is False, "Require PyQt4")
|
|
|
+ def test_resampling_to_QImg_3(self):
|
|
|
+
|
|
|
+ region = Region()
|
|
|
+ region.from_rast(self.name)
|
|
|
+ region.cols = 400
|
|
|
+ region.rows = 300
|
|
|
+ region.adjust()
|
|
|
+
|
|
|
+ tmpfile = tempfile(False)
|
|
|
+ tmpfile = tmpfile + ".png"
|
|
|
+
|
|
|
+ # With array as argument
|
|
|
+ array = np.ndarray((region.rows*region.cols*4), np.uint8)
|
|
|
+
|
|
|
+ raster2numpy_img(rastname=self.name, region=region,
|
|
|
+ color="RGB", array=array)
|
|
|
+
|
|
|
+ image = QImage(array.data,
|
|
|
+ region.cols, region.rows, QImage.Format_RGB32)
|
|
|
+ #image.save("data/d.png")
|
|
|
+ image.save(tmpfile)
|
|
|
+ self.assertFilesEqualMd5(tmpfile, "data/d.png")
|
|
|
+
|
|
|
+ @unittest.skipIf(has_PyQt4 is False, "Require PyQt4")
|
|
|
+ def test_resampling_to_QImg_4(self):
|
|
|
+
|
|
|
+ region = Region()
|
|
|
+ region.from_rast(self.name)
|
|
|
+ region.cols = 400
|
|
|
+ region.rows = 300
|
|
|
+ region.adjust()
|
|
|
+
|
|
|
+ tmpfile = tempfile(False)
|
|
|
+ tmpfile = tmpfile + ".png"
|
|
|
+
|
|
|
+ array = raster2numpy_img(rastname=self.name, region=region,
|
|
|
+ color="RGB")
|
|
|
+
|
|
|
+ image = QImage(array.data,
|
|
|
+ region.cols, region.rows, QImage.Format_RGB32)
|
|
|
+ #image.save("data/e.png")
|
|
|
+ image.save(tmpfile)
|
|
|
+ self.assertFilesEqualMd5(tmpfile, "data/e.png")
|
|
|
+
|
|
|
def test_resampling_to_numpy_img_1(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.ewres = 10
|
|
|
region.nsres = 10
|
|
|
region.adjust(rows=True, cols=True)
|
|
|
-
|
|
|
+
|
|
|
a = raster2numpy_img(self.name, region)
|
|
|
-
|
|
|
+
|
|
|
self.assertEqual(len(a), region.rows * region.cols*4)
|
|
|
|
|
|
def test_resampling_to_numpy_img_2(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.ewres = 1
|
|
|
region.nsres = 1
|
|
|
region.adjust(rows=True, cols=True)
|
|
|
-
|
|
|
+
|
|
|
a = raster2numpy_img(self.name, region)
|
|
|
-
|
|
|
+
|
|
|
self.assertEqual(len(a), region.rows * region.cols*4)
|
|
|
|
|
|
def test_resampling_to_numpy_img_3(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.ewres = 0.4
|
|
|
region.nsres = 0.4
|
|
|
region.adjust(rows=True, cols=True)
|
|
|
-
|
|
|
+
|
|
|
a = raster2numpy_img(self.name, region, color="GRAY1")
|
|
|
-
|
|
|
+
|
|
|
self.assertEqual(len(a), region.rows * region.cols*1)
|
|
|
|
|
|
def test_resampling_to_numpy_img_4(self):
|
|
|
-
|
|
|
+
|
|
|
region = Region()
|
|
|
region.ewres = 0.1
|
|
|
region.nsres = 0.1
|
|
|
region.adjust(rows=True, cols=True)
|
|
|
-
|
|
|
+
|
|
|
a = raster2numpy_img(self.name, region, color="GRAY2")
|
|
|
-
|
|
|
+
|
|
|
self.assertEqual(len(a), region.rows * region.cols*1)
|
|
|
|
|
|
if __name__ == '__main__':
|