Compare commits

..

No commits in common. "deb9b2069f81db7085179f057b8ddf356e2db0d6" and "2e360943b28fbd16f6c1d1a408ce3907e0c20ae5" have entirely different histories.

6 changed files with 26 additions and 122 deletions

View File

@ -112,8 +112,7 @@ class GeoTIFF(SQLSubModel):
elif key == "description": elif key == "description":
self.description = value self.description = value
elif key == "file_name": elif key == "file_name":
if self._file_name != value: self.read_file(value)
self.read_file(value)
elif key == "coordinates": elif key == "coordinates":
self.coordinates = value self.coordinates = value
elif key == "coordinates_bottom": elif key == "coordinates_bottom":

View File

@ -17,7 +17,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
import traceback
from tools import trace, timer from tools import trace, timer
@ -93,8 +92,7 @@ class ReplWindow(PamhyrWindow):
value = exec(rich_code) value = exec(rich_code)
value = self.__debug_exec_result__ value = self.__debug_exec_result__
except Exception as e: except Exception as e:
value = f"<font color=\"red\">" + str(e) + "</font>\n" value = f"<font color=\"red\">" + str(e) + "</font>"
value += f"<font color=\"grey\">{traceback.format_exc()}</font>"
# Display code # Display code
msg = f"<font color=\"grey\"> # " + code + " #</font>" msg = f"<font color=\"grey\"> # " + code + " #</font>"

View File

@ -22,8 +22,8 @@ from Modules import Modules
from View.Tools.PamhyrWindow import PamhyrWindow from View.Tools.PamhyrWindow import PamhyrWindow
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QLabel, QPlainTextEdit, QPushButton, QCheckBox, QLabel, QPlainTextEdit, QPushButton,
QFileDialog, QVBoxLayout, QDoubleSpinBox, QCheckBox, QFileDialog, QVBoxLayout,
) )
from PyQt5.QtCore import ( from PyQt5.QtCore import (
@ -78,15 +78,14 @@ class EditGeoTIFFWindow(PamhyrWindow):
self._undo = undo self._undo = undo
self.setup_values()
self.setup_graph() self.setup_graph()
self.setup_values()
self.setup_connection() self.setup_connection()
def setup_graph(self): def setup_graph(self):
self.canvas = MplCanvas(width=5, height=4, dpi=100) self.canvas = MplCanvas(width=5, height=4, dpi=100)
self.canvas.setObjectName("canvas") self.canvas.setObjectName("canvas")
self.plot_layout = self.find(QVBoxLayout, self.plot_layout = self.find(QVBoxLayout, "verticalLayout_geotiff")
"verticalLayout_geotiff")
self.plot_layout.addWidget(self.canvas) self.plot_layout.addWidget(self.canvas)
self.plot = PlotXY( self.plot = PlotXY(
@ -110,10 +109,14 @@ class EditGeoTIFFWindow(PamhyrWindow):
self.set_line_edit_text("lineEdit_description", self.set_line_edit_text("lineEdit_description",
self._geotiff.description) self._geotiff.description)
bounds = list(self._geotiff.coordinates.values()) self._values = {
self._set_values_from_bounds(bounds) "bottom": self._geotiff.coord_bottom,
self._set_default_values_from_bounds(bounds) "top": self._geotiff.coord_top,
self._reset_spinboxes() "left": self._geotiff.coord_left,
"right": self._geotiff.coord_right,
}
self._reset_values()
if self._study.is_read_only(): if self._study.is_read_only():
self.set_check_box_enable("checkBox", False) self.set_check_box_enable("checkBox", False)
@ -129,23 +132,14 @@ class EditGeoTIFFWindow(PamhyrWindow):
"right": bounds[3], "right": bounds[3],
} }
def _set_default_values_from_bounds(self, bounds): self._reset_values()
self._values_default = {
"bottom": bounds[0],
"top": bounds[2],
"left": bounds[1],
"right": bounds[3],
}
def _reset_spinboxes(self): def _reset_values(self):
for key in self._values: for key in self._values:
self._reset_spinbox(key) self._reset_values_key(key)
def _reset_spinbox(self, key): def _reset_values_key(self, key):
self.set_double_spin_box( self.set_double_spin_box(f"doubleSpinBox_{key}", self._values[key])
f"doubleSpinBox_{key}",
self._values_default[key]
)
def setup_connection(self): def setup_connection(self):
self.find(QPushButton, "pushButton_cancel")\ self.find(QPushButton, "pushButton_cancel")\
@ -157,18 +151,7 @@ class EditGeoTIFFWindow(PamhyrWindow):
for key in self._values: for key in self._values:
self.find(QPushButton, f"pushButton_{key}")\ self.find(QPushButton, f"pushButton_{key}")\
.clicked.connect(lambda: self._reset_spinbox(key)) .clicked.connect(lambda: self._reset_values_key(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): def draw_geotiff(self, memfile=None):
if not _rasterio_loaded: if not _rasterio_loaded:
@ -181,8 +164,6 @@ class EditGeoTIFFWindow(PamhyrWindow):
with rasterio.open(self._file_name) as data: with rasterio.open(self._file_name) as data:
img = data.read() img = data.read()
b = data.bounds[:] b = data.bounds[:]
self._set_values_from_bounds(b)
else: else:
with memfile.open() as gt: with memfile.open() as gt:
img = gt.read() img = gt.read()
@ -191,9 +172,11 @@ class EditGeoTIFFWindow(PamhyrWindow):
if self._plot_img is not None: if self._plot_img is not None:
self._plot_img.remove() self._plot_img.remove()
self._set_values_from_bounds(b)
self._plot_img = self.canvas.axes.imshow( self._plot_img = self.canvas.axes.imshow(
img.transpose((1, 2, 0)), img.transpose((1, 2, 0)),
extent=list(self._values.values()) extent=[b[0], b[2], b[1], b[3]]
) )
self.plot.idle() self.plot.idle()
@ -219,7 +202,7 @@ class EditGeoTIFFWindow(PamhyrWindow):
if filename != "": if filename != "":
self._file_name = filename self._file_name = filename
self.draw_geotiff() self. draw_geotiff()
def accept(self): def accept(self):
if self._study.is_editable(): if self._study.is_editable():

View File

@ -19,7 +19,7 @@
from tools import trace, timer from tools import trace, timer
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAction, QListView, QVBoxLayout, QAction, QListView,
) )
from View.Tools.PamhyrWindow import PamhyrWindow from View.Tools.PamhyrWindow import PamhyrWindow
@ -28,23 +28,6 @@ from View.GeoTIFF.List import ListModel
from View.GeoTIFF.Translate import GeoTIFFTranslate from View.GeoTIFF.Translate import GeoTIFFTranslate
from View.GeoTIFF.Edit.Window import EditGeoTIFFWindow 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): class GeoTIFFListWindow(PamhyrWindow):
_pamhyr_ui = "GeoTIFFList" _pamhyr_ui = "GeoTIFFList"
@ -65,7 +48,6 @@ class GeoTIFFListWindow(PamhyrWindow):
) )
self.setup_list() self.setup_list()
self.setup_graph()
self.setup_connections() self.setup_connections()
def setup_list(self): def setup_list(self):
@ -77,26 +59,6 @@ class GeoTIFFListWindow(PamhyrWindow):
trad=self._trad, 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): def setup_connections(self):
if self._study.is_editable(): if self._study.is_editable():
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
@ -104,39 +66,9 @@ class GeoTIFFListWindow(PamhyrWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit) 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): def update(self):
self._list.update() 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): def selected_rows(self):
lst = self.find(QListView, f"listView") lst = self.find(QListView, f"listView")
return list(map(lambda i: i.row(), lst.selectedIndexes())) return list(map(lambda i: i.row(), lst.selectedIndexes()))
@ -156,7 +88,6 @@ class GeoTIFFListWindow(PamhyrWindow):
return return
self._list.delete(rows[0]) self._list.delete(rows[0])
self.update()
def edit(self): def edit(self):
rows = self.selected_rows() rows = self.selected_rows()

