test background img import

terraz_dev
Theophile Terraz 2025-06-06 10:16:44 +02:00
parent 3e8132646d
commit 5ba38d5cd6
4 changed files with 53 additions and 0 deletions

View File

@ -12,3 +12,5 @@ shapely>=2.0.1
lxml>=4.9.3
platformdirs>=4.2.0
pyshp>=2.3.1
rasterio==1.3.11
#fortranformat==2.0.3

View File

@ -19,6 +19,7 @@
import os
import csv
import logging
import rasterio
from numpy import sqrt
@ -35,6 +36,7 @@ from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QItemSelectionModel, QTimer,
QSettings
)
from PyQt5.QtWidgets import (
@ -334,6 +336,7 @@ class ResultsWindow(PamhyrWindow):
"action_add": self._add_custom_plot,
"action_export": self._export,
# "action_export": self.export_current,
"action_Geo_tiff": self.import_geotiff
}
if len(self._results) > 1:
@ -1162,3 +1165,39 @@ class ResultsWindow(PamhyrWindow):
profile_id = self._get_current_profile()
self.update_table_selection_profile(profile_id)
def import_geotiff(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 != "":
with rasterio.open(filename) as data:
img = data.read()
b = data.bounds[:]
# b[0] left
# b[1] bottom
# b[2] right
# b[3] top
if b[2] < b[0] and b[1] < b[3]:
self.canvas.axes.imshow(img.transpose((1, 2, 0)), extent=[b[0], b[2], b[1], b[3]])
else:
x = self.canvas.axes.get_xlim()
y = self.canvas.axes.get_ylim()
self.canvas.axes.imshow(img.transpose((1, 2, 0)), extent=[x[0], x[1], y[0], y[1]])
self.plot_xy.idle()

View File

@ -53,6 +53,9 @@ class ResultsTranslate(MainTranslate):
"Results",
"Max water elevation"
)
self._dict["file_all"] = _translate("GeoTIFF", "All files (*)")
self._dict["file_geotiff"] = _translate(
"GeoTIFF", "GeoTIFF file (*.tiff *.tif)")
self._sub_dict["table_headers_reach"] = {
"name": _translate("Results", "Reach name"),

View File

@ -238,6 +238,7 @@
<addaction name="action_add"/>
<addaction name="action_export"/>
<addaction name="action_reload"/>
<addaction name="action_Geo_tiff"/>
</widget>
<action name="action_add">
<property name="icon">
@ -275,6 +276,14 @@
<string>Ctrl+E</string>
</property>
</action>
<action name="action_Geo_tiff">
<property name="text">
<string>Geo tiff</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Import Geo tiff image&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</action>
</widget>
<resources/>
<connections/>