mirror of https://gitlab.com/pamhyr/pamhyr2
GeoTIFF: Add geometry and geotiff diplay next to the geotiff list.
parent
2e360943b2
commit
a2f3d22001
|
|
@ -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"<font color=\"red\">" + str(e) + "</font>"
|
||||
value = f"<font color=\"red\">" + str(e) + "</font>\n"
|
||||
value += f"<font color=\"grey\">{traceback.format_exc()}</font>"
|
||||
|
||||
# Display code
|
||||
msg = f"<font color=\"grey\"> # " + code + " #</font>"
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue