mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
GeoTIFF: Factorise draw geotiff function.
This commit is contained in:
1 parent
97ece018aa
commit
ae08642116
3 files changed
+60
-65
No files matched your search
+57
-6
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user