mirror of https://gitlab.com/pamhyr/pamhyr2
GeoTIFF: Factorise draw geotiff function.
parent
97ece018aa
commit
ae08642116
|
|
@ -86,17 +86,14 @@ class GeoTIFFListWindow(PamhyrWindow):
|
|||
self.plot = PlotXY(
|
||||
canvas=self.canvas,
|
||||
data=self._study.river.enable_edges(),
|
||||
geotiff=self._study.river.geotiff,
|
||||
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)
|
||||
|
|
@ -104,37 +101,9 @@ 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())
|
||||
)
|
||||
|
||||
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()))
|
||||
|
|
|
|||
|
|
@ -104,8 +104,6 @@ class WidgetInfo(PamhyrWidget):
|
|||
parent=self
|
||||
)
|
||||
|
||||
self._plot_img = {}
|
||||
|
||||
def update(self):
|
||||
if self._study is None:
|
||||
self.set_initial_values()
|
||||
|
|
@ -120,37 +118,14 @@ class WidgetInfo(PamhyrWidget):
|
|||
self.plot = PlotXY(
|
||||
canvas=self.canvas,
|
||||
data=self._study.river.enable_edges(),
|
||||
geotiff=self._study.river.geotiff,
|
||||
trad=self.parent._trad,
|
||||
toolbar=self._toolbar_xy,
|
||||
parent=self
|
||||
)
|
||||
|
||||
self.draw_all_geotiff()
|
||||
self.plot.update()
|
||||
|
||||
def draw_all_geotiff(self):
|
||||
if not _rasterio_loaded:
|
||||
return
|
||||
|
||||
for img in self._plot_img:
|
||||
self._plot_img[img].remove()
|
||||
|
||||
self._plot_img = {}
|
||||
|
||||
for geotiff in self._study.river.geotiff.lst:
|
||||
memfile = geotiff.memfile
|
||||
if memfile is None:
|
||||
return
|
||||
|
||||
with memfile.open() as gt:
|
||||
img = gt.read()
|
||||
coords = geotiff.coordinates
|
||||
|
||||
self._plot_img[geotiff] = self.canvas.axes.imshow(
|
||||
img.transpose((1, 2, 0)),
|
||||
extent=list(coords.values())
|
||||
)
|
||||
|
||||
def set_network_values(self):
|
||||
river = self._study.river
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,26 @@ from PyQt5.QtCore import (
|
|||
)
|
||||
from PyQt5.QtWidgets import QApplication, QTableView
|
||||
|
||||
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
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class PlotXY(PamhyrPlot):
|
||||
def __init__(self, canvas=None, trad=None, data=None, toolbar=None,
|
||||
table=None, parent=None):
|
||||
def __init__(self, canvas=None, trad=None, data=None, geotiff=None,
|
||||
toolbar=None, table=None, parent=None):
|
||||
super(PlotXY, self).__init__(
|
||||
canvas=canvas,
|
||||
trad=trad,
|
||||
|
|
@ -43,10 +57,14 @@ class PlotXY(PamhyrPlot):
|
|||
)
|
||||
|
||||
self._data = data
|
||||
self._geotiff = geotiff
|
||||
|
||||
self.label_x = self._trad["x"]
|
||||
self.label_y = self._trad["y"]
|
||||
self.parent = parent
|
||||
|
||||
self._plot_img = {}
|
||||
|
||||
self._isometric_axis = True
|
||||
|
||||
self._auto_relim_update = True
|
||||
|
|
@ -69,7 +87,12 @@ class PlotXY(PamhyrPlot):
|
|||
if data.reach.number_profiles != 0:
|
||||
self.draw_xy(data.reach)
|
||||
self.draw_lr(data.reach)
|
||||
self.idle()
|
||||
|
||||
if self._geotiff is not None:
|
||||
self.draw_geotiff(self._geotiff.files)
|
||||
|
||||
self.idle()
|
||||
|
||||
return
|
||||
|
||||
def draw_xy(self, reach):
|
||||
|
|
@ -78,9 +101,9 @@ class PlotXY(PamhyrPlot):
|
|||
line_xy.append(np.column_stack(xy))
|
||||
|
||||
line_xy_collection = collections.LineCollection(
|
||||
line_xy,
|
||||
colors=self.color_plot_river_bottom
|
||||
)
|
||||
line_xy,
|
||||
colors=self.color_plot_river_bottom
|
||||
)
|
||||
self.canvas.axes.add_collection(line_xy_collection)
|
||||
|
||||
def draw_lr(self, reach):
|
||||
|
|
@ -113,6 +136,34 @@ class PlotXY(PamhyrPlot):
|
|||
)
|
||||
self.line_lr.append(line)
|
||||
|
||||
def draw_geotiff(self, lst):
|
||||
if not _rasterio_loaded:
|
||||
return
|
||||
|
||||
for img in self._plot_img:
|
||||
self._plot_img[img].remove()
|
||||
|
||||
self._plot_img = {}
|
||||
|
||||
for geotiff in lst:
|
||||
memfile = geotiff.memfile
|
||||
if memfile is None:
|
||||
return
|
||||
|
||||
with memfile.open() as gt:
|
||||
img = gt.read()
|
||||
coords = geotiff.coordinates
|
||||
|
||||
self._plot_img[geotiff] = self.canvas.axes.imshow(
|
||||
img.transpose((1, 2, 0)),
|
||||
extent=list(coords.values())
|
||||
)
|
||||
|
||||
if not geotiff.is_enabled():
|
||||
self._plot_img[geotiff].set(alpha=0.5)
|
||||
|
||||
self.idle()
|
||||
|
||||
@timer
|
||||
def update(self):
|
||||
self.draw()
|
||||
|
|
|
|||
Loading…
Reference in New Issue