View File

@ -158,7 +158,7 @@ define_model_action = [
"action_menu_boundary_conditions_sediment", "action_menu_boundary_conditions_sediment",
"action_menu_rep_additional_lines", "action_menu_output_rk", "action_menu_rep_additional_lines", "action_menu_output_rk",
"action_menu_run_adists", "action_menu_pollutants", "action_menu_run_adists", "action_menu_pollutants",
"action_menu_d90", "action_menu_dif", "action_menu_edit_geotiff" "action_menu_d90", "action_menu_dif",
] ]
action = ( action = (
@ -298,7 +298,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.open_reach_sediment_layers, self.open_reach_sediment_layers,
"action_menu_additional_file": self.open_additional_files, "action_menu_additional_file": self.open_additional_files,
"action_menu_rep_additional_lines": self.open_rep_lines, "action_menu_rep_additional_lines": self.open_rep_lines,
"action_menu_edit_geotiff": self.open_geotiff,
"action_menu_close": self.close_model, "action_menu_close": self.close_model,
"action_menu_results_last": self.open_last_results, "action_menu_results_last": self.open_last_results,
"action_menu_open_results_from_file": self.open_results_from_file, "action_menu_open_results_from_file": self.open_results_from_file,

View File

@ -129,7 +129,6 @@
<string>&amp;Geometry</string> <string>&amp;Geometry</string>
</property> </property>
<addaction name="action_menu_edit_geometry"/> <addaction name="action_menu_edit_geometry"/>
<addaction name="action_menu_edit_geotiff"/>
</widget> </widget>
<widget class="QMenu" name="menu_run"> <widget class="QMenu" name="menu_run">
<property name="locale"> <property name="locale">
@ -812,11 +811,6 @@
<string>Compare results</string> <string>Compare results</string>
</property> </property>
</action> </action>
<action name="action_menu_edit_geotiff">
<property name="text">
<string>GeoTIFF</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>