diff --git a/src/View/Debug/Window.py b/src/View/Debug/Window.py
index c3ebae91..c5f4c720 100644
--- a/src/View/Debug/Window.py
+++ b/src/View/Debug/Window.py
@@ -17,6 +17,7 @@
# -*- coding: utf-8 -*-
import logging
+import traceback
from tools import trace, timer
@@ -92,7 +93,8 @@ class ReplWindow(PamhyrWindow):
value = exec(rich_code)
value = self.__debug_exec_result__
except Exception as e:
- value = f"" + str(e) + ""
+ value = f"" + str(e) + "\n"
+ value += f"{traceback.format_exc()}"
# Display code
msg = f" # " + code + " #"
diff --git a/src/View/GeoTIFF/Window.py b/src/View/GeoTIFF/Window.py
index 69fa40c7..12ab2047 100644
--- a/src/View/GeoTIFF/Window.py
+++ b/src/View/GeoTIFF/Window.py
@@ -19,7 +19,7 @@
from tools import trace, timer
from PyQt5.QtWidgets import (
- QAction, QListView,
+ QAction, QListView, QVBoxLayout,
)
from View.Tools.PamhyrWindow import PamhyrWindow
@@ -28,6 +28,23 @@ from View.GeoTIFF.List import ListModel
from View.GeoTIFF.Translate import GeoTIFFTranslate
from View.GeoTIFF.Edit.Window import EditGeoTIFFWindow
+from View.Tools.Plot.PamhyrCanvas import MplCanvas
+from View.PlotXY import PlotXY
+
+try:
+ import rasterio
+ import rasterio.control
+ import rasterio.crs
+ import rasterio.sample
+ import rasterio.vrt
+ import rasterio._features
+
+ from rasterio.io import MemoryFile
+ _rasterio_loaded = True
+except Exception as e:
+ print(f"Module 'rasterio' is not available: {e}")
+ _rasterio_loaded = False
+
class GeoTIFFListWindow(PamhyrWindow):
_pamhyr_ui = "GeoTIFFList"
@@ -48,6 +65,7 @@ class GeoTIFFListWindow(PamhyrWindow):
)
self.setup_list()
+ self.setup_graph()
self.setup_connections()
def setup_list(self):
@@ -59,6 +77,26 @@ class GeoTIFFListWindow(PamhyrWindow):
trad=self._trad,
)
+ def setup_graph(self):
+ self.canvas = MplCanvas(width=5, height=4, dpi=100)
+ self.canvas.setObjectName("canvas")
+ self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
+ self.plot_layout.addWidget(self.canvas)
+
+ self.plot = PlotXY(
+ canvas=self.canvas,
+ data=self._study.river.enable_edges(),
+ trad=self._trad,
+ toolbar=None,
+ parent=self
+ )
+ self.plot.update()
+
+ self._plot_img = {}
+
+ for geotiff in self._study.river.geotiff.lst:
+ self.draw_geotiff(geotiff)
+
def setup_connections(self):
if self._study.is_editable():
self.find(QAction, "action_add").triggered.connect(self.add)
@@ -66,9 +104,39 @@ class GeoTIFFListWindow(PamhyrWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit)
+ def draw_geotiff(self, geotiff):
+ if not _rasterio_loaded:
+ return
+
+ memfile = geotiff.memfile
+ if memfile is None:
+ return
+
+ with memfile.open() as gt:
+ img = gt.read()
+ coords = geotiff.coordinates
+
+ if geotiff in self._plot_img:
+ self._plot_img[geotiff].remove()
+
+ self._plot_img[geotiff] = self.canvas.axes.imshow(
+ img.transpose((1, 2, 0)),
+ extent=list(coords.values())
+ )
+
+ self.plot.idle()
+
def update(self):
self._list.update()
+ for geotiff in self._plot_img:
+ self._plot_img[geotiff].remove()
+
+ self._plot_img = {}
+
+ for geotiff in self._study.river.geotiff.lst:
+ self.draw_geotiff(geotiff)
+
def selected_rows(self):
lst = self.find(QListView, f"listView")
return list(map(lambda i: i.row(), lst.selectedIndexes()))