diff --git a/src/Model/GeoTIFF/GeoTIFF.py b/src/Model/GeoTIFF/GeoTIFF.py index 4bd17632..315d58cf 100644 --- a/src/Model/GeoTIFF/GeoTIFF.py +++ b/src/Model/GeoTIFF/GeoTIFF.py @@ -35,6 +35,8 @@ try: 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}") @@ -153,7 +155,7 @@ class GeoTIFF(SQLSubModel): if self._file_bytes == b'': return None - if self._memfile == None: + if self._memfile is None: self._memfile = MemoryFile() self._memfile.write(self._file_bytes) @@ -202,9 +204,12 @@ class GeoTIFF(SQLSubModel): def _db_update(cls, execute, version, data=None): major, minor, release = version.strip().split(".") - if major == "0" and int(minor) <= 2: + if major == "0" and int(minor) < 2: + cls._db_create(execute) + + if major == "0" and int(minor) == 2: if int(release) < 3: - cls._create_submodel(execute) + cls._db_create(execute) return True @@ -225,43 +230,44 @@ class GeoTIFF(SQLSubModel): "scenario " + "FROM geotiff " + f"WHERE scenario = {scenario.id} " + - f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})" + f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})" ) - for row in table: - it = iter(row) + if table is not None: + for row in table: + it = iter(row) - id = next(it) - enabled = (next(it) == 1) - deleted = (next(it) == 1) - name = next(it) - description = next(it) - file_name = next(it) - file_bytes = next(it) - coordinates_bottom = next(it) - coordinates_top = next(it) - coordinates_left = next(it) - coordinates_right = next(it) - owner_scenario = next(it) + id = next(it) + enabled = (next(it) == 1) + deleted = (next(it) == 1) + name = next(it) + description = next(it) + file_name = next(it) + file_bytes = next(it) + coordinates_bottom = next(it) + coordinates_top = next(it) + coordinates_left = next(it) + coordinates_right = next(it) + owner_scenario = next(it) - f = cls( - id=id, enabled=enabled, name=name, - description=description, coordinates={ - "bottom": coordinates_bottom, - "top": coordinates_top, - "left": coordinates_left, - "right": coordinates_right, - }, - status=data['status'], - owner_scenario=owner_scenario - ) - if deleted: - f.set_as_deleted() + f = cls( + id=id, enabled=enabled, name=name, + description=description, coordinates={ + "bottom": coordinates_bottom, + "top": coordinates_top, + "left": coordinates_left, + "right": coordinates_right, + }, + status=data['status'], + owner_scenario=owner_scenario + ) + if deleted: + f.set_as_deleted() - f._file_bytes = file_bytes + f._file_bytes = file_bytes - loaded.add(id) - new.append(f) + loaded.add(id) + new.append(f) data["scenario"] = scenario.parent new += cls._db_load(execute, data) @@ -287,7 +293,7 @@ class GeoTIFF(SQLSubModel): self.name, self.description, self.file_name, - self.file_bytes + self.file_bytes, self.coordinates['bottom'], self.coordinates['top'], self.coordinates['left'], diff --git a/src/Model/GeoTIFF/GeoTIFFList.py b/src/Model/GeoTIFF/GeoTIFFList.py index 9e0fafb6..b80a7694 100644 --- a/src/Model/GeoTIFF/GeoTIFFList.py +++ b/src/Model/GeoTIFF/GeoTIFFList.py @@ -20,7 +20,7 @@ from tools import trace, timer from Model.Except import NotImplementedMethodeError from Model.Tools.PamhyrListExt import PamhyrModelList -from Model.AdditionalFile.GeoTIFF import GeoTIFF +from Model.GeoTIFF.GeoTIFF import GeoTIFF class GeoTIFFList(PamhyrModelList): diff --git a/src/Model/River.py b/src/Model/River.py index e0c4602b..b9418026 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -59,6 +59,7 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList \ import LateralContributionsAdisTSList from Model.D90AdisTS.D90AdisTSList import D90AdisTSList from Model.DIFAdisTS.DIFAdisTSList import DIFAdisTSList +from Model.GeoTIFF.GeoTIFFList import GeoTIFFList from Model.Results.Results import Results logger = logging.getLogger() @@ -468,6 +469,7 @@ class River(Graph): LateralContributionsAdisTSList, D90AdisTSList, DIFAdisTSList, + GeoTIFFList, Results ] @@ -505,6 +507,8 @@ class River(Graph): self._D90AdisTS = D90AdisTSList(status=self._status) self._DIFAdisTS = DIFAdisTSList(status=self._status) + self._geo_tiff = GeoTIFFList(status=self._status) + self._results = {} @classmethod @@ -617,6 +621,8 @@ class River(Graph): new._DIFAdisTS = DIFAdisTSList._db_load(execute, data) + new._geo_tiff = GeoTIFFList._db_load(execute, data) + return new def _db_load_results(self, execute, data=None): @@ -726,6 +732,7 @@ class River(Graph): self._BoundaryConditionsAdisTS, self._LateralContributionsAdisTS, self._D90AdisTS, self._DIFAdisTS, + self._geo_tiff, ] for solver in self._parameters: diff --git a/src/Model/Study.py b/src/Model/Study.py index bdb3d2db..f32e90bf 100644 --- a/src/Model/Study.py +++ b/src/Model/Study.py @@ -37,7 +37,7 @@ logger = logging.getLogger() class Study(SQLModel): - _version = "0.2.2" + _version = "0.2.3" _sub_classes = [ Scenario, diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 00db0ce4..8f0f54ac 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -1734,11 +1734,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if self._last_solver._type == "mage8": self.open_solver_results( - solver, # self.last_results + solver, # self.last_results ) elif self._last_solver._type == "adistswc": self.open_solver_results_adists( - solver, # self.last_results + solver, # self.last_results ) def open_results_from_file(self):