Merge remote-tracking branch 'origin/dev-setband'
This commit is contained in:
commit
9f7478dfa9
@ -3,12 +3,13 @@ import os
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
from PyQt5.QtWidgets import QAction, QActionGroup, QLabel, QFileDialog, QMenuBar
|
from PyQt5.QtWidgets import QAction, QActionGroup, QLabel, QFileDialog, QMenuBar
|
||||||
|
from rscder.gui import project
|
||||||
from rscder.gui.project import Create
|
from rscder.gui.project import Create
|
||||||
from rscder.utils.project import Project
|
from rscder.utils.project import Project
|
||||||
from rscder.utils.misc import singleton
|
from rscder.utils.misc import singleton
|
||||||
from rscder.gui.plugins import PluginDialog
|
from rscder.gui.plugins import PluginDialog
|
||||||
from rscder.utils.setting import Settings
|
from rscder.utils.setting import Settings
|
||||||
|
from rscder.gui.load import loader
|
||||||
def get_action_manager() -> 'ActionManager':
|
def get_action_manager() -> 'ActionManager':
|
||||||
return ActionManager()
|
return ActionManager()
|
||||||
|
|
||||||
@ -226,14 +227,17 @@ class ActionManager(QtCore.QObject):
|
|||||||
def data_load(self):
|
def data_load(self):
|
||||||
if Project().is_init:
|
if Project().is_init:
|
||||||
Project().save()
|
Project().save()
|
||||||
|
file_loader=loader(self.w_parent)
|
||||||
file_open = QFileDialog.getOpenFileNames(self.w_parent, '打开数据', Settings.General().last_path, '*.*')
|
if(file_loader.exec_()):
|
||||||
if file_open[0] != '':
|
Project().add_layer(file_loader.path1,file_loader.path2,file_loader.style1,file_loader.style2)
|
||||||
if len(file_open[0]) != 2:
|
|
||||||
self.message_box.warning('请选择两个数据文件')
|
|
||||||
return
|
|
||||||
Project().add_layer(file_open[0][0], file_open[0][1])
|
|
||||||
self.message_box.info('Data loaded')
|
self.message_box.info('Data loaded')
|
||||||
|
# file_open = QFileDialog.getOpenFileNames(self.w_parent, '打开数据', Settings.General().last_path, '*.*')
|
||||||
|
# if file_open[0] != '':
|
||||||
|
# if len(file_open[0]) != 2:
|
||||||
|
# self.message_box.warning('请选择两个数据文件')
|
||||||
|
# return
|
||||||
|
# Project().add_layer(file_open[0][0], file_open[0][1])
|
||||||
|
|
||||||
|
|
||||||
def view_setting(self):
|
def view_setting(self):
|
||||||
pass
|
pass
|
||||||
|
171
rscder/gui/load.py
Normal file
171
rscder/gui/load.py
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
from tkinter.ttk import Style
|
||||||
|
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow, QToolBox
|
||||||
|
from PyQt5.QtWidgets import QDialog, QFileDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QLabel, QMessageBox
|
||||||
|
from PyQt5.QtCore import Qt, QSize, QSettings
|
||||||
|
from PyQt5.QtGui import QIcon,QColor
|
||||||
|
from PyQt5 import QtGui
|
||||||
|
from rscder.utils.setting import Settings
|
||||||
|
from rscder.gui.mapcanvas import DoubleCanvas
|
||||||
|
from qgis.gui import QgsMapCanvas
|
||||||
|
from rscder.utils.project import RasterLayer
|
||||||
|
class loader(QDialog):
|
||||||
|
def __init__(self, parent=None) -> None:
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setWindowTitle('Load Data')
|
||||||
|
self.setWindowIcon(QIcon(":/icons/data_load.png"))
|
||||||
|
self.path1=''
|
||||||
|
self.path2=''
|
||||||
|
self.bands=['red:','green:','blue:','NIR:']
|
||||||
|
self.bandsorder=[3,2,1,4]
|
||||||
|
self.mapcanva1 = QgsMapCanvas(self)
|
||||||
|
self.mapcanva2 = QgsMapCanvas(self)
|
||||||
|
self.mapcanva1.setCanvasColor(QColor(0, 0, 0))
|
||||||
|
self.mapcanva2.setCanvasColor(QColor(0, 0, 0))
|
||||||
|
self.mapcanva1.setFixedWidth(200)
|
||||||
|
self.mapcanva1.setFixedHeight(200)
|
||||||
|
self.mapcanva2.setFixedWidth(200)
|
||||||
|
self.mapcanva2.setFixedHeight(200)
|
||||||
|
maplayout=QHBoxLayout()
|
||||||
|
maplayout.addWidget(self.mapcanva1)
|
||||||
|
maplayout.addWidget(self.mapcanva2)
|
||||||
|
|
||||||
|
path1_label = QLabel('Pic 1:')
|
||||||
|
path1_label.setFixedWidth(60)
|
||||||
|
path1_input = QLineEdit()
|
||||||
|
path1_input.setPlaceholderText('Pic 1')
|
||||||
|
path1_input.setToolTip('Pic 1')
|
||||||
|
path1_input.setReadOnly(True)
|
||||||
|
path1_input.setText(self.path1)
|
||||||
|
self.path1_input = path1_input
|
||||||
|
|
||||||
|
|
||||||
|
path1_open = QPushButton('...', self)
|
||||||
|
path1_open.setFixedWidth(30)
|
||||||
|
path1_open.clicked.connect(self.open_file1)
|
||||||
|
|
||||||
|
|
||||||
|
path1_layout=QHBoxLayout()
|
||||||
|
path1_layout.addWidget(path1_label)
|
||||||
|
path1_layout.addWidget(path1_input)
|
||||||
|
path1_layout.addWidget(path1_open)
|
||||||
|
|
||||||
|
|
||||||
|
labels1=[QLabel() for i in range(4)]
|
||||||
|
style1_inputs=[QLineEdit() for i in range(4)]
|
||||||
|
for i in range(4):
|
||||||
|
labels1[i].setText(self.bands[i])
|
||||||
|
labels1[i].setFixedWidth(50)
|
||||||
|
style1_inputs[i].setText(str(self.bandsorder[i]))
|
||||||
|
style1_inputs[i].setFixedWidth(20)
|
||||||
|
self.style1_inputs=style1_inputs
|
||||||
|
style1_set = QPushButton(self.tr('确定'), self)
|
||||||
|
style1_set.setFixedWidth(40)
|
||||||
|
style1_set.clicked.connect(self.set_style1)
|
||||||
|
|
||||||
|
style1_layout=QHBoxLayout()
|
||||||
|
for i in range(4):
|
||||||
|
style1_layout.addWidget(labels1[i])
|
||||||
|
style1_layout.addWidget(style1_inputs[i])
|
||||||
|
style1_layout.addWidget(style1_set)
|
||||||
|
|
||||||
|
path2_label = QLabel('Pic 2:')
|
||||||
|
path2_label.setFixedWidth(60)
|
||||||
|
path2_input = QLineEdit()
|
||||||
|
path2_input.setPlaceholderText('Pic 1')
|
||||||
|
path2_input.setToolTip('Pic 1')
|
||||||
|
path2_input.setReadOnly(True)
|
||||||
|
path2_input.setText(self.path2)
|
||||||
|
self.path2_input = path2_input
|
||||||
|
|
||||||
|
path2_open = QPushButton('...', self)
|
||||||
|
path2_open.setFixedWidth(30)
|
||||||
|
path2_open.clicked.connect(self.open_file2)
|
||||||
|
|
||||||
|
path2_layout=QHBoxLayout()
|
||||||
|
path2_layout.addWidget(path2_label)
|
||||||
|
path2_layout.addWidget(path2_input)
|
||||||
|
path2_layout.addWidget(path2_open)
|
||||||
|
|
||||||
|
|
||||||
|
labels2=[QLabel() for i in range(4)]
|
||||||
|
|
||||||
|
style2_inputs=[QLineEdit() for i in range(4)]
|
||||||
|
for i in range(4):
|
||||||
|
labels2[i].setText(self.bands[i])
|
||||||
|
labels2[i].setFixedWidth(50)
|
||||||
|
style2_inputs[i].setText(str(self.bandsorder[i]))
|
||||||
|
style2_inputs[i].setFixedWidth(20)
|
||||||
|
self.style2_inputs=style2_inputs
|
||||||
|
style2_set = QPushButton(self.tr('确定'), self)
|
||||||
|
style2_set.setFixedWidth(40)
|
||||||
|
style2_set.clicked.connect(self.set_style2)
|
||||||
|
|
||||||
|
style2_layout=QHBoxLayout()
|
||||||
|
for i in range(4):
|
||||||
|
style2_layout.addWidget(labels2[i])
|
||||||
|
style2_layout.addWidget(style2_inputs[i])
|
||||||
|
style2_layout.addWidget(style2_set)
|
||||||
|
|
||||||
|
ok_button = QPushButton(self.tr('确定'))
|
||||||
|
cancel_button = QPushButton(self.tr('取消'))
|
||||||
|
|
||||||
|
ok_button.clicked.connect(self.ok)
|
||||||
|
cancel_button.clicked.connect(self.cancel)
|
||||||
|
|
||||||
|
button_layout = QHBoxLayout()
|
||||||
|
button_layout.setDirection(QHBoxLayout.RightToLeft)
|
||||||
|
button_layout.addWidget(ok_button, 0, Qt.AlignRight)
|
||||||
|
button_layout.addWidget(cancel_button, 0, Qt.AlignRight)
|
||||||
|
|
||||||
|
main_layout = QVBoxLayout()
|
||||||
|
main_layout.addLayout(path1_layout)
|
||||||
|
main_layout.addLayout(style1_layout)
|
||||||
|
main_layout.addLayout(path2_layout)
|
||||||
|
main_layout.addLayout(style2_layout)
|
||||||
|
main_layout.addLayout(maplayout)
|
||||||
|
main_layout.addLayout(button_layout)
|
||||||
|
self.setLayout(main_layout)
|
||||||
|
|
||||||
|
def open_file1(self):
|
||||||
|
path1 = QFileDialog.getOpenFileNames(self, '打开数据1', Settings.General().last_path, '*.*')
|
||||||
|
if path1:
|
||||||
|
self.path1 = path1[0][0]
|
||||||
|
self.path1_input.setText(self.path1)
|
||||||
|
self.left_layer=RasterLayer(path=self.path1)
|
||||||
|
self.mapcanva1.setLayers([self.left_layer.layer])
|
||||||
|
self.mapcanva1.zoomToFeatureExtent(self.left_layer.layer.extent())
|
||||||
|
|
||||||
|
def open_file2(self):
|
||||||
|
path2 = QFileDialog.getOpenFileNames(self, '打开数据2', Settings.General().last_path, '*.*')
|
||||||
|
if path2:
|
||||||
|
self.path2 = path2[0][0]
|
||||||
|
self.path2_input.setText(self.path2)
|
||||||
|
self.right_layer=RasterLayer(path=self.path2)
|
||||||
|
self.mapcanva2.setLayers([self.right_layer.layer])
|
||||||
|
self.mapcanva2.zoomToFeatureExtent(self.right_layer.layer.extent())
|
||||||
|
def ok(self):
|
||||||
|
self.bandsorder1=[int(q.text()) for q in self.style1_inputs ]
|
||||||
|
self.style1={'r':self.bandsorder1[0],'g':self.bandsorder1[1],'b':self.bandsorder1[2],'NIR':self.bandsorder1[3]}
|
||||||
|
|
||||||
|
self.bandsorder2=[int(q.text()) for q in self.style2_inputs ]
|
||||||
|
self.style2={'r':self.bandsorder2[0],'g':self.bandsorder2[1],'b':self.bandsorder2[2],'NIR':self.bandsorder2[3]}
|
||||||
|
|
||||||
|
if self.path1 == '':
|
||||||
|
QMessageBox.warning(self, 'Warning', 'Please select pic 1!')
|
||||||
|
return
|
||||||
|
if self.path2 == '':
|
||||||
|
QMessageBox.warning(self, 'Warning', 'Please select pic 2!')
|
||||||
|
return
|
||||||
|
self.accept()
|
||||||
|
def cancel(self):
|
||||||
|
self.reject()
|
||||||
|
|
||||||
|
def set_style1(self):
|
||||||
|
self.bandsorder1=[int(q.text()) for q in self.style1_inputs ]
|
||||||
|
self.style1={'r':self.bandsorder1[0],'g':self.bandsorder1[1],'b':self.bandsorder1[2],'NIR':self.bandsorder1[3]}
|
||||||
|
self.left_layer.set_stlye(self.style1)
|
||||||
|
|
||||||
|
def set_style2(self):
|
||||||
|
self.bandsorder2=[int(q.text()) for q in self.style2_inputs ]
|
||||||
|
self.style2={'r':self.bandsorder2[0],'g':self.bandsorder2[1],'b':self.bandsorder2[2],'NIR':self.bandsorder2[3]}
|
||||||
|
self.right_layer.set_stlye(self.style2)
|
@ -12,7 +12,7 @@ import numpy as np
|
|||||||
from osgeo import gdal, gdal_array
|
from osgeo import gdal, gdal_array
|
||||||
from rscder.utils.icons import IconInstance
|
from rscder.utils.icons import IconInstance
|
||||||
from rscder.utils.setting import Settings
|
from rscder.utils.setting import Settings
|
||||||
from qgis.core import QgsRasterLayer, QgsMarkerSymbol, QgsUnitTypes, QgsCategorizedSymbolRenderer, QgsRendererCategory, QgsPalLayerSettings, QgsRuleBasedLabeling, QgsTextFormat, QgsLineSymbol, QgsSingleSymbolRenderer, QgsSimpleLineSymbolLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsFeature, QgsGeometry, QgsPointXY
|
from qgis.core import QgsRasterLayer, QgsMarkerSymbol, QgsUnitTypes, QgsCategorizedSymbolRenderer, QgsRendererCategory, QgsPalLayerSettings, QgsRuleBasedLabeling, QgsTextFormat, QgsLineSymbol, QgsSingleSymbolRenderer, QgsSimpleLineSymbolLayer, QgsVectorLayer, QgsCoordinateReferenceSystem, QgsFeature, QgsGeometry, QgsPointXY,QgsMultiBandColorRenderer
|
||||||
from PyQt5.QtCore import QObject, pyqtSignal, Qt, QThread
|
from PyQt5.QtCore import QObject, pyqtSignal, Qt, QThread
|
||||||
from PyQt5.QtWidgets import QTreeWidgetItem, QAction
|
from PyQt5.QtWidgets import QTreeWidgetItem, QAction
|
||||||
from PyQt5.QtGui import QColor, QIcon, QFont
|
from PyQt5.QtGui import QColor, QIcon, QFont
|
||||||
@ -187,8 +187,8 @@ class Project(QObject):
|
|||||||
os.makedirs(pth)
|
os.makedirs(pth)
|
||||||
return pth
|
return pth
|
||||||
|
|
||||||
def add_layer(self, pth1, pth2):
|
def add_layer(self, pth1, pth2,style_info1,style_info2):
|
||||||
player = PairLayer(pth1, pth2)
|
player = PairLayer(pth1, pth2,style_info1,style_info2)
|
||||||
if player.check():
|
if player.check():
|
||||||
self.layers[player.id] = player
|
self.layers[player.id] = player
|
||||||
self.layer_show_update.emit()
|
self.layer_show_update.emit()
|
||||||
@ -369,13 +369,13 @@ class GridLayer(BasicLayer):
|
|||||||
|
|
||||||
class RasterLayer(BasicLayer):
|
class RasterLayer(BasicLayer):
|
||||||
|
|
||||||
def __init__(self, name=None, enable=False, path=None,
|
def __init__(self, name=None, enable=False, path=None, view_mode=BasicLayer.BOATH_VIEW,style_info={'r':3,'g':2,'b':1,'NIR':3}):
|
||||||
view_mode=BasicLayer.BOATH_VIEW):
|
|
||||||
if name is None:
|
if name is None:
|
||||||
name = os.path.splitext(os.path.basename(path))[0]
|
name = os.path.splitext(os.path.basename(path))[0]
|
||||||
super().__init__(name, enable, ':/icons/raster.png', path, BasicLayer.IN_FILE, view_mode)
|
super().__init__(name, enable, ':/icons/raster.png', path, BasicLayer.IN_FILE, view_mode)
|
||||||
self.layer = QgsRasterLayer(self.path, self.name)
|
self.layer = QgsRasterLayer(self.path, self.name)
|
||||||
|
self.style_info=style_info
|
||||||
|
self.apply_style()
|
||||||
def compare(self, other:'RasterLayer'):
|
def compare(self, other:'RasterLayer'):
|
||||||
ds1 = gdal.Open(self.path)
|
ds1 = gdal.Open(self.path)
|
||||||
ds2 = gdal.Open(other.path)
|
ds2 = gdal.Open(other.path)
|
||||||
@ -415,7 +415,13 @@ class RasterLayer(BasicLayer):
|
|||||||
s = (ds.RasterXSize, ds.RasterYSize)
|
s = (ds.RasterXSize, ds.RasterYSize)
|
||||||
del ds
|
del ds
|
||||||
return s
|
return s
|
||||||
|
def apply_style(self):
|
||||||
|
renderer=QgsMultiBandColorRenderer(self.layer.dataProvider(),self.style_info['r'],self.style_info['g'],self.style_info['b'])
|
||||||
|
self.layer.setRenderer(renderer)
|
||||||
|
self.layer.triggerRepaint()
|
||||||
|
def set_stlye(self,style_info):
|
||||||
|
self.style_info=style_info
|
||||||
|
self.apply_style()
|
||||||
class VectorLayer(BasicLayer):
|
class VectorLayer(BasicLayer):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -566,13 +572,13 @@ class ResultPointLayer(BasicLayer):
|
|||||||
|
|
||||||
class PairLayer(BasicLayer):
|
class PairLayer(BasicLayer):
|
||||||
|
|
||||||
def __init__(self, pth1, pth2) -> None:
|
def __init__(self, pth1, pth2,style_info1,style_info2) -> None:
|
||||||
|
|
||||||
self.layers:List[BasicLayer] = []
|
self.layers:List[BasicLayer] = []
|
||||||
self.id = str(uuid.uuid1())
|
self.id = str(uuid.uuid1())
|
||||||
self.checked = False
|
self.checked = False
|
||||||
self.main_l1 = RasterLayer(path = pth1, enable=True, view_mode=BasicLayer.LEFT_VIEW)
|
self.main_l1 = RasterLayer(path = pth1, enable=True, view_mode=BasicLayer.LEFT_VIEW,style_info=style_info1)
|
||||||
self.main_l2 = RasterLayer(path = pth2, enable=True, view_mode=BasicLayer.RIGHT_VIEW)
|
self.main_l2 = RasterLayer(path = pth2, enable=True, view_mode=BasicLayer.RIGHT_VIEW,style_info=style_info2)
|
||||||
self.main_l1.set_layer_parent(self)
|
self.main_l1.set_layer_parent(self)
|
||||||
self.main_l2.set_layer_parent(self)
|
self.main_l2.set_layer_parent(self)
|
||||||
self.grid = None
|
self.grid = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user