fix filter bugs
change table layer action
This commit is contained in:
parent
848c720435
commit
398fb21cb0
@ -43,8 +43,8 @@ class RateSetdialog(QDialog):
|
||||
self.cancel_button.clicked.connect(self.on_cancel)
|
||||
self.cancel_button.setDefault(False)
|
||||
self.buttonbox=QDialogButtonBox(self)
|
||||
self.buttonbox.addButton(self.ok_button,QDialogButtonBox.NoRole)
|
||||
self.buttonbox.addButton(self.cancel_button,QDialogButtonBox.NoRole)
|
||||
self.buttonbox.addButton(self.ok_button,QDialogButtonBox.Ok)
|
||||
self.buttonbox.addButton(self.cancel_button,QDialogButtonBox.Cancel)
|
||||
self.buttonbox.setCenterButtons(True)
|
||||
vlayout=QVBoxLayout()
|
||||
vlayout.addLayout(h1)
|
||||
@ -53,7 +53,7 @@ class RateSetdialog(QDialog):
|
||||
vlayout.addWidget(self.buttonbox)
|
||||
self.setLayout(vlayout)
|
||||
|
||||
self.old_data = None
|
||||
# self.old_data = None
|
||||
|
||||
def on_ok(self):
|
||||
self.onclose()
|
||||
@ -67,12 +67,14 @@ class RateSetdialog(QDialog):
|
||||
|
||||
def onclose(self) -> None:
|
||||
if self.layer_select.current_layer is not None:
|
||||
self.layer_select.current_layer.th = self.slider.value()
|
||||
self.layer_select.current_layer.save()
|
||||
|
||||
|
||||
def closeEvent(self, a0) -> None:
|
||||
if self.layer_select.current_layer is not None:
|
||||
self.layer_select.current_layer.data = self.layer_select.current_layer.old_data
|
||||
self.layer_select.current_layer.update_point_layer(-1)
|
||||
# def closeEvent(self, a0) -> None:
|
||||
# if self.layer_select.current_layer is not None:
|
||||
# self.layer_select.current_layer.data = self.layer_select.current_layer.old_data
|
||||
# self.layer_select.current_layer.update_point_layer(-1)
|
||||
|
||||
|
||||
class RateSetPlugin(BasicPlugin):
|
||||
@ -111,6 +113,7 @@ class RateSetPlugin(BasicPlugin):
|
||||
return
|
||||
data=layer.data.copy()
|
||||
# print(input)
|
||||
|
||||
data[np.where(data[:,-2]<(input)),-1]=0
|
||||
data[np.where(data[:,-2]>(input)),-1]=1
|
||||
layer.data=data
|
||||
|
@ -65,7 +65,7 @@ class FilterMethod(QDialog):
|
||||
|
||||
class MainPlugin(BasicPlugin):
|
||||
|
||||
alg_ok = pyqtSignal(PairLayer, RasterLayer)
|
||||
alg_ok = pyqtSignal(PairLayer, str)
|
||||
|
||||
@staticmethod
|
||||
def info():
|
||||
@ -94,22 +94,24 @@ class MainPlugin(BasicPlugin):
|
||||
# # self.action.setChecked(False)
|
||||
# self.action.triggered.connect(self.run)
|
||||
# ActionManager().filter_menu.addAction(self.action)
|
||||
# self.alg_ok.connect(self.alg_oked)
|
||||
self.alg_ok.connect(self.alg_oked)
|
||||
# basic
|
||||
|
||||
def alg_oked(self, parent, layer:RasterLayer):
|
||||
parent.add_result_layer(layer)
|
||||
def alg_oked(self, layer, outpath):
|
||||
rlayer = RasterLayer(path = outpath, enable= True, view_mode = layer.view_mode )
|
||||
layer.layer_parent.add_result_layer(rlayer)
|
||||
|
||||
def run_alg(self, layer:RasterLayer, alg:AlgFrontend, p):
|
||||
|
||||
pth = layer.path
|
||||
if pth is None:
|
||||
return
|
||||
out_path = alg.run_alg(pth, **p)
|
||||
out_path = alg.run_alg(pth, **p, send_message=self.send_message)
|
||||
self.send_message.emit('滤波完成')
|
||||
self.send_message.emit('结果在:'+out_path)
|
||||
|
||||
|
||||
rlayer = RasterLayer(path = out_path, enable= True, view_mode = layer.view_mode )
|
||||
|
||||
self.alg_ok.emit(layer.layer_parent, rlayer)
|
||||
self.alg_ok.emit(layer, out_path)
|
||||
|
||||
def run(self, key):
|
||||
if key not in FILTER:
|
||||
|
@ -5,8 +5,10 @@ from osgeo import gdal
|
||||
from rscder.utils.project import Project
|
||||
import os
|
||||
from rscder.utils.project import BasicLayer, ResultPointLayer
|
||||
from misc.utils import format_now
|
||||
|
||||
def table_layer(pth:str,layer:BasicLayer, name, send_message = None):
|
||||
def table_layer(pth:str,layer:BasicLayer, name, cdpath=None,
|
||||
th=0, method_info=dict(), send_message = None):
|
||||
if send_message is not None:
|
||||
send_message.emit('正在计算表格结果...')
|
||||
cell_size = layer.layer_parent.cell_size
|
||||
@ -15,7 +17,7 @@ def table_layer(pth:str,layer:BasicLayer, name, send_message = None):
|
||||
ysize = ds.RasterYSize
|
||||
geo = ds.GetGeoTransform()
|
||||
|
||||
out_csv = os.path.join(Project().other_path, f'{name}_table_result_{ int(datetime.now().timestamp() * 1000) }.csv')
|
||||
out_csv = os.path.join(Project().other_path, f'{name}_table_result_{ format_now() }.csv')
|
||||
yblocks = ysize // cell_size[1] + 1
|
||||
xblocks = xsize // cell_size[0] + 1
|
||||
with open(out_csv, 'w') as f:
|
||||
@ -39,7 +41,8 @@ def table_layer(pth:str,layer:BasicLayer, name, send_message = None):
|
||||
center_y = center_y * geo[5] + geo [3]
|
||||
f.write(f'{center_x},{center_y},{block_data_xy.mean() * 100},{int(block_data_xy.mean() > 0.5)}\n')
|
||||
|
||||
result_layer = ResultPointLayer(out_csv, enable=True, proj=layer.proj, geo=layer.geo,result_path=dict(path=pth))
|
||||
result_layer = ResultPointLayer(out_csv, enable=True, proj=layer.proj, geo=layer.geo,result_path=dict(path=pth, cmi=cdpath),
|
||||
th=th, method_info=method_info, load=True)
|
||||
# print(result_layer.result_path)
|
||||
layer.layer_parent.add_result_layer(result_layer)
|
||||
if send_message is not None:
|
||||
|
@ -2,6 +2,11 @@ import os
|
||||
import random
|
||||
import logging
|
||||
# def generate_temp_file
|
||||
import datetime
|
||||
|
||||
def format_now():
|
||||
|
||||
datetime.datetime.now().strftime('')
|
||||
|
||||
class Register:
|
||||
|
||||
|
@ -78,7 +78,7 @@ class ManulGapAlg(AlgFrontend):
|
||||
ds = None
|
||||
if send_message is not None:
|
||||
send_message.emit('自定义阈值分割完成')
|
||||
return out_th
|
||||
return out_th, gap
|
||||
|
||||
|
||||
import numpy as np
|
||||
@ -174,5 +174,5 @@ class OTSUAlg(AlgFrontend):
|
||||
ds = None
|
||||
send_message.emit('OTSU阈值完成')
|
||||
|
||||
return out_th
|
||||
return out_th, gap
|
||||
# ManulGapAlg.run_alg
|
@ -12,7 +12,7 @@ from .scripts import UNSUPER_CD
|
||||
from thres import THRES
|
||||
from misc import table_layer, AlgSelectWidget
|
||||
from follow import FOLLOW
|
||||
|
||||
import os
|
||||
class UnsupervisedCDMethod(QDialog):
|
||||
def __init__(self,parent=None, alg:AlgFrontend=None):
|
||||
super(UnsupervisedCDMethod, self).__init__(parent)
|
||||
@ -146,18 +146,31 @@ class UnsupervisedCDFollow(AlgFrontend):
|
||||
return
|
||||
|
||||
name = layer1.name
|
||||
|
||||
method_info = dict()
|
||||
if falg is not None:
|
||||
pth1 = falg.run_alg(pth1, name=name, send_message= send_message, **fparams)
|
||||
pth2 = falg.run_alg(pth2, name=name, send_message= send_message, **fparams)
|
||||
|
||||
method_info['滤波算法'] = falg.get_name()
|
||||
else:
|
||||
method_info['滤波算法'] = '无'
|
||||
|
||||
cdpth = cdalg.run_alg(pth1, pth2, layer1.layer_parent, send_message= send_message,**cdparams)
|
||||
thpth = thalg.run_alg(cdpth, name=name, send_message= send_message, **thparams)
|
||||
|
||||
if falg is not None:
|
||||
try:
|
||||
os.remove(pth1)
|
||||
os.remove(pth2)
|
||||
# send_message.emit('删除临时文件')
|
||||
except:
|
||||
# send_message.emit('删除临时文件失败!')
|
||||
pass
|
||||
|
||||
table_layer(thpth,layer1,name, send_message)
|
||||
thpth, th = thalg.run_alg(cdpth, name=name, send_message= send_message, **thparams)
|
||||
|
||||
method_info['变化检测算法'] = cdalg.get_name()
|
||||
method_info['二值化算法'] = thalg.get_name()
|
||||
|
||||
table_layer(thpth,layer1,name, cdpath=cdpth, th=th, method_info=method_info, send_message = send_message)
|
||||
|
||||
|
||||
class UnsupervisedPlugin(BasicPlugin):
|
||||
@ -192,7 +205,7 @@ class UnsupervisedPlugin(BasicPlugin):
|
||||
|
||||
|
||||
def run_cd(self, alg):
|
||||
print(alg.get_name())
|
||||
# print(alg.get_name())
|
||||
dialog = UnsupervisedCDMethod(self.mainwindow, alg)
|
||||
dialog.show()
|
||||
|
||||
@ -214,14 +227,30 @@ class UnsupervisedPlugin(BasicPlugin):
|
||||
|
||||
if cdalg is None or thalg is None:
|
||||
return
|
||||
|
||||
method_info = dict()
|
||||
if falg is not None:
|
||||
pth1 = falg.run_alg(pth1, name=name, send_message=self.send_message, **fparams)
|
||||
pth2 = falg.run_alg(pth2, name=name, send_message=self.send_message, **fparams)
|
||||
|
||||
method_info['滤波算法'] = falg.get_name()
|
||||
else:
|
||||
method_info['滤波算法'] = '无'
|
||||
|
||||
cdpth = cdalg.run_alg(pth1, pth2, layer1.layer_parent, send_message=self.send_message,**cdparams)
|
||||
thpth = thalg.run_alg(cdpth, name=name, send_message=self.send_message, **thparams)
|
||||
|
||||
table_layer(thpth,layer1,name,self.send_message)
|
||||
if falg is not None:
|
||||
try:
|
||||
os.remove(pth1)
|
||||
os.remove(pth2)
|
||||
# send_message.emit('删除临时文件')
|
||||
except:
|
||||
# send_message.emit('删除临时文件失败!')
|
||||
pass
|
||||
|
||||
thpth, th = thalg.run_alg(cdpth, name=name, send_message=self.send_message, **thparams)
|
||||
|
||||
method_info['变化检测算法'] = cdalg.get_name()
|
||||
method_info['二值化算法'] = thalg.get_name()
|
||||
|
||||
table_layer(thpth,layer1,name, cdpath=cdpth, th=th, method_info=method_info, send_message = self.send_message)
|
||||
# table_layer(thpth,layer1,name,self.send_message)
|
||||
|
@ -175,7 +175,7 @@ class loader(QDialog):
|
||||
path1 = QFileDialog.getOpenFileNames(self, '打开数据1', Settings.General().last_path, '*.*')
|
||||
if path1[0]!='':
|
||||
try:
|
||||
|
||||
Settings.General().last_path = path1[0][0]
|
||||
self.path1 = path1[0][0]
|
||||
self.path1_input.setText(self.path1)
|
||||
result=QMessageBox.question(self, '提示', '是否创建图像金字塔', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) #默认关闭界面选择No
|
||||
@ -210,7 +210,7 @@ class loader(QDialog):
|
||||
def open_file2(self):
|
||||
path2 = QFileDialog.getOpenFileNames(self, '打开数据2', Settings.General().last_path, '*.*')
|
||||
if path2[0]!='':
|
||||
|
||||
Settings.General().last_path = path2[0][0]
|
||||
self.path2 = path2[0][0]
|
||||
self.path2_input.setText(self.path2)
|
||||
result=QMessageBox.question(self, '提示', '是否创建图像金字塔', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) #默认关闭界面选择No
|
||||
|
@ -213,6 +213,8 @@ class Project(QObject):
|
||||
return pth
|
||||
|
||||
def add_layer(self, pth1, pth2,style_info1,style_info2):
|
||||
if not self.is_init:
|
||||
self.setup(Settings.General().root, 'default')
|
||||
player = PairLayer(pth1, pth2,style_info1,style_info2)
|
||||
if player.check():
|
||||
self.layers[player.id] = player
|
||||
@ -336,7 +338,7 @@ class BasicLayer(QObject):
|
||||
show_info.triggered.connect(lambda :showIofn(self.info))
|
||||
return actions
|
||||
|
||||
return actions
|
||||
# return actions
|
||||
@property
|
||||
def info(self):
|
||||
return None
|
||||
@ -599,7 +601,12 @@ class VectorLayer(BasicLayer):
|
||||
|
||||
class ResultPointLayer(BasicLayer):
|
||||
|
||||
def __init__(self, path, name=None, enable = False, proj = None, geo = None,result_path={},dsort=False):
|
||||
def __init__(self, path, name=None, enable = False, proj = None, geo = None,
|
||||
th=0.5,
|
||||
render_info=dict(font_color='#FF0000', font_size=100, font_name='Times New Roman', color='#ffff00', point_size=2),
|
||||
method_info=dict(),
|
||||
result_path={},dsort=False,
|
||||
load = False):
|
||||
if name is None:
|
||||
name = os.path.splitext(os.path.basename(path))[0]
|
||||
super().__init__(name, enable, icon=IconInstance().VECTOR, path=path, path_mode = BasicLayer.IN_FILE, view_mode=BasicLayer.BOATH_VIEW )
|
||||
@ -608,8 +615,13 @@ class ResultPointLayer(BasicLayer):
|
||||
self.geo = geo
|
||||
self.dsort=dsort
|
||||
self.result_path:dict=result_path
|
||||
self.render_info = render_info
|
||||
self.method_info = method_info
|
||||
self.th = th
|
||||
self.load = load
|
||||
if self.load:
|
||||
# self.methods=
|
||||
self.load_point_file()
|
||||
self.load_point_file()
|
||||
|
||||
def save(self):
|
||||
|
||||
@ -618,7 +630,6 @@ class ResultPointLayer(BasicLayer):
|
||||
for i in range(len(self.data)):
|
||||
f.write('{},{},{},{}\n'.format(self.data[i][0], self.data[i][1], self.data[i][2], int(self.data[i][3])))
|
||||
|
||||
|
||||
def update(self, data):
|
||||
row = data['row']
|
||||
value = data['value']
|
||||
@ -632,7 +643,7 @@ class ResultPointLayer(BasicLayer):
|
||||
lyr.fieldName = 'prob'
|
||||
lyr.placement = QgsPalLayerSettings.OverPoint
|
||||
|
||||
lyr.textFont = QFont('Times New Roman', 100)
|
||||
lyr.textFont = QFont(self.render_info['font_name'], self.render_info['font_size'])
|
||||
text_format = QgsTextFormat()
|
||||
text_format.setFont(lyr.textFont)
|
||||
if self.geo is None:
|
||||
@ -641,9 +652,9 @@ class ResultPointLayer(BasicLayer):
|
||||
res = self.geo[1]
|
||||
# lyr.xOffset = 25 * res
|
||||
# lyr.yOffset = -2 * res
|
||||
text_format.setSize(50 * res)
|
||||
text_format.setSize(self.render_info['font_size'] * res)
|
||||
text_format.setSizeUnit(QgsUnitTypes.RenderMapUnits)
|
||||
text_format.setColor(QColor('#FF0000'))
|
||||
text_format.setColor(QColor(self.render_info['font_color']))
|
||||
# text_format.background().color = QColor('#000000')
|
||||
text_format.buffer().setEnabled(True)
|
||||
text_format.buffer().setSize(1)
|
||||
@ -659,7 +670,7 @@ class ResultPointLayer(BasicLayer):
|
||||
|
||||
def set_render(self, layer):
|
||||
# xres = self.geo[1]
|
||||
symbol_change = QgsMarkerSymbol.createSimple({'color': '#ffff00', 'size': 2 })
|
||||
symbol_change = QgsMarkerSymbol.createSimple({'color': self.render_info['color'], 'size': self.render_info['point_size'] })
|
||||
symbol_change.setSizeUnit(QgsUnitTypes.RenderUnit.RenderMillimeters)
|
||||
category_change = QgsRendererCategory(1, symbol_change,'change')
|
||||
|
||||
@ -670,6 +681,7 @@ class ResultPointLayer(BasicLayer):
|
||||
layer.setRenderer(render)
|
||||
|
||||
def load_point_file(self):
|
||||
self.load = True
|
||||
data = np.loadtxt(self.path, delimiter=',', skiprows=1)
|
||||
if data is None:
|
||||
return
|
||||
@ -763,15 +775,16 @@ class ResultPointLayer(BasicLayer):
|
||||
basic['文件路径']=self.path
|
||||
|
||||
#中间算法信息:
|
||||
methods={ k:v[0] for k ,v in self.result_path.items()}
|
||||
methods={ k:v for k ,v in self.method_info.items()}
|
||||
basic['变化检测算法']=methods
|
||||
#渲染信息
|
||||
render={}
|
||||
render['标注字体大小']=2
|
||||
render['标注颜色']='#ffff00'
|
||||
render['阈值']=self.result_path['后处理'][1]
|
||||
render['标注字体大小']=self.render_info['font_size']
|
||||
render['标注颜色']=self.render_info['font_color']
|
||||
render['阈值']=self.th
|
||||
|
||||
return {'基础属性':basic,'渲染属性':render}
|
||||
|
||||
class PairLayer(BasicLayer):
|
||||
|
||||
def __init__(self, pth1, pth2,style_info1,style_info2,mask=None) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user