mirror of https://gitlab.com/pamhyr/pamhyr2
GeoTIFF: Add geotiff to mainwindow tab info and fix bounds at file import.
parent
786923bdbf
commit
7f0102a881
|
|
@ -35,6 +35,7 @@ from View.GeoTIFF.UndoCommand import (
|
|||
SetCommand
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.PlotXY import PlotXY
|
||||
|
||||
|
|
@ -87,6 +88,11 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
self.canvas.setObjectName("canvas")
|
||||
self.plot_layout = self.find(QVBoxLayout,
|
||||
"verticalLayout_geotiff")
|
||||
self._toolbar = PamhyrPlotToolbar(
|
||||
self.canvas, self,
|
||||
items=["home", "zoom", "save", "iso", "back/forward", "move"]
|
||||
)
|
||||
self.plot_layout.addWidget(self._toolbar)
|
||||
self.plot_layout.addWidget(self.canvas)
|
||||
|
||||
self.plot = PlotXY(
|
||||
|
|
@ -124,16 +130,16 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
def _set_values_from_bounds(self, bounds):
|
||||
self._values = {
|
||||
"bottom": bounds[0],
|
||||
"top": bounds[2],
|
||||
"left": bounds[1],
|
||||
"top": bounds[1],
|
||||
"left": bounds[2],
|
||||
"right": bounds[3],
|
||||
}
|
||||
|
||||
def _set_default_values_from_bounds(self, bounds):
|
||||
self._values_default = {
|
||||
"bottom": bounds[0],
|
||||
"top": bounds[2],
|
||||
"left": bounds[1],
|
||||
"top": bounds[1],
|
||||
"left": bounds[2],
|
||||
"right": bounds[3],
|
||||
}
|
||||
|
||||
|
|
@ -180,13 +186,20 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
|
||||
with rasterio.open(self._file_name) as data:
|
||||
img = data.read()
|
||||
b = data.bounds[:]
|
||||
b = data.bounds[:] # left, bottom, right, top
|
||||
|
||||
self._set_values_from_bounds(b)
|
||||
if b[2] > b[0] and b[1] < b[3]:
|
||||
coord = [b[0], b[2], b[1], b[3]]
|
||||
else:
|
||||
xlim = self.canvas.axes.get_xlim()
|
||||
ylim = self.canvas.axes.get_ylim()
|
||||
coord = xlim + ylim
|
||||
|
||||
self._set_values_from_bounds(coord)
|
||||
self._set_default_values_from_bounds(coord)
|
||||
else:
|
||||
with memfile.open() as gt:
|
||||
img = gt.read()
|
||||
b = gt.bounds[:]
|
||||
|
||||
if self._plot_img is not None:
|
||||
self._plot_img.remove()
|
||||
|
|
@ -197,6 +210,7 @@ class EditGeoTIFFWindow(PamhyrWindow):
|
|||
)
|
||||
|
||||
self.plot.idle()
|
||||
self._reset_spinboxes()
|
||||
|
||||
def _import(self):
|
||||
options = QFileDialog.Options()
|
||||
|
|
|
|||
|
|
@ -124,8 +124,6 @@ class GeoTIFFListWindow(PamhyrWindow):
|
|||
extent=list(coords.values())
|
||||
)
|
||||
|
||||
self.plot.idle()
|
||||
|
||||
def update(self):
|
||||
self._list.update()
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,20 @@ from View.Tools.PamhyrWidget import PamhyrWidget
|
|||
|
||||
from PyQt5.QtWidgets import QVBoxLayout
|
||||
|
||||
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
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
|
|
@ -90,6 +104,8 @@ class WidgetInfo(PamhyrWidget):
|
|||
parent=self
|
||||
)
|
||||
|
||||
self._plot_img = {}
|
||||
|
||||
def update(self):
|
||||
if self._study is None:
|
||||
self.set_initial_values()
|
||||
|
|
@ -108,8 +124,33 @@ class WidgetInfo(PamhyrWidget):
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue