mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "016f3fc73cf2aabf44f7f304ac08f73dfc2797f9" and "e640fa1bc0ba1d6a3e1c457cce7303f74864d3ac" have entirely different histories.
016f3fc73c
...
e640fa1bc0
|
|
@ -50,23 +50,20 @@ class InternalMeshing(AMeshingTool):
|
|||
elif limites[0] == limites[1]:
|
||||
return reach
|
||||
|
||||
# we never modify original profiles, we work on copies
|
||||
m_profiles = self.st_to_m(reach, limites)
|
||||
new_profiles = self.interpolate_transversal_step(m_profiles,
|
||||
step)
|
||||
self.st_to_m(reach, limites)
|
||||
self.interpolate_transversal_step(reach,
|
||||
limites,
|
||||
step)
|
||||
self.purge_aligned_points(reach)
|
||||
|
||||
for new_profiles2 in new_profiles:
|
||||
for p in new_profiles2:
|
||||
p.hard_purge_aligned_points()
|
||||
|
||||
return new_profiles
|
||||
return reach
|
||||
|
||||
def st_to_m(self, reach, limites):
|
||||
|
||||
gl = reach.compute_guidelines()
|
||||
profiles = [reach.profile(i).copy()
|
||||
for i in range(limites[0], limites[1]+1)
|
||||
]
|
||||
profiles = reach.profiles[limites[0]:limites[1]+1]
|
||||
|
||||
print(profiles)
|
||||
|
||||
# we make sure that the lines are in the left-to-right order
|
||||
guide_list = [
|
||||
|
|
@ -89,9 +86,9 @@ class InternalMeshing(AMeshingTool):
|
|||
for i in range(len(guide_list) - 1):
|
||||
index1 = p.named_point_index(guide_list[i])
|
||||
index2 = p.named_point_index(guide_list[i+1])
|
||||
if index2 - index1 > max_values[i+1]:
|
||||
max_values[i+1] = index2 - index1
|
||||
max_values_index[i+1] = j
|
||||
if index2 - index1 > max_values[i + 1]:
|
||||
max_values[i + 1] = index2 - index1
|
||||
max_values_index[i + 1] = j
|
||||
index1 = p.named_point_index(guide_list[-1])
|
||||
index2 = len(p) - 1
|
||||
if index2 - index1 > max_values[-1]:
|
||||
|
|
@ -107,46 +104,46 @@ class InternalMeshing(AMeshingTool):
|
|||
self.compl_sect(profiles[isect+1],
|
||||
profiles[isect],
|
||||
gl1[i], gl2[i])
|
||||
return profiles
|
||||
|
||||
def interpolate_transversal_step(self,
|
||||
profiles,
|
||||
reach,
|
||||
limites,
|
||||
step):
|
||||
# calcul number of intermediate profiles
|
||||
np = []
|
||||
for i in range(len(profiles)-1):
|
||||
np.append(int((profiles[i+1].rk -
|
||||
profiles[i].rk) / step) - 1)
|
||||
for i in range(limites[0], limites[1]):
|
||||
np.append(int((reach.profiles[i+1].rk -
|
||||
reach.profiles[i].rk) / step) - 1)
|
||||
if np[-1] < 0:
|
||||
np[-1] = 0
|
||||
|
||||
new_profiles = []
|
||||
for i in range(len(profiles)-1):
|
||||
new_profiles2 = []
|
||||
d = [] # ratios
|
||||
p = [] # new profiles
|
||||
ptr = int(limites[0])
|
||||
for i in range(limites[1] - limites[0]):
|
||||
d = 1.0/float(np[i]+1)
|
||||
ptr0 = ptr
|
||||
for j in range(np[i]):
|
||||
p = profiles[i].copy()
|
||||
p = reach.profiles[ptr0].copy()
|
||||
# RATIO entre les deux sections initiales
|
||||
dj = float(j+1)*d
|
||||
pt1 = profiles[i].points
|
||||
pt2 = profiles[i+1].points
|
||||
for k in range(len(pt1)):
|
||||
p.points[k].x = pt1[k].x + \
|
||||
dj*(pt2[k].x -
|
||||
pt1[k].x)
|
||||
p.points[k].y = pt1[k].y + \
|
||||
dj*(pt2[k].y -
|
||||
pt1[k].y)
|
||||
p.points[k].z = pt1[k].z + \
|
||||
dj*(pt2[k].z -
|
||||
pt1[k].z)
|
||||
p.rk = profiles[i].rk + \
|
||||
dj*(profiles[i+1].rk -
|
||||
profiles[i].rk)
|
||||
ptr += 1 # next profile, original
|
||||
for k in range(len(reach.profiles[ptr0].points)):
|
||||
p.points[k].x = reach.profiles[ptr0].points[k].x + \
|
||||
dj*(reach.profiles[ptr].points[k].x -
|
||||
reach.profiles[ptr0].points[k].x)
|
||||
p.points[k].y = reach.profiles[ptr0].points[k].y + \
|
||||
dj*(reach.profiles[ptr].points[k].y -
|
||||
reach.profiles[ptr0].points[k].y)
|
||||
p.points[k].z = reach.profiles[ptr0].points[k].z + \
|
||||
dj*(reach.profiles[ptr].points[k].z -
|
||||
reach.profiles[ptr0].points[k].z)
|
||||
p.rk = reach.profiles[ptr0].rk + \
|
||||
dj*(reach.profiles[ptr].rk -
|
||||
reach.profiles[ptr0].rk)
|
||||
p.name = f'interpol{p.rk}'
|
||||
new_profiles2.append(p)
|
||||
new_profiles.append(new_profiles2)
|
||||
return new_profiles
|
||||
reach.insert_profile(ptr, p)
|
||||
ptr += 1 # next profile, original
|
||||
|
||||
def compl_sect(self, sect1, sect2, tag1, tag2):
|
||||
# sect1: reference section
|
||||
|
|
@ -284,14 +281,14 @@ class InternalMeshing(AMeshingTool):
|
|||
origin_value=0.0,
|
||||
orientation=0):
|
||||
if reach is None or len(reach.profiles) == 0:
|
||||
return []
|
||||
return reach
|
||||
|
||||
nprof = reach.number_profiles
|
||||
if origin >= nprof or origin < 0:
|
||||
logger.warning(
|
||||
f"Origin outside reach"
|
||||
)
|
||||
return reach.get_rk()
|
||||
return reach
|
||||
|
||||
# orientation is the orintation of the bief:
|
||||
# 1: up -> downstream
|
||||
|
|
@ -304,8 +301,7 @@ class InternalMeshing(AMeshingTool):
|
|||
else:
|
||||
sgn = sign(reach.profiles[-1].rk - reach.profiles[0].rk)
|
||||
|
||||
rk = [0.0]*nprof
|
||||
rk[origin] = origin_value
|
||||
reach.profiles[origin].rk = origin_value
|
||||
|
||||
if origin < nprof - 1:
|
||||
for i in range(origin+1, nprof):
|
||||
|
|
@ -316,7 +312,8 @@ class InternalMeshing(AMeshingTool):
|
|||
d2 = reach.profiles[i-1].named_point(
|
||||
directrices[1]
|
||||
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
||||
rk[i] = rk[i-1] + (sgn * (d1 + d2) / 2)
|
||||
reach.profiles[i].rk = reach.profiles[i-1].rk \
|
||||
+ (sgn * (d1 + d2) / 2)
|
||||
if origin > 0:
|
||||
for i in reversed(range(0, origin)):
|
||||
# 2D
|
||||
|
|
@ -326,6 +323,9 @@ class InternalMeshing(AMeshingTool):
|
|||
d2 = reach.profiles[i+1].named_point(
|
||||
directrices[1]
|
||||
).dist_2d(reach.profiles[i].named_point(directrices[1]))
|
||||
rk[i] = rk[i+1] - (sgn * (d1 + d2) / 2)
|
||||
reach.profiles[i].rk = reach.profiles[i+1].rk \
|
||||
- (sgn * (d1 + d2) / 2)
|
||||
|
||||
return rk
|
||||
def purge_aligned_points(self, reach):
|
||||
for p in reach.profiles:
|
||||
p.purge_aligned_points()
|
||||
|
|
|
|||
|
|
@ -278,7 +278,7 @@ class PointXYZ(Point):
|
|||
id=-1,
|
||||
name=self.name,
|
||||
x=self.x, y=self.y, z=self.z,
|
||||
profile=self._profile,
|
||||
profile=self.profile,
|
||||
status=self._status
|
||||
)
|
||||
if self.is_deleted():
|
||||
|
|
@ -406,3 +406,13 @@ class PointXYZ(Point):
|
|||
d = np.sqrt(abs(a2 - pow((c2 - b2 + a2) / (2*np.sqrt(c2)), 2)))
|
||||
|
||||
return d
|
||||
|
||||
def copy(self):
|
||||
p = PointXYZ(self.x,
|
||||
self.y,
|
||||
self.z,
|
||||
self.name,
|
||||
self._profile,
|
||||
self._status)
|
||||
p.sl = self.sl
|
||||
return p
|
||||
|
|
|
|||
|
|
@ -1109,12 +1109,14 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
self.point(i+1).z = 0.5 * self.point(i).z + 0.5 * self.point(i+2).z
|
||||
|
||||
def copy(self):
|
||||
p = ProfileXYZ(id=self.id,
|
||||
name=self.name,
|
||||
rk=self.rk,
|
||||
reach=self.reach,
|
||||
num=self.num,
|
||||
status=self._status)
|
||||
p = ProfileXYZ(self.id,
|
||||
self.name,
|
||||
self.rk,
|
||||
self.reach,
|
||||
self.num,
|
||||
0,
|
||||
0, 0,
|
||||
self._status)
|
||||
for i, k in enumerate(self.points):
|
||||
p.insert_point(i, k.copy())
|
||||
|
||||
|
|
@ -1132,18 +1134,3 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
align = True
|
||||
self.delete_i([i])
|
||||
break
|
||||
|
||||
def hard_purge_aligned_points(self):
|
||||
align = True
|
||||
points = self.points
|
||||
while (align):
|
||||
align = False
|
||||
for i in range(1, len(points) - 1):
|
||||
d = points[i].dist_from_seg(points[i-1],
|
||||
points[i+1])
|
||||
if d < 0.00001 and points[i].name == "":
|
||||
align = True
|
||||
points.pop(i)
|
||||
break
|
||||
self._points = points
|
||||
self.modified()
|
||||
|
|
|
|||
|
|
@ -220,26 +220,6 @@ class Reach(SQLSubModel):
|
|||
)
|
||||
self.modified()
|
||||
|
||||
def hard_delete(self, indexes):
|
||||
"""Delete some elements in profile list
|
||||
|
||||
Args:
|
||||
indexes: The list of index to delete
|
||||
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
self._profiles = list(
|
||||
map(
|
||||
lambda p: p[1],
|
||||
filter(
|
||||
lambda e: e[0] not in indexes,
|
||||
enumerate(self._profiles)
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
||||
def delete_profiles(self, profiles):
|
||||
"""Delete some elements in profile list
|
||||
|
||||
|
|
|
|||
|
|
@ -250,12 +250,12 @@ class GeometryReachTableModel(PamhyrTableModel):
|
|||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def meshing(self, mesher, data, tableView):
|
||||
def meshing(self, mesher, data):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
MeshingCommand(
|
||||
self._data, mesher, data, tableView
|
||||
self._data, mesher, data, "mesh"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -266,8 +266,8 @@ class GeometryReachTableModel(PamhyrTableModel):
|
|||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
UpdateRKCommand(
|
||||
self._data, mesher, data
|
||||
MeshingCommand(
|
||||
self._data, mesher, data, "update_rk"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ from copy import deepcopy
|
|||
from tools import trace, timer, logger_exception
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QMessageBox, QUndoCommand, QUndoStack, QTableView,
|
||||
QMessageBox, QUndoCommand, QUndoStack, QTableView
|
||||
)
|
||||
from PyQt5.QtCore import (QItemSelection, QItemSelectionRange,
|
||||
QItemSelectionModel)
|
||||
|
||||
from Model.Geometry import Reach
|
||||
from Model.Except import exception_message_box
|
||||
|
|
@ -229,110 +227,46 @@ class ImportCommand(QUndoCommand):
|
|||
self._reach.insert_profile(self._row, profile)
|
||||
|
||||
|
||||
class UpdateRKCommand(QUndoCommand):
|
||||
def __init__(self, reach, mesher, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._reach = reach
|
||||
self._data = data
|
||||
self._mesher = mesher
|
||||
self._rks = reach.get_rk()
|
||||
|
||||
self._new_rks = None
|
||||
|
||||
def undo(self):
|
||||
for rk, profile in zip(self._rks, self._reach.profiles):
|
||||
profile.rk = rk
|
||||
|
||||
def redo(self):
|
||||
if self._new_rks is None:
|
||||
self._new_rks = self._mesher.update_rk(
|
||||
self._reach,
|
||||
**self._data
|
||||
)
|
||||
|
||||
for rk, profile in zip(self._new_rks, self._reach.profiles):
|
||||
profile.rk = rk
|
||||
|
||||
|
||||
class MeshingCommand(QUndoCommand):
|
||||
def __init__(self, reach, mesher, data, tableView):
|
||||
def __init__(self, reach, mesher, data, command):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._reach = reach
|
||||
self._data = data
|
||||
self._limites = data["limites"]
|
||||
self._mesher = mesher
|
||||
self._command = command
|
||||
|
||||
self._profiles = [p.copy() for p in reach.profiles]
|
||||
self._profiles.reverse()
|
||||
|
||||
self._new_profiles = None
|
||||
self._new_profiles_indexes = None
|
||||
self._tableView = tableView
|
||||
self._indexes = tableView.selectionModel().selection()
|
||||
|
||||
rows = list(
|
||||
set(
|
||||
(i.row() for i in tableView.selectedIndexes())
|
||||
)
|
||||
)
|
||||
self._selected_rk = [self._reach.profile(r).rk for r in rows]
|
||||
self._new_indexes = None
|
||||
|
||||
def undo(self):
|
||||
self._reach.hard_delete(self._new_profiles_indexes)
|
||||
self._reach.purge()
|
||||
|
||||
# Update selection
|
||||
selection = self._tableView.selectionModel()
|
||||
selection.select(
|
||||
self._indexes,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
for profile in self._profiles:
|
||||
self._reach.insert_profile(0, profile)
|
||||
|
||||
def redo(self):
|
||||
if self._new_profiles is None:
|
||||
self._new_profiles = self._mesher.meshing(
|
||||
self._reach,
|
||||
**self._data
|
||||
)
|
||||
if self._command == "update_rk":
|
||||
self._mesher.update_rk(
|
||||
self._reach,
|
||||
**self._data
|
||||
)
|
||||
else:
|
||||
self._mesher.meshing(
|
||||
self._reach,
|
||||
**self._data
|
||||
)
|
||||
|
||||
if self._new_profiles_indexes is None:
|
||||
k = self._limites[0]
|
||||
self._new_profiles_indexes = []
|
||||
for i in range(self._limites[1] - self._limites[0]):
|
||||
k += 1
|
||||
for p in self._new_profiles[i]:
|
||||
self._new_profiles_indexes.append(k)
|
||||
k += 1
|
||||
self._new_profiles = [p.copy() for p in self._reach.profiles]
|
||||
self._new_profiles.reverse()
|
||||
else:
|
||||
self._reach.purge()
|
||||
|
||||
k = self._limites[0]
|
||||
for i in range(self._limites[1] - self._limites[0]):
|
||||
k += 1
|
||||
for p in self._new_profiles[i]:
|
||||
self._reach.insert_profile(k, p)
|
||||
k += 1
|
||||
|
||||
# Update selection
|
||||
if self._new_indexes is None:
|
||||
ind = []
|
||||
for i in range(self._reach.number_profiles):
|
||||
if self._reach.profile(i).rk in self._selected_rk:
|
||||
ind.append(i)
|
||||
self._tableView.setFocus()
|
||||
self._new_indexes = QItemSelection()
|
||||
if len(ind) > 0:
|
||||
for i in ind:
|
||||
self._new_indexes.append(QItemSelectionRange(
|
||||
self._tableView.model().index(i, 0)
|
||||
))
|
||||
|
||||
selection = self._tableView.selectionModel()
|
||||
selection.select(
|
||||
self._new_indexes,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
for profile in self._new_profiles:
|
||||
self._reach.insert_profile(0, profile)
|
||||
|
||||
|
||||
class PurgeCommand(QUndoCommand):
|
||||
|
|
|
|||
|
|
@ -64,17 +64,8 @@ class UpdateRKDialog(PamhyrDialog):
|
|||
self._end_dir = self._gl[i]
|
||||
|
||||
self._orientation = 0
|
||||
r = self.parent.tableView\
|
||||
.selectionModel()\
|
||||
.selectedRows()
|
||||
if len(r) < 1:
|
||||
self._origin = self._reach.profile(0)
|
||||
self._origin_value = self._reach.profile(0).rk
|
||||
self._origin_index = 0
|
||||
else:
|
||||
self._origin = self._reach.profile(r[0].row())
|
||||
self._origin_value = self._reach.profile(r[0].row()).rk
|
||||
self._origin_index = r[0].row()
|
||||
self._origin = self._reach.profile(0)
|
||||
self._origin_value = self._reach.profile(0).rk
|
||||
|
||||
self._init_default_values_profiles()
|
||||
self._init_default_values_guidelines()
|
||||
|
|
@ -89,8 +80,6 @@ class UpdateRKDialog(PamhyrDialog):
|
|||
.connect(
|
||||
self.changed_profile
|
||||
)
|
||||
self.find(QComboBox, "comboBox_origin")\
|
||||
.setCurrentIndex(self._origin_index)
|
||||
|
||||
buttonbox = self.find(QButtonGroup, "buttonGroup_orientation")
|
||||
|
||||
|
|
|
|||
|
|
@ -323,10 +323,29 @@ class GeometryWindow(PamhyrWindow):
|
|||
logger_exception(e)
|
||||
return
|
||||
|
||||
ind = []
|
||||
for i in range(self._reach.number_profiles):
|
||||
if self._reach.profile(i).rk in selected_rk:
|
||||
ind.append(i)
|
||||
self.tableView.setFocus()
|
||||
selection = self.tableView.selectionModel()
|
||||
index = QItemSelection()
|
||||
if len(ind) > 0:
|
||||
for i in ind:
|
||||
index.append(QItemSelectionRange(
|
||||
self.tableView.model().index(i, 0)
|
||||
))
|
||||
selection.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
|
||||
def _edit_meshing(self, data):
|
||||
try:
|
||||
mesher = InternalMeshing()
|
||||
self._table.meshing(mesher, data, self.tableView)
|
||||
self._table.meshing(mesher, data)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
||||
|
|
@ -351,7 +370,7 @@ class GeometryWindow(PamhyrWindow):
|
|||
|
||||
def _update_rk(self, data):
|
||||
try:
|
||||
mesher = InternalMeshing()
|
||||
mesher = MeshingWithMageMailleurTT()
|
||||
self._table.update_rk(mesher, data)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
|
|
|
|||
|
|
@ -159,9 +159,9 @@ class TableModel(PamhyrTableModel):
|
|||
if self._opt_data == "reach":
|
||||
self._lst = _river.reachs
|
||||
elif self._opt_data == "profile" or self._opt_data == "raw_data":
|
||||
self._lst = _river.reach(reach).profiles
|
||||
# self._lst = list(compress(_river.reach(reach).profiles,
|
||||
# _river.reach(reach).profile_mask))
|
||||
# self._lst = _river.reach(reach).profiles
|
||||
self._lst = list(compress(_river.reach(reach).profiles,
|
||||
_river.reach(reach).profile_mask))
|
||||
elif self._opt_data == "solver":
|
||||
self._lst = self._parent._solvers
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
import os
|
||||
import csv
|
||||
import logging
|
||||
# import rasterio
|
||||
import rasterio
|
||||
|
||||
from numpy import sqrt
|
||||
|
||||
|
|
@ -339,8 +339,6 @@ class ResultsWindow(PamhyrWindow):
|
|||
# "action_export": self.export_current,
|
||||
"action_Geo_tiff": self.import_geotiff
|
||||
}
|
||||
self.find(QAction, "action_Geo_tiff").setEnabled(False)
|
||||
self.find(QAction, "action_Geo_tiff").setVisible(False)
|
||||
|
||||
if len(self._results) > 1:
|
||||
self.find(QAction, "action_reload").setEnabled(False)
|
||||
|
|
@ -1169,48 +1167,47 @@ class ResultsWindow(PamhyrWindow):
|
|||
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
|
||||
# xlim = self.canvas.axes.get_xlim()
|
||||
# ylim = self.canvas.axes.get_ylim()
|
||||
# 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:
|
||||
# dlg = CoordinatesDialog(
|
||||
# xlim,
|
||||
# ylim,
|
||||
# trad=self._trad,
|
||||
# parent=self
|
||||
# )
|
||||
# if dlg.exec():
|
||||
# self.canvas.axes.imshow(img.transpose((1, 2, 0)),
|
||||
# extent=dlg.values)
|
||||
# self.plot_xy.idle()
|
||||
# self.canvas.axes.set_xlim(xlim)
|
||||
# self.canvas.axes.set_ylim(ylim)
|
||||
return
|
||||
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
|
||||
xlim = self.canvas.axes.get_xlim()
|
||||
ylim = self.canvas.axes.get_ylim()
|
||||
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:
|
||||
dlg = CoordinatesDialog(
|
||||
xlim,
|
||||
ylim,
|
||||
trad=self._trad,
|
||||
parent=self
|
||||
)
|
||||
if dlg.exec():
|
||||
self.canvas.axes.imshow(img.transpose((1, 2, 0)),
|
||||
extent=dlg.values)
|
||||
self.plot_xy.idle()
|
||||
self.canvas.axes.set_xlim(xlim)
|
||||
self.canvas.axes.set_ylim(ylim)
|
||||
|
|
|
|||
Loading…
Reference in New Issue