mirror of https://gitlab.com/pamhyr/pamhyr2
GeoTIFF: Continue view integration.
parent
f27b2cc586
commit
6e52b1681e
|
|
@ -42,6 +42,8 @@ except Exception as e:
|
||||||
print(f"Module 'rasterio' is not available: {e}")
|
print(f"Module 'rasterio' is not available: {e}")
|
||||||
_rasterio_loaded = False
|
_rasterio_loaded = False
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class GeoTIFF(SQLSubModel):
|
class GeoTIFF(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
@ -57,10 +59,11 @@ class GeoTIFF(SQLSubModel):
|
||||||
|
|
||||||
self._enabled = enabled
|
self._enabled = enabled
|
||||||
self._name = f"GeoTIFF #{self._pamhyr_id}" if name == "" else name
|
self._name = f"GeoTIFF #{self._pamhyr_id}" if name == "" else name
|
||||||
self._description = text
|
self._description = description
|
||||||
|
|
||||||
self._file_bytes = b''
|
self._file_bytes = b''
|
||||||
self._coordinates = coordinates
|
self._coordinates = coordinates
|
||||||
|
self._file_name = ""
|
||||||
|
|
||||||
if path != "":
|
if path != "":
|
||||||
self.read_file(path)
|
self.read_file(path)
|
||||||
|
|
@ -101,7 +104,7 @@ class GeoTIFF(SQLSubModel):
|
||||||
elif key == "description":
|
elif key == "description":
|
||||||
self.description = value
|
self.description = value
|
||||||
elif key == "file_name":
|
elif key == "file_name":
|
||||||
self.file_name = 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":
|
||||||
|
|
@ -206,17 +209,25 @@ class GeoTIFF(SQLSubModel):
|
||||||
return self._memfile
|
return self._memfile
|
||||||
|
|
||||||
def read_file(self, path):
|
def read_file(self, path):
|
||||||
|
logger.debug(f"Read GeoTIFF file at : '{path}'")
|
||||||
|
|
||||||
self._file_name = path
|
self._file_name = path
|
||||||
self._file_bytes = b''
|
self._file_bytes = b''
|
||||||
self._memfile = None
|
self._memfile = None
|
||||||
|
|
||||||
|
nbytes = 0
|
||||||
|
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
while True:
|
while True:
|
||||||
data = f.read(4096)
|
data = f.read(4096)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
nbytes += len(data)
|
||||||
self._file_bytes += data
|
self._file_bytes += data
|
||||||
|
|
||||||
|
logger.debug(f"Read GeoTIFF: {nbytes} bytes readed")
|
||||||
|
|
||||||
def write_file(self, path):
|
def write_file(self, path):
|
||||||
with open(path, "w+b") as f:
|
with open(path, "w+b") as f:
|
||||||
f.write(self._file_bytes)
|
f.write(self._file_bytes)
|
||||||
|
|
|
||||||
|
|
@ -507,7 +507,7 @@ class River(Graph):
|
||||||
self._D90AdisTS = D90AdisTSList(status=self._status)
|
self._D90AdisTS = D90AdisTSList(status=self._status)
|
||||||
self._DIFAdisTS = DIFAdisTSList(status=self._status)
|
self._DIFAdisTS = DIFAdisTSList(status=self._status)
|
||||||
|
|
||||||
self._geo_tiff = GeoTIFFList(status=self._status)
|
self._geotiff = GeoTIFFList(status=self._status)
|
||||||
|
|
||||||
self._results = {}
|
self._results = {}
|
||||||
|
|
||||||
|
|
@ -621,7 +621,7 @@ class River(Graph):
|
||||||
|
|
||||||
new._DIFAdisTS = DIFAdisTSList._db_load(execute, data)
|
new._DIFAdisTS = DIFAdisTSList._db_load(execute, data)
|
||||||
|
|
||||||
new._geo_tiff = GeoTIFFList._db_load(execute, data)
|
new._geotiff = GeoTIFFList._db_load(execute, data)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
@ -732,7 +732,7 @@ class River(Graph):
|
||||||
self._BoundaryConditionsAdisTS,
|
self._BoundaryConditionsAdisTS,
|
||||||
self._LateralContributionsAdisTS,
|
self._LateralContributionsAdisTS,
|
||||||
self._D90AdisTS, self._DIFAdisTS,
|
self._D90AdisTS, self._DIFAdisTS,
|
||||||
self._geo_tiff,
|
self._geotiff,
|
||||||
]
|
]
|
||||||
|
|
||||||
for solver in self._parameters:
|
for solver in self._parameters:
|
||||||
|
|
@ -825,6 +825,10 @@ Last export at: @date."""
|
||||||
def additional_files(self):
|
def additional_files(self):
|
||||||
return self._additional_files
|
return self._additional_files
|
||||||
|
|
||||||
|
@property
|
||||||
|
def geotiff(self):
|
||||||
|
return self._geotiff
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rep_lines(self):
|
def rep_lines(self):
|
||||||
return self._rep_lines
|
return self._rep_lines
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,15 @@ from View.Tools.PamhyrWindow import PamhyrWindow
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QLabel, QPlainTextEdit, QPushButton,
|
QLabel, QPlainTextEdit, QPushButton,
|
||||||
QCheckBox,
|
QCheckBox, QFileDialog,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtGui import (
|
||||||
|
QPixmap,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QSettings
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.GeoTIFF.Translate import GeoTIFFTranslate
|
from View.GeoTIFF.Translate import GeoTIFFTranslate
|
||||||
|
|
@ -35,22 +43,24 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class EditGeoTIFFWindow(PamhyrWindow):
|
class EditGeoTIFFWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "EditGeoTIFF"
|
_pamhyr_ui = "GeoTIFF"
|
||||||
_pamhyr_name = "Edit GeoTIFF"
|
_pamhyr_name = "Edit GeoTIFF"
|
||||||
|
|
||||||
def __init__(self, study=None, config=None, add_file=None,
|
def __init__(self, study=None, config=None, geotiff=None,
|
||||||
trad=None, undo=None, parent=None):
|
trad=None, undo=None, parent=None):
|
||||||
|
|
||||||
name = trad[self._pamhyr_name] + " - " + study.name
|
|
||||||
super(EditGeoTIFFWindow, self).__init__(
|
super(EditGeoTIFFWindow, self).__init__(
|
||||||
title=name,
|
title=self._pamhyr_name,
|
||||||
study=study,
|
study=study,
|
||||||
config=config,
|
config=config,
|
||||||
|
trad=trad,
|
||||||
options=[],
|
options=[],
|
||||||
parent=parent
|
parent=parent
|
||||||
)
|
)
|
||||||
|
|
||||||
self._geotiff = geotiff
|
self._geotiff = geotiff
|
||||||
|
self._file_name = geotiff.file_name
|
||||||
|
|
||||||
self._hash_data.append(self._geotiff)
|
self._hash_data.append(self._geotiff)
|
||||||
|
|
||||||
self._undo = undo
|
self._undo = undo
|
||||||
|
|
@ -61,12 +71,17 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
||||||
def setup_values(self):
|
def setup_values(self):
|
||||||
self.set_check_box("checkBox", self._geotiff.enabled)
|
self.set_check_box("checkBox", self._geotiff.enabled)
|
||||||
self.set_line_edit_text("lineEdit_name", self._geotiff.name)
|
self.set_line_edit_text("lineEdit_name", self._geotiff.name)
|
||||||
self.set_line_edit_text("lineEdit_description", self._geotiff.description)
|
self.set_line_edit_text("lineEdit_description",
|
||||||
|
self._geotiff.description)
|
||||||
|
|
||||||
self.set_double_spin_box("doubleSpinBox_bottom", self._geotiff.coord_bottom)
|
self._values = {
|
||||||
self.set_double_spin_box("doubleSpinBox_top", self._geotiff.coord_top)
|
"bottom": self._geotiff.coord_bottom,
|
||||||
self.set_double_spin_box("doubleSpinBox_left", self._geotiff.coord_left)
|
"top": self._geotiff.coord_top,
|
||||||
self.set_double_spin_box("doubleSpinBox_right", self._geotiff.coord_right)
|
"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)
|
||||||
|
|
@ -74,11 +89,50 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
||||||
self.set_line_edit_enable("lineEdit_path", False)
|
self.set_line_edit_enable("lineEdit_path", False)
|
||||||
self.set_plaintext_edit_enable("plainTextEdit", False)
|
self.set_plaintext_edit_enable("plainTextEdit", False)
|
||||||
|
|
||||||
|
def _reset_values(self):
|
||||||
|
for key in self._values:
|
||||||
|
self._reset_values_key(key)
|
||||||
|
|
||||||
|
def _reset_values_key(self, key):
|
||||||
|
self.set_double_spin_box(f"doubleSpinBox_{key}", self._values[key])
|
||||||
|
|
||||||
def setup_connection(self):
|
def setup_connection(self):
|
||||||
self.find(QPushButton, "pushButton_cancel")\
|
self.find(QPushButton, "pushButton_cancel")\
|
||||||
.clicked.connect(self.close)
|
.clicked.connect(self.close)
|
||||||
self.find(QPushButton, "pushButton_ok")\
|
self.find(QPushButton, "pushButton_ok")\
|
||||||
.clicked.connect(self.accept)
|
.clicked.connect(self.accept)
|
||||||
|
self.find(QPushButton, "pushButton_import")\
|
||||||
|
.clicked.connect(self._import)
|
||||||
|
|
||||||
|
for key in self._values:
|
||||||
|
self.find(QPushButton, f"pushButton_{key}")\
|
||||||
|
.clicked.connect(lambda: self._reset_values_key(key))
|
||||||
|
|
||||||
|
def _import(self):
|
||||||
|
options = QFileDialog.Options()
|
||||||
|
settings = QSettings(QSettings.IniFormat,
|
||||||
|
QSettings.UserScope, 'MyOrg', )
|
||||||
|
options |= QFileDialog.DontUseNativeDialog
|
||||||
|
|
||||||
|
file_types = [
|
||||||
|
self._trad["file_geotiff"],
|
||||||
|
self._trad["file_all"],
|
||||||
|
]
|
||||||
|
|
||||||
|
filename, _ = QFileDialog.getOpenFileName(
|
||||||
|
self,
|
||||||
|
self._trad["open_file"],
|
||||||
|
"",
|
||||||
|
";; ".join(file_types),
|
||||||
|
options=options
|
||||||
|
)
|
||||||
|
|
||||||
|
if filename != "":
|
||||||
|
self._file_name = filename
|
||||||
|
|
||||||
|
pixmap = QPixmap(filename)
|
||||||
|
self.find(QLabel, "label_geotiff")\
|
||||||
|
.setPixmap(pixmap)
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if self._study.is_editable():
|
if self._study.is_editable():
|
||||||
|
|
@ -99,6 +153,7 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
||||||
coordinates_top=coord_top,
|
coordinates_top=coord_top,
|
||||||
coordinates_left=coord_left,
|
coordinates_left=coord_left,
|
||||||
coordinates_right=coord_right,
|
coordinates_right=coord_right,
|
||||||
|
file_name=self._file_name,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class ListModel(PamhyrListModel):
|
||||||
return QBrush(color)
|
return QBrush(color)
|
||||||
|
|
||||||
if role == Qt.ItemDataRole.DisplayRole:
|
if role == Qt.ItemDataRole.DisplayRole:
|
||||||
text = f"{file.name}: '{file.path}'"
|
text = f"{file.name}: '{file.description}'"
|
||||||
|
|
||||||
if not file.is_enabled():
|
if not file.is_enabled():
|
||||||
text += " (disabled)"
|
text += " (disabled)"
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ _translate = QCoreApplication.translate
|
||||||
|
|
||||||
class GeoTIFFTranslate(MainTranslate):
|
class GeoTIFFTranslate(MainTranslate):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(AddFileTranslate, self).__init__()
|
super(GeoTIFFTranslate, self).__init__()
|
||||||
|
|
||||||
self._dict["GeoTIFF files"] = _translate(
|
self._dict["GeoTIFF files"] = _translate(
|
||||||
"GeoTIFF", "GeoTIFF files"
|
"GeoTIFF", "GeoTIFF files"
|
||||||
|
|
|
||||||
|
|
@ -93,18 +93,18 @@ class GeoTIFFListWindow(PamhyrWindow):
|
||||||
rows = self.selected_rows()
|
rows = self.selected_rows()
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
add_file = self._study.river.geotiff.files[row]
|
geotiff= self._study.river.geotiff.files[row]
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
EditGeoTIFFWindow,
|
EditGeoTIFFWindow,
|
||||||
data=[self._study, self._config, add_file]
|
data=[self._study, self._config, geotiff]
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
win = EditGeoTIFFWindow(
|
win = EditGeoTIFFWindow(
|
||||||
study=self._study,
|
study=self._study,
|
||||||
config=self._config,
|
config=self._config,
|
||||||
add_file=add_file,
|
geotiff=geotiff,
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
parent=self,
|
parent=self,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ from View.Frictions.Window import FrictionsWindow
|
||||||
from View.SedimentLayers.Window import SedimentLayersWindow
|
from View.SedimentLayers.Window import SedimentLayersWindow
|
||||||
from View.SedimentLayers.Reach.Window import ReachSedimentLayersWindow
|
from View.SedimentLayers.Reach.Window import ReachSedimentLayersWindow
|
||||||
from View.AdditionalFiles.Window import AddFileListWindow
|
from View.AdditionalFiles.Window import AddFileListWindow
|
||||||
|
from View.GeoTIFF.Window import GeoTIFFListWindow
|
||||||
from View.REPLines.Window import REPLineListWindow
|
from View.REPLines.Window import REPLineListWindow
|
||||||
from View.SolverParameters.Window import SolverParametersWindow
|
from View.SolverParameters.Window import SolverParametersWindow
|
||||||
from View.RunSolver.Window import (
|
from View.RunSolver.Window import (
|
||||||
|
|
@ -1360,6 +1361,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
)
|
)
|
||||||
self.additonal_files.show()
|
self.additonal_files.show()
|
||||||
|
|
||||||
|
def open_geotiff(self):
|
||||||
|
if self._study is not None:
|
||||||
|
if self.sub_window_exists(
|
||||||
|
GeoTIFFListWindow,
|
||||||
|
data=[self._study, None]
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
self.geotiff = GeoTIFFListWindow(
|
||||||
|
study=self._study, parent=self
|
||||||
|
)
|
||||||
|
self.geotiff.show()
|
||||||
|
|
||||||
def open_rep_lines(self):
|
def open_rep_lines(self):
|
||||||
if self._study is not None:
|
if self._study is not None:
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
|
|
|
||||||
|
|
@ -53,11 +53,6 @@ class ResultsTranslate(MainTranslate):
|
||||||
"Results",
|
"Results",
|
||||||
"Max water elevation"
|
"Max water elevation"
|
||||||
)
|
)
|
||||||
self._dict["file_all"] = _translate("Results", "All files (*)")
|
|
||||||
self._dict["file_geotiff"] = _translate(
|
|
||||||
"Results", "GeoTIFF file (*.tiff *.tif)")
|
|
||||||
self._dict["file_csv"] = _translate(
|
|
||||||
"Results", "CSV file (*.csv)")
|
|
||||||
self._dict["ImageCoordinates"] = _translate(
|
self._dict["ImageCoordinates"] = _translate(
|
||||||
"Results", "Image coordinates"
|
"Results", "Image coordinates"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,18 @@ class CommonWordTranslate(PamhyrTranslate):
|
||||||
|
|
||||||
self._dict["method"] = _translate("CommonWord", "Method")
|
self._dict["method"] = _translate("CommonWord", "Method")
|
||||||
|
|
||||||
|
# Files
|
||||||
|
self._dict["open_file"] = _translate(
|
||||||
|
"CommonWord", "Open file"
|
||||||
|
)
|
||||||
|
self._dict["file_all"] = _translate("CommonWord", "All files (*)")
|
||||||
|
self._dict["file_geotiff"] = _translate(
|
||||||
|
"CommonWord", "GeoTIFF file (*.tiff *.tif)"
|
||||||
|
)
|
||||||
|
self._dict["file_csv"] = _translate(
|
||||||
|
"CommonWord", "CSV file (*.csv)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UnitTranslate(CommonWordTranslate):
|
class UnitTranslate(CommonWordTranslate):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue