mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
4 Commits
2e360943b2
...
deb9b2069f
| Author | SHA1 | Date |
|---|---|---|
|
|
deb9b2069f | |
|
|
9308a73e8e | |
|
|
869e116ad0 | |
|
|
a2f3d22001 |
|
|
@ -112,6 +112,7 @@ class GeoTIFF(SQLSubModel):
|
|||
elif key == "description":
|
||||
self.description = value
|
||||
elif key == "file_name":
|
||||
if self._file_name != value:
|
||||
self.read_file(value)
|
||||
elif key == "coordinates":
|
||||
self.coordinates = value
|
||||
|
|
|
|||
|
|
@ -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>"
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ from Modules import Modules
|
|||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QLabel, QPlainTextEdit, QPushButton,
|
||||
QCheckBox, QFileDialog, QVBoxLayout,
|
||||
QLabel, QPlainTextEdit, QPushButton, QCheckBox,
|
||||
QFileDialog, QVBoxLayout, QDoubleSpinBox,
|
||||
)
|
||||
|
||||
from PyQt5.QtCore import (
|
||||
|
|
@ -78,14 +78,15 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
|
||||
self._undo = undo
|
||||
|
||||
self.setup_graph()
|
||||
self.setup_values()
|
||||
self.setup_graph()
|
||||
self.setup_connection()
|
||||
|
||||
def setup_graph(self):
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.plot_layout = self.find(QVBoxLayout, "verticalLayout_geotiff")
|
||||
self.plot_layout = self.find(QVBoxLayout,
|
||||
"verticalLayout_geotiff")
|
||||
self.plot_layout.addWidget(self.canvas)
|
||||
|
||||
self.plot = PlotXY(
|
||||
|
|
@ -109,14 +110,10 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
self.set_line_edit_text("lineEdit_description",
|
||||
self._geotiff.description)
|
||||
|
||||
self._values = {
|
||||
"bottom": self._geotiff.coord_bottom,
|
||||
"top": self._geotiff.coord_top,
|
||||
"left": self._geotiff.coord_left,
|
||||
"right": self._geotiff.coord_right,
|
||||
}
|
||||
|
||||
self._reset_values()
|
||||
bounds = list(self._geotiff.coordinates.values())
|
||||
self._set_values_from_bounds(bounds)
|
||||
self._set_default_values_from_bounds(bounds)
|
||||
self._reset_spinboxes()
|
||||
|
||||
if self._study.is_read_only():
|
||||
self.set_check_box_enable("checkBox", False)
|
||||
|
|
@ -132,14 +129,23 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
"right": bounds[3],
|
||||
}
|
||||
|
||||
self._reset_values()
|
||||
def _set_default_values_from_bounds(self, bounds):
|
||||
self._values_default = {
|
||||
"bottom": bounds[0],
|
||||
"top": bounds[2],
|
||||
"left": bounds[1],
|
||||
"right": bounds[3],
|
||||
}
|
||||
|
||||
def _reset_values(self):
|
||||
def _reset_spinboxes(self):
|
||||
for key in self._values:
|
||||
self._reset_values_key(key)
|
||||
self._reset_spinbox(key)
|
||||
|
||||
def _reset_values_key(self, key):
|
||||
self.set_double_spin_box(f"doubleSpinBox_{key}", self._values[key])
|
||||
def _reset_spinbox(self, key):
|
||||
self.set_double_spin_box(
|
||||
f"doubleSpinBox_{key}",
|
||||
self._values_default[key]
|
||||
)
|
||||
|
||||
def setup_connection(self):
|
||||
self.find(QPushButton, "pushButton_cancel")\
|
||||
|
|
@ -151,7 +157,18 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
|
||||
for key in self._values:
|
||||
self.find(QPushButton, f"pushButton_{key}")\
|
||||
.clicked.connect(lambda: self._reset_values_key(key))
|
||||
.clicked.connect(lambda: self._reset_spinbox(key))
|
||||
|
||||
self.find(QDoubleSpinBox, f"doubleSpinBox_{key}")\
|
||||
.valueChanged.connect(
|
||||
lambda: self.update_values_from_spinbox(key)
|
||||
)
|
||||
|
||||
def update_values_from_spinbox(self, key):
|
||||
self._values[key] = self.get_double_spin_box(f"doubleSpinBox_{key}")
|
||||
|
||||
self._plot_img.set_extent(list(self._values.values()))
|
||||
self.plot.idle()
|
||||
|
||||
def draw_geotiff(self, memfile=None):
|
||||
if not _rasterio_loaded:
|
||||
|
|
@ -164,6 +181,8 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
with rasterio.open(self._file_name) as data:
|
||||
img = data.read()
|
||||
b = data.bounds[:]
|
||||
|
||||
self._set_values_from_bounds(b)
|
||||
else:
|
||||
with memfile.open() as gt:
|
||||
img = gt.read()
|
||||
|
|
@ -172,11 +191,9 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
if self._plot_img is not None:
|
||||
self._plot_img.remove()
|
||||
|
||||
self._set_values_from_bounds(b)
|
||||
|
||||
self._plot_img = self.canvas.axes.imshow(
|
||||
img.transpose((1, 2, 0)),
|
||||
extent=[b[0], b[2], b[1], b[3]]
|
||||
extent=list(self._values.values())
|
||||
)
|
||||
|
||||
self.plot.idle()
|
||||
|
|
|
|||
|
|
@ -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.files:
|
||||
self.draw_geotiff(geotiff)
|
||||
|
||||
def selected_rows(self):
|
||||
lst = self.find(QListView, f"listView")
|
||||
return list(map(lambda i: i.row(), lst.selectedIndexes()))
|
||||
|
|
@ -88,6 +156,7 @@ class GeoTIFFListWindow(PamhyrWindow):
|
|||
return
|
||||
|
||||
self._list.delete(rows[0])
|
||||
self.update()
|
||||
|
||||
def edit(self):
|
||||
rows = self.selected_rows()
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ define_model_action = [
|
|||
"action_menu_boundary_conditions_sediment",
|
||||
"action_menu_rep_additional_lines", "action_menu_output_rk",
|
||||
"action_menu_run_adists", "action_menu_pollutants",
|
||||
"action_menu_d90", "action_menu_dif",
|
||||
"action_menu_d90", "action_menu_dif", "action_menu_edit_geotiff"
|
||||
]
|
||||
|
||||
action = (
|
||||
|
|
@ -298,6 +298,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
self.open_reach_sediment_layers,
|
||||
"action_menu_additional_file": self.open_additional_files,
|
||||
"action_menu_rep_additional_lines": self.open_rep_lines,
|
||||
"action_menu_edit_geotiff": self.open_geotiff,
|
||||
"action_menu_close": self.close_model,
|
||||
"action_menu_results_last": self.open_last_results,
|
||||
"action_menu_open_results_from_file": self.open_results_from_file,
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@
|
|||
<string>&Geometry</string>
|
||||
</property>
|
||||
<addaction name="action_menu_edit_geometry"/>
|
||||
<addaction name="action_menu_edit_geotiff"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_run">
|
||||
<property name="locale">
|
||||
|
|
@ -811,6 +812,11 @@
|
|||
<string>Compare results</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_menu_edit_geotiff">
|
||||
<property name="text">
|
||||
<string>GeoTIFF</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
|
|||
Loading…
Reference in New Issue