1# -*- coding: utf-8 -*-

2"""

3/***************************************************************************

4 FillSinkDialog

5 A QGIS plugin

6 FillSink plug-in

7 -------------------

8 begin : 2017-03-13

9 git sha : $Format:%H$

10 copyright : (C) 2017 by Hermesys

11 email : shpark@hermesys.co.kr

12 ***************************************************************************/

13

14/***************************************************************************

15 * *

16 * This program is free software; you can redistribute it and/or modify *

17 * it under the terms of the GNU General Public License as published by *

18 * the Free Software Foundation; either version 2 of the License, or *

19 * (at your option) any later version. *

20 * *

21 ***************************************************************************/

22"""

23 import os

24 import tempfile

25 import xml.etree.ElementTree as ET

26

27 from qgis.core import QgsProject

28 from qgis.PyQt.QtCore import QRect, Qt

29 from qgis.PyQt.QtGui import QPixmap

30 from qgis.PyQt.QtWidgets import (

31 QAbstractItemView,

32 QDialog,

33 QFileDialog,

34 QLineEdit,

35 QMessageBox,

36 QTableWidget,

37 QTableWidgetItem,

38)

39

40 from grm.lib.File_Class import ChFile_Exists, GetFile_Name

41 from grm.lib.Util import (

42 GetcomboSelectedLayerPath,

43 MsError,

44 MsInfo,

45 SetCommbox,

46 SetCommbox2,

47 error_decorator,

48)

49 from grm.lib.xmltodict import parse, unparse

50 from grm.ui.LandCover_dialog_base import Ui_Dialog

51

52

53 class LandCoverDialog(QDialog, Ui_Dialog):

54 def __init__(

55 self,

56 _xmltodic={},

57 _LandCoverCount=0,

58 _GreenAmptCount=0,

59 _SoilDepthCount=0,

60 _grmDialogFlag=0,

61 parent=None,

62 ):

63 super(LandCoverDialog, self).__init__(parent)

64 self.setupUi(self)

65 # 프로젝트 XML to dic 자료 받아서 전역 변수 셋팅

66 self._xmltodict = _xmltodic

67 self._LandCoverCount = _LandCoverCount

68 self._GreenAmptCount = _GreenAmptCount

69 self._SoilDepthCount = _SoilDepthCount

70 self._grmDialogFlag = _grmDialogFlag # Setup / Run GRM 창 실행 중인지 확인

71 self.StaticDB = (

72 os.path.dirname(os.path.realpath(__file__)) + "\..\DLL\GRMStaticDB.xml"

73 )

74

75 print("self._grmDialogFlag :: " + str(self._grmDialogFlag))

76

77 # 초기에 각각의 컨트롤 들의 기본값을 셋팅

78 self.InitControls()

79

80 # 각각의 컨트롤 들을 초기 값이나 설정을 셋팅

81 def InitControls(self):

82 self.btnCancel.clicked.connect(self.closeForm)

83

84 # 확인버튼을 눌렀을 때

85 self.btnOK.clicked.connect(self.OKForm)

86

87 # 초기 모든 변수값 셋팅

88 self.SetProjectValue()

89

90 # 콤보 박스에 레이어 목록 적용 값 셋팅

91 self.SetLayerListCombobox()

92

93 # 라디오 버튼 셋팅

94 self.SetRadio()

95

96 # 테이블 헤더 설정

97 self.SetTableHeader()

98

99 # 각각의 테이블에 데이터 값 읽어서 넣기

100 # 1순위 - 프로젝트 파일 데이터

101 # 2순위 - 프로젝트 파일 내에 Vat 파일 경로

102 self.SetTableData()

103 self.tlbLandCover.cellDoubleClicked.connect(

104 lambda: self.aboutApp("LandCover", self.tlbLandCover.currentRow())

105 )

106 self.tblGreenAmpt.cellDoubleClicked.connect(

107 lambda: self.aboutApp("GreenAmpt", self.tblGreenAmpt.currentRow())

108 )

109 self.tblSoilDepth.cellDoubleClicked.connect(

110 lambda: self.aboutApp("SoilDepth", self.tblSoilDepth.currentRow())

111 )

112

113 # 콤보 박스 변경시 선택된 콤보 박스 레이어 목록으로 Table 셋팅

114 self.cmbLandCover.activated.connect(

115 lambda: self.Get_ComboBox_LayerPath(

116 self.cmbLandCover, self.tlbLandCover, self.txtLandCover, "LandCover"

117 )

118 )

119 self.cmbSoilTexture.activated.connect(

120 lambda: self.Get_ComboBox_LayerPath(

121 self.cmbSoilTexture, self.tblGreenAmpt, self.txtSoilTexture, "GreenAmpt"

122 )

123 )

124 self.cmbSoilDepth.activated.connect(

125 lambda: self.Get_ComboBox_LayerPath(

126 self.cmbSoilDepth, self.tblSoilDepth, self.txtSoilDepth, "SoilDepth"

127 )

128 )

129

130 # Vat 선택 버튼 클릭 이벤트(서택된 파일로 테이블값이 변경 됨)

131 self.btnVatLand.clicked.connect(

132 lambda: self.SelectVat("btnVatLand", self.txtLandCover)

133 )

134 self.btnVatAmpt.clicked.connect(

135 lambda: self.SelectVat("btnVatAmpt", self.txtSoilTexture)

136 )

137 self.btnVatDepth.clicked.connect(

138 lambda: self.SelectVat("btnVatDepth", self.txtSoilDepth)

139 )

140

141 self.btn_LAI_file.clicked.connect(

142 lambda is_checked: self.select_txt_file(self.path_LAI_file)

143 )

144 self.btn_bianey_criddle_coet.clicked.connect(

145 lambda is_checked: self.select_txt_file(self.path_blaney_criddle_coet)

146 )

147

148 # 사용자가 VAT 파일 바꿀때 테이블 값도 바뀌어서 적용

149 def SelectVat(self, button, txtbox):

150 try:

151 dir = os.path.dirname(txtbox.text())

152 filename = QFileDialog.getOpenFileName(

153 self, "select output file ", dir, "*.vat"

154 )[0]

155 if filename:

156 txtbox.setText(filename)

157 if button == "btnVatLand":

158 self.SetVATValue(

159 self.txtLandCover.text(), self.tlbLandCover, "LandCover"

160 )

161 elif button == "btnVatAmpt":

162 self.SetVATValue(

163 self.txtSoilTexture.text(), self.tblGreenAmpt, "GreenAmpt"

164 )

165 elif button == "btnVatDepth":

166 self.SetVATValue(

167 self.txtSoilDepth.text(), self.tblSoilDepth, "SoilDepth"

168 )

169 except Exception as e:

170 MsError(e)

171

172 @error_decorator

173 def select_txt_file(self, txtbox: QLineEdit):

174 dir = os.path.dirname(txtbox.text())

175 filename = QFileDialog.getOpenFileName(

176 self, "select output file ", dir, "*.txt"

177 )[0]

178 if filename:

179 txtbox.setText(filename)

180

181 def Get_ComboBox_LayerPath(self, combox, table, txt, type):

182 try:

183 if combox.currentIndex() != 0:

184 self.layerPath = (

185 GetcomboSelectedLayerPath(combox)

186 .lower()

187 .replace(".asc", ".vat")

188 .replace(".tif", ".vat")

189 )

190

191 if ChFile_Exists(self.layerPath):

192 txt.setText(str(self.layerPath))

193 self.SetVATValue(self.layerPath, table, type)

194 except Exception as e:

195 MsError(e)

196

197 def OKForm(self):

198 if self.rbtUseLCLayer.isChecked():

199 if self.cmbLandCover.currentIndex() == 0:

200 MsInfo(" layer is not selected ")

201 self.cmbLandCover.setFocus()

202 return

203

204 if self.txtLandCover.text() == "":

205 MsInfo("The VAT file is not selected.")

206 self.txtLandCover.setFocus()

207 return

208

209 if self.rbtUseSoilTextureLayer.isChecked():

210 if self.cmbSoilTexture.currentIndex() == 0:

211 MsInfo(" layer is not selected ")

212 self.cmbSoilTexture.setFocus()

213 return

214

215 if self.txtSoilTexture.text() == "":

216 MsInfo("The VAT file is not selected.")

217 self.txtSoilTexture.setFocus()

218 return

219

220 if self.rbtUseSoilDepthLayer.isChecked():

221 if self.cmbSoilDepth.currentIndex() == 0:

222 MsInfo(" layer is not selected ")

223 self.cmbSoilDepth.setFocus()

224 return

225

226 if self.txtSoilDepth.text() == "":

227 MsInfo("The VAT file is not selected.")

228 self.txtSoilDepth.setFocus()

229 return

230

231 # 1. 라디오 rbtUseConstLCAtt

232 if self.rbtUseConstLCAtt.isChecked():

233 if self.Checktxtbox(self.txtCoefficient):

234 result = float(self.txtCoefficient.text())

235 if not (0.0015 <= result and result <= 1.5):

236 MsInfo(

237 "{0}\n{1}".format(

238 "[Land cover roughness coefficient] is invalid.",

239 "0.0015<=Land cover roughness coefficient<=1.5",

240 )

241 )

242 self.txtCoefficient.setFocus()

243 return

244 else:

245 MsInfo(

246 "{0}\n{1}".format(

247 "[Land cover roughness coefficient] is invalid.",

248 "0.0015<=Land cover roughness coefficient<=1.5",

249 )

250 )

251 self.txtCoefficient.setFocus()

252 return

253

254 if self.Checktxtbox(self.txtImpervious):

255 result = float(self.txtImpervious.text())

256 if not (0 <= result and result <= 1):

257 MsInfo("[Impervious ratio] is invalid. \n0<=Impervious ration<=1")

258 self.txtImpervious.setFocus()

259 return

260 else:

261 MsInfo("[Impervious ratio] is invalid. \n0<=Impervious ration<=1")

262 self.txtImpervious.setFocus()

263 return

264

265 # 2. rbtUseConstTextureAtt 선택 시,

266 if self.rbtUseConstTextureAtt.isChecked():

267 if self.Checktxtbox(self.txtPorosity):

268 result = float(self.txtPorosity.text())

269 if not (0 <= result and result <= 1):

270 MsInfo("[Porosity] is invalid. \n0<=Porosity<=1")

271 self.txtPorosity.setFocus()

272 return

273 else:

274 MsInfo("[Porosity] is invalid. \n0<=Porosity<=1")

275 self.txtPorosity.setFocus()

276 return

277

278 if self.Checktxtbox(self.txtEffective_porosity):

279 result = float(self.txtEffective_porosity.text())

280 if not (0 <= result and result <= 1):

281 MsInfo(

282 "[Effective poropsity] is invalid. \n0<=Effective porosity<=1"

283 )

284 self.txtEffective_porosity.setFocus()

285 return

286 else:

287 MsInfo("[Effective poropsity] is invalid. \n0<=Effective porosity<=1")

288 self.txtEffective_porosity.setFocus()

289 return

290

291 if self.Checktxtbox(self.txtSuction_head):

292 result = float(self.txtSuction_head.text())

293 if not (0 <= result and result <= 9999):

294 MsInfo(

295 "[Wetting front suction head] is invalid. \n0<=Wetting front suction head<=9999"

296 )

297 self.txtSuction_head.setFocus()

298 return

299 else:

300 MsInfo(

301 "[Wetting front suction head] is invalid. \n0<=Wetting front suction head<=9999"

302 )

303 self.txtSuction_head.setFocus()

304 return

305

306 if self.Checktxtbox(self.txtConductiovity):

307 result = float(self.txtConductiovity.text())

308 if not (0 <= result and result <= 1):

309 MsInfo(

310 "[Hydraulic conductivity] is invalid. \n0<=Hydraulic conductivity<=1"

311 )

312 self.txtConductiovity.setFocus()

313 return

314 else:

315 MsInfo(

316 "[Hydraulic conductivity] is invalid. \n0<=Hydraulic conductivity<=1"

317 )

318 self.txtConductiovity.setFocus()

319 return

320

321 # 3.rbtUseConstDepth 체크

322 if self.rbtUseConstDepth.isChecked():

323 if self.Checktxtbox(self.txtSoil_depth):

324 result = float(self.txtSoil_depth.text())

325 if not (0 <= result and result <= 9999):

326 MsInfo("[Soil Depth] is invalid.\n0<=Soil Depth<=9999")

327 self.txtSoil_depth.setFocus()

328 return

329 else:

330 MsInfo("[Soil Depth] is invalid.\n0<=Soil Depth<=9999")

331 self.txtSoil_depth.setFocus()

332 return

333

334 # GMP 파일에 Lanccover,depth.. xml 생성

335 self.DataSave()

336 # _util.MessageboxShowInfo("Land cover / soil", "Land covers and soil attributes setup are completed.")

337

338 quit_msg = " Land covers and soil attributes setup are completed. "

339 reply = QMessageBox.information(

340 self, "Land cover / soil", quit_msg, QMessageBox.Ok

341 )

342 if reply == QMessageBox.Ok:

343 self.close()

344

345 # QlineEdit 값 체크

346 def Checktxtbox(self, textbox):

347 if textbox.text() != "" and self.isFloat(textbox.text()):

348 return True

349 else:

350 return False

351

352 # Vat 파일에서 읽어 와서 테이블에 값셋팅 하기

353 def SetVATValue(self, path, table, type):

354 try:

355 if path != "":

356 temOutput = tempfile.mktemp() + ".txt"

357 # fileObj = codecs.open( path, "r", "utf-8" )

358 # lines = fileObj.readlines()

359 try:

360 with open(path, "r", encoding="cp949") as f:

361 lines = f.readlines()

362 except Exception as e:

363 with open(path, "r", encoding="utf-8") as f:

364 lines = f.readlines()

365

366 # 테이블 초기화

367 table.clear()

368 if type == "LandCover":

369 table.setColumnCount(7)

370 table.setHorizontalHeaderLabels(

371 [

372 "GridValue",

373 "UserLandCover",

374 "GRMCode",

375 "RoughnessCoefficient",

376 "ImperviousRatio",

377 "CanopyRatio",

378 "InterceptionMaxWaterCanopy_mm",

379 ]

380 )

381

382 elif type == "GreenAmpt":

383 table.setColumnCount(7)

384 table.setHorizontalHeaderLabels(

385 [

386 "GridValue",

387 "USERSoil",

388 "GRMCode",

389 "Porosity",

390 "EffectivePorosity",

391 "WFSoilSuctionHead",

392 "HydraulicConductivity",

393 ]

394 )

395 elif type == "SoilDepth":

396 table.setColumnCount(4)

397 table.setHorizontalHeaderLabels(

398 ["GridValue", "UserDepthClass", "GRMCode", "SoilDepth"]

399 )

400 table.setRowCount(int(len(lines)))

401

402 # Table에 데이터 값 대입

403 for i in range(0, len(lines)):

404 if lines[i] is not None and lines[i] != "":

405 splitsdata = lines[i].split(",")

406 # item1 = QTableWidgetItem(splitsdata[0])

407 item1 = QTableWidgetItem(splitsdata[0])

408 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

409 table.setItem(i, 0, QTableWidgetItem(item1))

410 item2 = QTableWidgetItem(splitsdata[1])

411 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

412 table.setItem(i, 1, QTableWidgetItem(item2))

413

414 txtvalue = splitsdata[1]

415 if txtvalue.upper() == "USER":

416 user = True

417 else:

418 user = False

419 self.SetMainTableValue(

420 splitsdata[1].strip(), table, (i), type, user

421 )

422 except Exception as es:

423 MsError(es)

424

425 # 메인창 Land cover tablewidget 테이블에 데이터 셋팅 (3~ 이후 컬럼의 데이터 값을 StaticDB 셋팅)

426 def SetMainTableValue(self, value, widget, row, type, user):

427 doc = ET.parse(self.StaticDB)

428 root = doc.getroot()

429 if type == "LandCover":

430 for element in root.findall(

431 "{http://tempuri.org/DataSet1.xsd}LandCoverParameter"

432 ):

433 if user:

434 item1 = QTableWidgetItem(

435 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

436 )

437 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

438 widget.setItem(row, 2, QTableWidgetItem("USER"))

439 widget.setItem(row, 3, QTableWidgetItem(""))

440 widget.setItem(row, 4, QTableWidgetItem(""))

441 widget.setItem(row, 5, QTableWidgetItem(""))

442 widget.setItem(row, 6, QTableWidgetItem(""))

443 break

444 else:

445 if (

446 element.findtext("{http://tempuri.org/DataSet1.xsd}LandCoverK")

447 == value

448 or element.findtext(

449 "{http://tempuri.org/DataSet1.xsd}LandCoverE"

450 )

451 == value

452 or element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

453 == value

454 ):

455 item1 = QTableWidgetItem(

456 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

457 )

458 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

459 widget.setItem(row, 2, QTableWidgetItem(item1))

460 widget.setItem(

461 row,

462 3,

463 QTableWidgetItem(

464 element.findtext(

465 "{http://tempuri.org/DataSet1.xsd}RoughnessCoefficient"

466 )

467 ),

468 )

469 widget.setItem(

470 row,

471 4,

472 QTableWidgetItem(

473 element.findtext(

474 "{http://tempuri.org/DataSet1.xsd}ImperviousRatio"

475 )

476 ),

477 )

478 widget.setItem(

479 row,

480 5,

481 QTableWidgetItem(

482 element.findtext(

483 "{http://tempuri.org/DataSet1.xsd}CanopyRatio"

484 )

485 ),

486 )

487 widget.setItem(

488 row,

489 6,

490 QTableWidgetItem(

491 element.findtext(

492 "{http://tempuri.org/DataSet1.xsd}InterceptionMaxWaterCanopy_mm"

493 )

494 ),

495 )

496 break

497

498 elif type == "GreenAmpt":

499 for element in root.findall(

500 "{http://tempuri.org/DataSet1.xsd}GreenAmptSoilParameter"

501 ):

502 if user:

503 item1 = QTableWidgetItem(

504 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

505 )

506 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

507 widget.setItem(row, 2, QTableWidgetItem("USER"))

508 widget.setItem(row, 3, QTableWidgetItem(""))

509 widget.setItem(row, 4, QTableWidgetItem(""))

510 widget.setItem(row, 5, QTableWidgetItem(""))

511 widget.setItem(row, 6, QTableWidgetItem(""))

512 else:

513 if (

514 element.findtext(

515 "{http://tempuri.org/DataSet1.xsd}SoilTextureK"

516 )

517 == value

518 ):

519 item1 = QTableWidgetItem(

520 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

521 )

522 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

523 widget.setItem(

524 row,

525 2,

526 QTableWidgetItem(

527 element.findtext(

528 "{http://tempuri.org/DataSet1.xsd}GRMCode"

529 )

530 ),

531 )

532 widget.setItem(

533 row,

534 3,

535 QTableWidgetItem(

536 element.findtext(

537 "{http://tempuri.org/DataSet1.xsd}PorosityDefault"

538 )

539 ),

540 )

541 widget.setItem(

542 row,

543 4,

544 QTableWidgetItem(

545 element.findtext(

546 "{http://tempuri.org/DataSet1.xsd}EffectivePorosityDefault"

547 )

548 ),

549 )

550 widget.setItem(

551 row,

552 5,

553 QTableWidgetItem(

554 element.findtext(

555 "{http://tempuri.org/DataSet1.xsd}WFSoilSuctionHeadDefault"

556 )

557 ),

558 )

559 widget.setItem(

560 row,

561 6,

562 QTableWidgetItem(

563 element.findtext(

564 "{http://tempuri.org/DataSet1.xsd}HydraulicConductivity"

565 )

566 ),

567 )

568 break

569

570 elif (

571 element.findtext(

572 "{http://tempuri.org/DataSet1.xsd}SoilTextureE"

573 )

574 == value

575 ):

576 item1 = QTableWidgetItem(

577 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

578 )

579 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

580 widget.setItem(

581 row,

582 2,

583 QTableWidgetItem(

584 element.findtext(

585 "{http://tempuri.org/DataSet1.xsd}GRMCode"

586 )

587 ),

588 )

589 widget.setItem(

590 row,

591 3,

592 QTableWidgetItem(

593 element.findtext(

594 "{http://tempuri.org/DataSet1.xsd}PorosityDefault"

595 )

596 ),

597 )

598 widget.setItem(

599 row,

600 4,

601 QTableWidgetItem(

602 element.findtext(

603 "{http://tempuri.org/DataSet1.xsd}EffectivePorosityDefault"

604 )

605 ),

606 )

607 widget.setItem(

608 row,

609 5,

610 QTableWidgetItem(

611 element.findtext(

612 "{http://tempuri.org/DataSet1.xsd}WFSoilSuctionHeadDefault"

613 )

614 ),

615 )

616 widget.setItem(

617 row,

618 6,

619 QTableWidgetItem(

620 element.findtext(

621 "{http://tempuri.org/DataSet1.xsd}HydraulicConductivity"

622 )

623 ),

624 )

625 break

626

627 elif (

628 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

629 == value

630 ):

631 item1 = QTableWidgetItem(

632 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

633 )

634 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

635 widget.setItem(

636 row,

637 2,

638 QTableWidgetItem(

639 element.findtext(

640 "{http://tempuri.org/DataSet1.xsd}GRMCode"

641 )

642 ),

643 )

644 widget.setItem(

645 row,

646 3,

647 QTableWidgetItem(

648 element.findtext(

649 "{http://tempuri.org/DataSet1.xsd}PorosityDefault"

650 )

651 ),

652 )

653 widget.setItem(

654 row,

655 4,

656 QTableWidgetItem(

657 element.findtext(

658 "{http://tempuri.org/DataSet1.xsd}EffectivePorosityDefault"

659 )

660 ),

661 )

662 widget.setItem(

663 row,

664 5,

665 QTableWidgetItem(

666 element.findtext(

667 "{http://tempuri.org/DataSet1.xsd}WFSoilSuctionHeadDefault"

668 )

669 ),

670 )

671 widget.setItem(

672 row,

673 6,

674 QTableWidgetItem(

675 element.findtext(

676 "{http://tempuri.org/DataSet1.xsd}HydraulicConductivity"

677 )

678 ),

679 )

680 break

681

682 elif type == "SoilDepth":

683 for element in root.findall(

684 "{http://tempuri.org/DataSet1.xsd}SoilDepthParameter"

685 ):

686 if user:

687 item1 = QTableWidgetItem(

688 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

689 )

690 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

691 widget.setItem(row, 2, QTableWidgetItem("USER"))

692 widget.setItem(row, 3, QTableWidgetItem(""))

693 break

694 else:

695 if (

696 element.findtext(

697 "{http://tempuri.org/DataSet1.xsd}SoilDepthClassK"

698 )

699 == value

700 ):

701 item1 = QTableWidgetItem(

702 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

703 )

704 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

705 widget.setItem(row, 2, QTableWidgetItem(item1))

706 widget.setItem(

707 row,

708 3,

709 QTableWidgetItem(

710 element.findtext(

711 "{http://tempuri.org/DataSet1.xsd}SoilDepthDefault"

712 )

713 ),

714 )

715 break

716 elif (

717 element.findtext(

718 "{http://tempuri.org/DataSet1.xsd}SoilDepthClassE"

719 )

720 == value

721 ):

722 item1 = QTableWidgetItem(

723 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

724 )

725 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

726 widget.setItem(row, 2, QTableWidgetItem(item1))

727 widget.setItem(

728 row,

729 3,

730 QTableWidgetItem(

731 element.findtext(

732 "{http://tempuri.org/DataSet1.xsd}SoilDepthDefault"

733 )

734 ),

735 )

736 break

737 elif (

738 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

739 == value

740 ):

741 item1 = QTableWidgetItem(

742 element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode")

743 )

744 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

745 widget.setItem(row, 2, QTableWidgetItem(item1))

746 widget.setItem(

747 row,

748 3,

749 QTableWidgetItem(

750 element.findtext(

751 "{http://tempuri.org/DataSet1.xsd}SoilDepthDefault"

752 )

753 ),

754 )

755 break

756

757 def closeForm(self):

758 self.close() # 폼 종료

759

760 # 초기 모든 변수값 셋팅 (프로젝트 파일에서 값을 읽어서 초기 셋팅 값을 결정함)

761 def SetProjectValue(self):

762 self.LandCoverType = self._xmltodict["GRMProject"]["ProjectSettings"][

763 "LandCoverDataType"

764 ]

765 self.SoilTextureType = self._xmltodict["GRMProject"]["ProjectSettings"][

766 "SoilTextureDataType"

767 ]

768 self.SoilDepthType = self._xmltodict["GRMProject"]["ProjectSettings"][

769 "SoilDepthDataType"

770 ]

771

772 # 그룹 박스 타이틀 부분 공백 줄이기

773 self.grp1.setStyleSheet("QGroupBox{padding-top:15px;margin-top:-15px;}")

774 self.grp_2.setStyleSheet("QGroupBox{padding-top:15px;margin-top:-15px;}")

775 self.groupBox_3.setStyleSheet("QGroupBox{padding-top:15px;margin-top:-15px;}")

776 self.groupBox_4.setStyleSheet("QGroupBox{padding-top:15px;margin-top:-15px;}")

777 self.groupBox_5.setStyleSheet("QGroupBox{padding-top:15px;margin-top:-15px;}")

778 self.groupBox_6.setStyleSheet("QGroupBox{padding-top:15px;margin-top:-15px;}")

779

780 # 콤보 박스에 레이어 목록 넣어 두기

781 def SetLayerListCombobox(self):

782 # 콤보 박스 레이어 받아 오기 설정

783 layers = QgsProject.instance().mapLayers().values()

784

785 if self._grmDialogFlag == 1:

786 lly = list(layers)

787 remove_set = QgsProject.instance().mapLayersByName("WSFAlayerload")

788 layers = [i for i in lly if i not in remove_set]

789

790 SetCommbox(layers, self.cmbLandCover, "")

791 SetCommbox(layers, self.cmbSoilTexture, "")

792 SetCommbox(layers, self.cmbSoilDepth, "")

793

794 # 라디오 버튼 셋팅

795 def SetRadio(self):

796 try:

797 # Lanccover 첫번째 라디오 버튼 클릭 이벤트 처리

798 self.rbtUseLCLayer.clicked.connect(self.LCLaye_CheckedChanged)

799

800 # Lanccover 두번째 라디오 버튼 클릭 이벤트 처리

801 self.rbtUseConstLCAtt.clicked.connect(self.ConstLCAtt_CheckedChanged)

802

803 # SoilTexture 첫번째 라디오 버튼 클릭 이벤트 처리

804 self.rbtUseSoilTextureLayer.clicked.connect(

805 self.SoilTextureLayer_CheckedChanged

806 )

807

808 # SoilTexture 두번째 라디오 버튼 클릭 이벤트 처리

809 self.rbtUseConstTextureAtt.clicked.connect(self.TextureAtt_CheckedChanged)

810

811 # SoilDepth 첫번째 라디오 버튼 클릭 이벤트 처리

812 self.rbtUseSoilDepthLayer.clicked.connect(

813 self.SoilDepthLayer_CheckedChanged

814 )

815

816 # SoilDepth 두번째 라디오 버튼 클릭 이벤트 처리

817 self.rbtUseConstDepth.clicked.connect(self.ConstDepth_CheckedChanged)

818

819 # ------------------------Lndcover 라디오 버튼 셋팅 시작---------------------------------

820 # 2017/11/27 =====

821

822 if self.LandCoverType == "File":

823 # 라디오 버튼 클릭시 활성, 비활성 컨트롤 함수

824 self.LCLaye_CheckedChanged()

825

826 # 라디오 버튼 체크 상태로 변환

827 self.rbtUseLCLayer.setChecked(True)

828

829 # 텍스트 파일에 Vat 파일 경로를 셋팅

830 self.txtLandCover.setText(

831 self._xmltodict["GRMProject"]["ProjectSettings"]["LandCoverVATFile"]

832 )

833

834 # 콤보 박스의 선택 레이어를 프로젝트 파일에 있는 것으로 셋팅

835 LandCoverFile = self._xmltodict["GRMProject"]["ProjectSettings"][

836 "LandCoverFile"

837 ]

838 if LandCoverFile != "" and LandCoverFile is not None:

839 LandCoverName = GetFile_Name(LandCoverFile)

840 SetCommbox2(self.cmbLandCover, LandCoverName, LandCoverFile)

841 else:

842 # 2번째 라디오 버튼 클릭시 이벤트 함수

843 self.ConstLCAtt_CheckedChanged()

844

845 # 2번째 라디오 버튼 체크 상태로 변환

846 self.rbtUseConstLCAtt.setChecked(True)

847

848 # 사용자 일괄 적용 라디오 버튼 클릭시 적용 할 텍스트 박스의 값을 셋팅

849 self.txtCoefficient.setText(

850 self._xmltodict["GRMProject"]["ProjectSettings"][

851 "ConstantRoughnessCoeff"

852 ]

853 )

854 self.txtImpervious.setText(

855 self._xmltodict["GRMProject"]["ProjectSettings"][

856 "ConstantImperviousRatio"

857 ]

858 )

859 # ------------------------Lndcover 라디오 버튼 셋팅 종료----------------------------------

860

861 self.path_LAI_file.setText(

862 self._xmltodict["GRMProject"]["ProjectSettings"]["LAIFile"]

863 )

864 self.path_blaney_criddle_coet.setText(

865 self._xmltodict["GRMProject"]["ProjectSettings"][

866 "BlaneyCriddleCoefDataFile"

867 ]

868 )

869

870 # ------------------------SoilTextureVATFile 라디오 버튼 셋팅 시작---------------------------------

871 # SoilTextureVATFile 이벤트

872 if self.SoilTextureType == "File":

873 # SoilTextureVATFile 항목의 첫번째 라디오 버튼 클릭 이벤트(컨트롤 활성, 비활성 기능 연동)

874 self.SoilTextureLayer_CheckedChanged()

875

876 # 라디오 버튼 클릭 상태로 셋팅

877 self.rbtUseSoilTextureLayer.setChecked(True)

878

879 # 텍스트 박스에 VAT 파일 경로 넣기

880 self.txtSoilTexture.setText(

881 self._xmltodict["GRMProject"]["ProjectSettings"][

882 "SoilTextureVATFile"

883 ]

884 )

885

886 # layer 콤보 박스 항목을 프로젝트 파일의 데이터 내용에 해당되는 콤보 박스 항목으로 셋팅

887 SoilTextureFile = self._xmltodict["GRMProject"]["ProjectSettings"][

888 "SoilTextureFile"

889 ]

890 if SoilTextureFile != "" and SoilTextureFile is not None:

891 SoilTextureName = GetFile_Name(SoilTextureFile)

892 SetCommbox2(self.cmbSoilTexture, SoilTextureName, SoilTextureFile)

893 else:

894 # 2번째 라디오 버튼(일괄 적용) 클릭 이벤트

895 self.TextureAtt_CheckedChanged()

896

897 # 라디오 버튼 클릭 상태로 설정

898 self.rbtUseConstTextureAtt.setChecked(True)

899

900 # 프로젝트 파일에서 각각 텍스트 값을 입력

901 self.txtPorosity.setText(

902 self._xmltodict["GRMProject"]["ProjectSettings"][

903 "ConstantSoilPorosity"

904 ]

905 )

906 self.txtEffective_porosity.setText(

907 self._xmltodict["GRMProject"]["ProjectSettings"][

908 "ConstantSoilEffPorosity"

909 ]

910 )

911 self.txtSuction_head.setText(

912 self._xmltodict["GRMProject"]["ProjectSettings"][

913 "ConstantSoilWettingFrontSuctionHead"

914 ]

915 )

916 self.txtConductiovity.setText(

917 self._xmltodict["GRMProject"]["ProjectSettings"][

918 "ConstantSoilHydraulicConductivity"

919 ]

920 )

921

922 # ------------------------SoilTextureVATFile 라디오 버튼 셋팅 종료----------------------------------

923

924 # ------------------------SoilDepth 라디오 버튼 셋팅 시작----------------------------------

925 if self.SoilDepthType == "File":

926 # SoilDepth 항목의 첫번째 체크 박스 선택 이벤트 함수

927 self.SoilDepthLayer_CheckedChanged()

928

929 # SoilDepth 항목의 첫번째 라디오 버튼 클릭 상태로 설정

930 self.rbtUseSoilDepthLayer.setChecked(True)

931

932 # 텍스트 박스에 VAT 파일 경로 넣기

933 self.txtSoilDepth.setText(

934 self._xmltodict["GRMProject"]["ProjectSettings"]["SoilDepthVATFile"]

935 )

936

937 # layer 콤보 박스 항목을 프로젝트 파일의 데이터 내용에 해당되는 콤보 박스 항목으로 셋팅

938 SoilDepthFile = self._xmltodict["GRMProject"]["ProjectSettings"][

939 "SoilDepthFile"

940 ]

941 if SoilDepthFile != "" and SoilDepthFile is not None:

942 SoilDepthName = GetFile_Name(SoilDepthFile)

943 SetCommbox2(self.cmbSoilDepth, SoilDepthName, SoilDepthFile)

944 else:

945 # SoilDepth 항목의 두번째 체크 박스 선택 이벤트 함수

946 self.ConstDepth_CheckedChanged()

947

948 # SoilDepth 항목의 두번째 라디오 버튼 클릭 상태로 설정

949 self.rbtUseConstDepth.setChecked(True)

950

951 # 프로젝트 파일에서 값읽어서 텍스트 박스에 셋팅

952 self.txtSoil_depth.setText(

953 self._xmltodict["GRMProject"]["ProjectSettings"][

954 "ConstantSoilDepth"

955 ]

956 )

957 except Exception as e:

958 MsError(e)

959

960 # LandCover 첫번째 라이디오 버튼 클릭시 이벤트 처리

961 def LCLaye_CheckedChanged(self):

962 self.btnVatLand.setEnabled(True)

963 self.txtLandCover.setEnabled(True)

964 self.cmbLandCover.setEnabled(True)

965 self.tlbLandCover.setEnabled(True)

966 self.txtCoefficient.setEnabled(False)

967 self.txtImpervious.setEnabled(False)

968

969 # LandCover 두번째 라이디오 버튼 클릭시 이벤트 처리

970 def ConstLCAtt_CheckedChanged(self):

971 self.btnVatLand.setEnabled(False)

972 self.txtLandCover.setEnabled(False)

973 self.cmbLandCover.setEnabled(False)

974 self.tlbLandCover.setEnabled(False)

975 self.txtCoefficient.setEnabled(True)

976 self.txtImpervious.setEnabled(True)

977

978 # SoilTexture 첫번째 라디오 버튼 클릭 이벤트 처리

979 def SoilTextureLayer_CheckedChanged(self):

980 self.cmbSoilTexture.setEnabled(True)

981 self.txtSoilTexture.setEnabled(True)

982 self.btnVatAmpt.setEnabled(True)

983 self.tblGreenAmpt.setEnabled(True)

984 self.txtPorosity.setEnabled(False)

985 self.txtEffective_porosity.setEnabled(False)

986 self.txtSuction_head.setEnabled(False)

987 self.txtConductiovity.setEnabled(False)

988

989 # SoilTexture 두번째 라디오 버튼 클릭 이벤트 처리

990 def TextureAtt_CheckedChanged(self):

991 self.cmbSoilTexture.setEnabled(False)

992 self.txtSoilTexture.setEnabled(False)

993 self.btnVatAmpt.setEnabled(False)

994 self.tblGreenAmpt.setEnabled(False)

995 self.txtPorosity.setEnabled(True)

996 self.txtEffective_porosity.setEnabled(True)

997 self.txtSuction_head.setEnabled(True)

998 self.txtConductiovity.setEnabled(True)

999

1000 # SoilDepth 첫번째 라디오 버튼 클릭 이벤트 처리

1001 def SoilDepthLayer_CheckedChanged(self):

1002 self.cmbSoilDepth.setEnabled(True)

1003 self.txtSoilDepth.setEnabled(True)

1004 self.btnVatDepth.setEnabled(True)

1005 self.tblSoilDepth.setEnabled(True)

1006 self.txtSoil_depth.setEnabled(False)

1007

1008 # SoilDepth 두번째 라디오 버튼 클릭 이벤트 처리

1009 def ConstDepth_CheckedChanged(self):

1010 self.cmbSoilDepth.setEnabled(False)

1011 self.txtSoilDepth.setEnabled(False)

1012 self.btnVatDepth.setEnabled(False)

1013 self.tblSoilDepth.setEnabled(False)

1014 self.txtSoil_depth.setEnabled(True)

1015

1016 # ====================각각의 테이블 헤더 셋팅 ======================================================================

1017 def SetTableHeader(self):

1018 self.SetLandCoverHeader()

1019

1020 self.SetGreenAmptHeader()

1021

1022 self.SetSoilDepthHeader()

1023

1024 # LandCover Table 헤더 셋팅

1025 def SetLandCoverHeader(self):

1026 self.tlbLandCover.setColumnCount(7)

1027 self.tlbLandCover.setHorizontalHeaderLabels(

1028 [

1029 "GridValue",

1030 "UserLandCover",

1031 "GRMCode",

1032 "RoughnessCoefficient",

1033 "ImperviousRatio",

1034 "CanopyRatio",

1035 "InterceptionMaxWaterCanopy_mm",

1036 ]

1037 )

1038

1039 # GreenAmpt Table 헤더 셋팅

1040 def SetGreenAmptHeader(self):

1041 self.tblGreenAmpt.setColumnCount(7)

1042 self.tblGreenAmpt.setHorizontalHeaderLabels(

1043 [

1044 "GridValue",

1045 "USERSoil",

1046 "GRMCode",

1047 "Porosity",

1048 "EffectivePorosity",

1049 "WFSoilSuctionHead",

1050 "HydraulicConductivity",

1051 ]

1052 )

1053

1054 # SoilDepth 테이블 헤더 셋팅

1055 def SetSoilDepthHeader(self):

1056 self.tblSoilDepth.setColumnCount(4)

1057 self.tblSoilDepth.setHorizontalHeaderLabels(

1058 ["GridValue", "UserDepthClass", "GRMCode", "SoilDepth"]

1059 )

1060

1061 # 테이블에 데이터 값 넣기

1062 def SetTableData(self):

1063 # 1순위 프로젝트 파일내 데이터 값

1064 # 2순위 Vat 파일 셋팅

1065

1066 if self.LandCoverType == "File" and self._LandCoverCount != 0:

1067 self.SetLandCoverTalbe()

1068

1069 if self.SoilTextureType == "File" and self._GreenAmptCount != 0:

1070 self.SetGreenAmptTalbe()

1071

1072 if self.SoilDepthType == "File" and self._SoilDepthCount != 0:

1073 self.SetSoilDepthTalbe()

1074

1075 def SetLandCoverTalbe(self):

1076 try:

1077 # 프로젝트 파일에서 불러온 데이터 테이블에 셋팅

1078 if self._LandCoverCount > 1:

1079 row = 0

1080 for artikel in self._xmltodict["GRMProject"]["LandCover"]:

1081 self.tlbLandCover.insertRow(row)

1082

1083 item1 = QTableWidgetItem(artikel["GridValue"])

1084 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1085 self.tlbLandCover.setItem(row, 0, QTableWidgetItem(item1))

1086

1087 item2 = QTableWidgetItem(artikel["UserLandCover"])

1088 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1089 self.tlbLandCover.setItem(row, 1, QTableWidgetItem(item2))

1090

1091 item3 = QTableWidgetItem(artikel["GRMCode"])

1092 item3.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1093 self.tlbLandCover.setItem(row, 2, QTableWidgetItem(item3))

1094

1095 self.tlbLandCover.setItem(

1096 row, 3, QTableWidgetItem(artikel["RoughnessCoefficient"])

1097 )

1098 self.tlbLandCover.setItem(

1099 row, 4, QTableWidgetItem(artikel["ImperviousRatio"])

1100 )

1101 self.tlbLandCover.setItem(

1102 row, 5, QTableWidgetItem(artikel["CanopyRatio"])

1103 )

1104 self.tlbLandCover.setItem(

1105 row,

1106 6,

1107 QTableWidgetItem(artikel["InterceptionMaxWaterCanopy_mm"]),

1108 )

1109 row = row + 1

1110 elif self._LandCoverCount == 1:

1111 self.tlbLandCover.insertRow(0)

1112

1113 item1 = QTableWidgetItem(

1114 self._xmltodict["GRMProject"]["LandCover"]["GridValue"]

1115 )

1116 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1117 self.tlbLandCover.setItem(row, 0, QTableWidgetItem(item1))

1118

1119 item2 = QTableWidgetItem(

1120 self._xmltodict["GRMProject"]["LandCover"]["UserLandCover"]

1121 )

1122 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1123 self.tlbLandCover.setItem(row, 1, QTableWidgetItem(item2))

1124

1125 item3 = QTableWidgetItem(

1126 self._xmltodict["GRMProject"]["LandCover"]["GRMCode"]

1127 )

1128 item3.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1129 self.tlbLandCover.setItem(row, 2, QTableWidgetItem(item3))

1130

1131 self.tlbLandCover.setItem(

1132 row,

1133 3,

1134 QTableWidgetItem(

1135 self._xmltodict["GRMProject"]["LandCover"][

1136 "RoughnessCoefficient"

1137 ]

1138 ),

1139 )

1140 self.tlbLandCover.setItem(

1141 row,

1142 4,

1143 QTableWidgetItem(

1144 self._xmltodict["GRMProject"]["LandCover"]["ImperviousRatio"]

1145 ),

1146 )

1147 self.tlbLandCover.setItem(

1148 row,

1149 5,

1150 QTableWidgetItem(

1151 self._xmltodict["GRMProject"]["LandCover"]["CanopyRatio"]

1152 ),

1153 )

1154 self.tlbLandCover.setItem(

1155 row,

1156 6,

1157 QTableWidgetItem(

1158 self._xmltodict["GRMProject"]["LandCover"][

1159 "InterceptionMaxWaterCanopy_mm"

1160 ]

1161 ),

1162 )

1163 elif self._LandCoverCount == 0:

1164 if self.cmbLandCover.currentIndex() != 0:

1165 self.Get_ComboBox_LayerPath(

1166 self.cmbLandCover,

1167 self.tlbLandCover,

1168 self.txtLandCover,

1169 "LandCover",

1170 )

1171

1172 except KeyError:

1173 self.Get_ComboBox_LayerPath(

1174 self.cmbLandCover, self.tlbLandCover, self.txtLandCover, "LandCover"

1175 )

1176

1177 def SetGreenAmptTalbe(self):

1178 try:

1179 # 프로젝트 파일에서 불러온 데이터 테이블에 셋팅

1180 if self._GreenAmptCount > 1:

1181 row = 0

1182 for artikel in self._xmltodict["GRMProject"]["GreenAmptParameter"]:

1183 self.tblGreenAmpt.insertRow(row)

1184

1185 item1 = QTableWidgetItem(artikel["GridValue"])

1186 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1187 self.tblGreenAmpt.setItem(row, 0, QTableWidgetItem(item1))

1188

1189 item2 = QTableWidgetItem(artikel["USERSoil"])

1190 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1191 self.tblGreenAmpt.setItem(row, 1, QTableWidgetItem(item2))

1192

1193 item3 = QTableWidgetItem(artikel["GRMCode"])

1194 item3.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1195 self.tblGreenAmpt.setItem(row, 2, QTableWidgetItem(item3))

1196

1197 self.tblGreenAmpt.setItem(

1198 row, 3, QTableWidgetItem(artikel["Porosity"])

1199 )

1200 self.tblGreenAmpt.setItem(

1201 row, 4, QTableWidgetItem(artikel["EffectivePorosity"])

1202 )

1203 self.tblGreenAmpt.setItem(

1204 row, 5, QTableWidgetItem(artikel["WFSoilSuctionHead"])

1205 )

1206 self.tblGreenAmpt.setItem(

1207 row, 6, QTableWidgetItem(artikel["HydraulicConductivity"])

1208 )

1209 row = row + 1

1210 elif self._GreenAmptCount == 1:

1211 self.tblGreenAmpt.insertRow(0)

1212

1213 item1 = QTableWidgetItem(

1214 self._xmltodict["GRMProject"]["GreenAmptParameter"]["GridValue"]

1215 )

1216 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1217 self.tblGreenAmpt.setItem(row, 0, QTableWidgetItem(item1))

1218

1219 item2 = QTableWidgetItem(

1220 self._xmltodict["GRMProject"]["GreenAmptParameter"]["USERSoil"]

1221 )

1222 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1223 self.tblGreenAmpt.setItem(row, 1, QTableWidgetItem(item2))

1224

1225 item3 = QTableWidgetItem(

1226 self._xmltodict["GRMProject"]["GreenAmptParameter"]["GRMCode"]

1227 )

1228 item3.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1229 self.tblGreenAmpt.setItem(row, 2, QTableWidgetItem(item3))

1230

1231 self.tblGreenAmpt.setItem(

1232 row,

1233 3,

1234 QTableWidgetItem(

1235 self._xmltodict["GRMProject"]["GreenAmptParameter"]["Porosity"]

1236 ),

1237 )

1238 self.tblGreenAmpt.setItem(

1239 row,

1240 4,

1241 QTableWidgetItem(

1242 self._xmltodict["GRMProject"]["GreenAmptParameter"][

1243 "EffectivePorosity"

1244 ]

1245 ),

1246 )

1247 self.tblGreenAmpt.setItem(

1248 row,

1249 5,

1250 QTableWidgetItem(

1251 self._xmltodict["GRMProject"]["GreenAmptParameter"][

1252 "WFSoilSuctionHead"

1253 ]

1254 ),

1255 )

1256 self.tblGreenAmpt.setItem(

1257 row,

1258 6,

1259 QTableWidgetItem(

1260 self._xmltodict["GRMProject"]["GreenAmptParameter"][

1261 "HydraulicConductivity"

1262 ]

1263 ),

1264 )

1265

1266 except KeyError:

1267 self.Get_ComboBox_LayerPath(

1268 self.cmbSoilTexture, self.tblGreenAmpt, self.txtSoilTexture, "GreenAmpt"

1269 )

1270

1271 def SetSoilDepthTalbe(self):

1272 try:

1273 # 프로젝트 파일에서 불러온 데이터 테이블에 셋팅

1274 if self._SoilDepthCount > 1:

1275 row = 0

1276 for artikel in self._xmltodict["GRMProject"]["SoilDepth"]:

1277 self.tblSoilDepth.insertRow(row)

1278

1279 item1 = QTableWidgetItem(artikel["GridValue"])

1280 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1281 self.tblSoilDepth.setItem(row, 0, QTableWidgetItem(item1))

1282

1283 item2 = QTableWidgetItem(artikel["UserDepthClass"])

1284 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1285 self.tblSoilDepth.setItem(row, 1, QTableWidgetItem(item2))

1286

1287 item3 = QTableWidgetItem(artikel["GRMCode"])

1288 item3.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1289 self.tblSoilDepth.setItem(row, 2, QTableWidgetItem(item3))

1290

1291 item4 = QTableWidgetItem(artikel["SoilDepth_cm"])

1292 self.tblSoilDepth.setItem(row, 3, QTableWidgetItem(item4))

1293 row = row + 1

1294

1295 elif self._SoilDepthCount == 1:

1296 self.tblSoilDepth.insertRow(0)

1297

1298 item1 = QTableWidgetItem(

1299 self._xmltodict["GRMProject"]["SoilDepth"]["GridValue"]

1300 )

1301 item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1302 self.tblSoilDepth.setItem(row, 0, QTableWidgetItem(item1))

1303

1304 item2 = QTableWidgetItem(

1305 self._xmltodict["GRMProject"]["SoilDepth"]["UserDepthClass"]

1306 )

1307 item2.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1308 self.tblSoilDepth.setItem(row, 1, QTableWidgetItem(item2))

1309

1310 item3 = QTableWidgetItem(

1311 self._xmltodict["GRMProject"]["SoilDepth"]["GRMCode"]

1312 )

1313 item3.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)

1314 self.tblSoilDepth.setItem(row, 2, QTableWidgetItem(item3))

1315

1316 item4 = QTableWidgetItem(

1317 self._xmltodict["GRMProject"]["SoilDepth"]["SoilDepth_cm"]

1318 )

1319 self.tblSoilDepth.setItem(row, 3, QTableWidgetItem(item4))

1320 except Exception as e:

1321 self.Get_ComboBox_LayerPath(

1322 self.cmbSoilDepth, self.tblSoilDepth, self.txtSoilDepth, "SoilDepth"

1323 )

1324 MsError(e)

1325

1326 # Qdilog 창에 Qtablewidget 셋팅

1327 def aboutApp(self, type, row):

1328 global _SelectRow

1329 _SelectRow = row

1330 website = "http://code.google.com/p/comictagger"

1331 email = "comictagger@gmail.com"

1332 license_link = "http://www.apache.org/licenses/LICENSE-2.0"

1333 license_name = "Apache License 2.0"

1334 Project = "test"

1335 msgBox = QMessageBox()

1336 msgBox.setWindowTitle(self.tr("Select Attribute"))

1337 msgBox.setTextFormat(Qt.RichText)

1338 msgBox.setIconPixmap(QPixmap(Project))

1339 msgBox.setText(

1340 "<br><br><br><br><br><br><br><br><br><br><br>"

1341 + "<font color=white>"

1342 + "{0},{1},{2}</font>".format(website, email, license_name)

1343 )

1344 self.addTableWidget(msgBox, type)

1345 msgBox.exec_()

1346

1347 # Create TableWidget

1348 def addTableWidget(self, parentItem, type):

1349 self.tableWidget = QTableWidget(parentItem)

1350 self.tableWidget.setGeometry(QRect(0, 0, 500, 250))

1351 self.tableWidget.setObjectName("tableWidget")

1352 self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

1353 self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)

1354 self.paranet = parentItem

1355 if type == "LandCover":

1356 self.SetLandcoverTable(self.tableWidget)

1357 if type == "GreenAmpt":

1358 self.SetGreenAmptTable(self.tableWidget)

1359 if type == "SoilDepth":

1360 self.SetSoilDepth(self.tableWidget)

1361

1362 # 더블 클릭시 Qdialog 에 테이블 셋팅 하기

1363 def SetLandcoverTable(self, tableWidget):

1364 doc = ET.parse(self.StaticDB)

1365 root = doc.getroot()

1366 list = []

1367 for element in root.findall(

1368 "{http://tempuri.org/DataSet1.xsd}LandCoverParameter"

1369 ):

1370 list.append(element.findtext("{http://tempuri.org/DataSet1.xsd}LandCoverE"))

1371 list.append(element.findtext("{http://tempuri.org/DataSet1.xsd}LandCoverK"))

1372 list.append(element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode"))

1373 list.append(

1374 element.findtext(

1375 "{http://tempuri.org/DataSet1.xsd}RoughnessCoefficient"

1376 )

1377 )

1378 list.append(

1379 element.findtext("{http://tempuri.org/DataSet1.xsd}ImperviousRatio")

1380 )

1381 list.append(

1382 element.findtext("{http://tempuri.org/DataSet1.xsd}CanopyRatio")

1383 )

1384 list.append(

1385 element.findtext(

1386 "{http://tempuri.org/DataSet1.xsd}InterceptionMaxWaterCanopy_mm"

1387 )

1388 )

1389

1390 # table에 값 셋팅

1391 tableWidget.verticalHeader().hide()

1392 tableWidget.setColumnCount(7)

1393

1394 value = int(len(list) / 7)

1395 tableWidget.setRowCount(value)

1396 tableWidget.setHorizontalHeaderLabels(

1397 [

1398 "LandCoverE",

1399 "LandCoverK",

1400 "GRMCode",

1401 "RoughnessCoefficient",

1402 "ImperviousRatio",

1403 "CanopyRatio",

1404 "InterceptionMaxWaterCanopy_mm",

1405 ]

1406 )

1407

1408 tableWidget.resizeColumnsToContents()

1409 tableWidget.resizeRowsToContents()

1410 tableWidget.itemDoubleClicked.connect(

1411 lambda: self.SelectCellValue(tableWidget, "LandCover")

1412 )

1413 # 각각의 컬럼에 갑셋팅(xml 상에 'ObTSId', 'ObTSLegend', 'ObTSMissingCount' 항목의 값이 없음

1414 for i in range(0, value):

1415 for j in range(0, 7):

1416 self.tableWidget.setItem(i, j, QTableWidgetItem(list[7 * i + j]))

1417

1418 def SetGreenAmptTable(self, tableWidget):

1419 # 프로젝트 파일 로드

1420 doc = ET.parse(self.StaticDB)

1421

1422 root = doc.getroot()

1423 list = []

1424 for element in root.findall(

1425 "{http://tempuri.org/DataSet1.xsd}GreenAmptSoilParameter"

1426 ):

1427 list.append(

1428 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilTextureE")

1429 )

1430 list.append(

1431 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilTextureK")

1432 )

1433 list.append(element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode"))

1434 list.append(

1435 element.findtext("{http://tempuri.org/DataSet1.xsd}PorosityMin")

1436 )

1437 list.append(

1438 element.findtext("{http://tempuri.org/DataSet1.xsd}PorosityMax")

1439 )

1440 list.append(

1441 element.findtext("{http://tempuri.org/DataSet1.xsd}PorosityDefault")

1442 )

1443 list.append(

1444 element.findtext(

1445 "{http://tempuri.org/DataSet1.xsd}EffectivePorosityMin"

1446 )

1447 )

1448 list.append(

1449 element.findtext(

1450 "{http://tempuri.org/DataSet1.xsd}EffectivePorosityMax"

1451 )

1452 )

1453 list.append(

1454 element.findtext(

1455 "{http://tempuri.org/DataSet1.xsd}EffectivePorosityDefault"

1456 )

1457 )

1458 list.append(

1459 element.findtext(

1460 "{http://tempuri.org/DataSet1.xsd}ResidualMoistureContent"

1461 )

1462 )

1463 list.append(

1464 element.findtext(

1465 "{http://tempuri.org/DataSet1.xsd}WFSoilSuctionHeadMin"

1466 )

1467 )

1468 list.append(

1469 element.findtext(

1470 "{http://tempuri.org/DataSet1.xsd}WFSoilSuctionHeadMax"

1471 )

1472 )

1473 list.append(

1474 element.findtext(

1475 "{http://tempuri.org/DataSet1.xsd}WFSoilSuctionHeadDefault"

1476 )

1477 )

1478 list.append(

1479 element.findtext(

1480 "{http://tempuri.org/DataSet1.xsd}HydraulicConductivity"

1481 )

1482 )

1483

1484 # table에 값 셋팅

1485 tableWidget.verticalHeader().hide()

1486 tableWidget.setColumnCount(14)

1487

1488 value = int(len(list) / 14)

1489 tableWidget.setRowCount(value)

1490 tableWidget.setHorizontalHeaderLabels(

1491 [

1492 "SoilTextureE",

1493 "SoilTextureK",

1494 "GRMCode",

1495 "PorosityMin",

1496 "PorosityMax",

1497 "PorosityDefault",

1498 "EffectivePorosityMin",

1499 "EffectivePorosityMax",

1500 "EffectivePorosityDefault",

1501 "ResidualMoistureContent",

1502 "WFSoilSuctionHeadMin",

1503 "WFSoilSuctionHeadMax",

1504 "WFSoilSuctionHeadDefault",

1505 "HydraulicConductivity",

1506 ]

1507 )

1508

1509 tableWidget.resizeColumnsToContents()

1510 tableWidget.resizeRowsToContents()

1511 tableWidget.itemDoubleClicked.connect(

1512 lambda: self.SelectCellValue(tableWidget, "GreenAmpt")

1513 )

1514

1515 # 각각의 컬럼에 갑셋팅(xml 상에 'ObTSId', 'ObTSLegend', 'ObTSMissingCount' 항목의 값이 없음

1516 for i in range(0, value):

1517 for j in range(0, 14):

1518 self.tableWidget.setItem(i, j, QTableWidgetItem(list[14 * i + j]))

1519

1520 def SetSoilDepth(self, tableWidget):

1521 doc = ET.parse(self.StaticDB)

1522

1523 root = doc.getroot()

1524 list = []

1525 for element in root.findall(

1526 "{http://tempuri.org/DataSet1.xsd}SoilDepthParameter"

1527 ):

1528 list.append(element.findtext("{http://tempuri.org/DataSet1.xsd}GRMCode"))

1529 list.append(

1530 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilDepthClassE")

1531 )

1532 list.append(

1533 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilDepthClassK")

1534 )

1535 list.append(

1536 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilDepthMin")

1537 )

1538 list.append(

1539 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilDepthMax")

1540 )

1541 list.append(

1542 element.findtext("{http://tempuri.org/DataSet1.xsd}SoilDepthDefault")

1543 )

1544

1545 # table에 값 셋팅

1546 tableWidget.verticalHeader().hide()

1547 tableWidget.setColumnCount(6)

1548

1549 value = int(len(list) / 6)

1550

1551 tableWidget.setRowCount(value)

1552 tableWidget.setHorizontalHeaderLabels(

1553 [

1554 "GRMCode",

1555 "SoilDepthClassE",

1556 "SoilDepthClassK",

1557 "SoilDepthMin",

1558 "SoilDepthMax",

1559 "SoilDepth",

1560 ]

1561 )

1562

1563 tableWidget.resizeColumnsToContents()

1564 tableWidget.resizeRowsToContents()

1565 tableWidget.itemDoubleClicked.connect(

1566 lambda: self.SelectCellValue(tableWidget, "SoilDepth")

1567 )

1568 # 각각의 컬럼에 갑셋팅(xml 상에 'ObTSId', 'ObTSLegend', 'ObTSMissingCount' 항목의 값이 없음

1569 for i in range(0, value):

1570 for j in range(0, 6):

1571 self.tableWidget.setItem(i, j, QTableWidgetItem(list[6 * i + j]))

1572

1573 # 작은 창 테이블 클릭시 큰 테이블에 선택값 셋팅(집중이 안되서 노가다함 ㅠㅠ)

1574 # 2020-01-15 박: 사용자 지정은 타이틀은 바뀌지 않게 되어 있는데 이거 변경 하게 하는지 최박사님께 문의 하도록

1575 def SelectCellValue(self, tableWidget, type):

1576 row = tableWidget.currentRow()

1577 try:

1578 items = []

1579

1580 if type == "LandCover":

1581 item2 = tableWidget.item(row, 0)

1582 item3 = tableWidget.item(row, 1)

1583 item4 = tableWidget.item(row, 2)

1584 item5 = tableWidget.item(row, 3)

1585 item6 = tableWidget.item(row, 4)

1586

1587 items = [item4, item5, item6]

1588 tbl = self.tlbLandCover

1589

1590 elif type == "GreenAmpt":

1591 item2 = tableWidget.item(row, 0)

1592 item3 = tableWidget.item(row, 1)

1593 item4 = tableWidget.item(row, 2)

1594 item5 = tableWidget.item(row, 5)

1595 item6 = tableWidget.item(row, 8)

1596 item7 = tableWidget.item(row, 12)

1597 item8 = tableWidget.item(row, 13)

1598

1599 items = [item4, item5, item6, item7, item8]

1600 tbl = self.tblGreenAmpt

1601

1602 elif type == "SoilDepth":

1603 item2 = tableWidget.item(row, 0)

1604 item3 = tableWidget.item(row, 1)

1605 item4 = tableWidget.item(row, 2)

1606 item5 = tableWidget.item(row, 5)

1607

1608 items = [item2, item5]

1609 tbl = self.tblSoilDepth

1610

1611 for i, it in enumerate(items):

1612 if tbl.item(_SelectRow, i + 2):

1613 tbl.item(_SelectRow, i + 2).setText(it.text())

1614 else:

1615 tbl.setItem(_SelectRow, i + 2, QTableWidgetItem(it.text()))

1616

1617 # 메시지 박스 종료

1618 # self.paranet.done(1)

1619 except AttributeError as e:

1620 print(e)

1621 MsError("This is not valid data.")

1622 finally:

1623 self.paranet.done(1)

1624

1625 def DataSave(self):

1626 if self.rbtUseLCLayer.isChecked():

1627 self._xmltodict["GRMProject"]["ProjectSettings"][

1628 "LandCoverDataType"

1629 ] = "File"

1630 if self.cmbLandCover.currentIndex() != 0:

1631 LandCoverLayerPath = GetcomboSelectedLayerPath(self.cmbLandCover)

1632 else:

1633 LandCoverLayerPath = ""

1634

1635 self._xmltodict["GRMProject"]["ProjectSettings"][

1636 "LandCoverFile"

1637 ] = LandCoverLayerPath

1638 self._xmltodict["GRMProject"]["ProjectSettings"][

1639 "LandCoverVATFile"

1640 ] = self.txtLandCover.text()

1641 self.dataSeve_Landcover()

1642 else:

1643 self._xmltodict["GRMProject"]["ProjectSettings"][

1644 "LandCoverDataType"

1645 ] = "Constant"

1646 self._xmltodict["GRMProject"]["ProjectSettings"][

1647 "ConstantRoughnessCoeff"

1648 ] = self.txtCoefficient.text()

1649 self._xmltodict["GRMProject"]["ProjectSettings"][

1650 "ConstantImperviousRatio"

1651 ] = self.txtImpervious.text()

1652

1653 if self.path_LAI_file.text() != "":

1654 self._xmltodict["GRMProject"]["ProjectSettings"][

1655 "LAIFile"

1656 ] = self.path_LAI_file.text()

1657 if self.path_blaney_criddle_coet.text() != "":

1658 self._xmltodict["GRMProject"]["ProjectSettings"][

1659 "BlaneyCriddleCoefDataFile"

1660 ] = self.path_blaney_criddle_coet.text()

1661

1662 # 타입 설정

1663 if self.rbtUseSoilTextureLayer.isChecked():

1664 self._xmltodict["GRMProject"]["ProjectSettings"][

1665 "SoilTextureDataType"

1666 ] = "File"

1667 if self.cmbSoilTexture.currentIndex() != 0:

1668 SoilTextureLayerPath = GetcomboSelectedLayerPath(self.cmbSoilTexture)

1669 else:

1670 SoilTextureLayerPath = ""

1671 self._xmltodict["GRMProject"]["ProjectSettings"][

1672 "SoilTextureFile"

1673 ] = SoilTextureLayerPath

1674 self._xmltodict["GRMProject"]["ProjectSettings"][

1675 "SoilTextureVATFile"

1676 ] = self.txtSoilTexture.text()

1677 self.dataSeve_SoilTexture()

1678 else:

1679 self._xmltodict["GRMProject"]["ProjectSettings"][

1680 "SoilTextureDataType"

1681 ] = "Constant"

1682 self._xmltodict["GRMProject"]["ProjectSettings"][

1683 "ConstantSoilPorosity"

1684 ] = self.txtPorosity.text()

1685 self._xmltodict["GRMProject"]["ProjectSettings"][

1686 "ConstantSoilEffPorosity"

1687 ] = self.txtEffective_porosity.text()

1688 self._xmltodict["GRMProject"]["ProjectSettings"][

1689 "ConstantSoilWettingFrontSuctionHead"

1690 ] = self.txtSuction_head.text()

1691 self._xmltodict["GRMProject"]["ProjectSettings"][

1692 "ConstantSoilHydraulicConductivity"

1693 ] = self.txtConductiovity.text()

1694

1695 # 타입 설정

1696 if self.rbtUseSoilDepthLayer.isChecked():

1697 self._xmltodict["GRMProject"]["ProjectSettings"][

1698 "SoilDepthDataType"

1699 ] = "File"

1700

1701 if self.cmbSoilDepth.currentIndex() != 0:

1702 SoilDepthLayerPath = GetcomboSelectedLayerPath(self.cmbSoilDepth)

1703 else:

1704 SoilDepthLayerPath = ""

1705 self._xmltodict["GRMProject"]["ProjectSettings"][

1706 "SoilDepthFile"

1707 ] = SoilDepthLayerPath

1708 self._xmltodict["GRMProject"]["ProjectSettings"][

1709 "SoilDepthVATFile"

1710 ] = self.txtSoilDepth.text()

1711 self.dataSeve_SoilDepth()

1712 else:

1713 self._xmltodict["GRMProject"]["ProjectSettings"][

1714 "SoilDepthDataType"

1715 ] = "Constant"

1716 self._xmltodict["GRMProject"]["ProjectSettings"][

1717 "ConstantSoilDepth"

1718 ] = self.txtSoil_depth.text()

1719

1720 def dataSeve_Landcover(self):

1721 try:

1722 # dictionary 에서 LandCover 항목을 모두 제거

1723 check = self._xmltodict["GRMProject"]["LandCover"]

1724 if check is not None:

1725 del self._xmltodict["GRMProject"]["LandCover"]

1726 except:

1727 pass

1728

1729 # dictionary 에서 엘레먼트 생성이 안되서 dic===> XML (element 생성 ) ===> dictionary 변환

1730 # DictoXml = xmltodict.unparse(self._xmltodict)

1731 DictoXml = unparse(self._xmltodict)

1732 ET.register_namespace("", "http://tempuri.org/GRMProject.xsd")

1733 xmltree = ET.ElementTree(ET.fromstring(DictoXml))

1734 root = xmltree.getroot()

1735 count = self.tlbLandCover.rowCount()

1736 self._LandCoverCount = count

1737

1738 try:

1739 for row in range(0, count):

1740 child = ET.Element("LandCover")

1741 root.append(child)

1742

1743 GridValue = ET.Element("GridValue")

1744 # 특수문자 있음 제외 함

1745 GridValue.text = self.tlbLandCover.item(row, 0).text().replace("﻿", "")

1746 child.append(GridValue)

1747

1748 UserLandCover = ET.Element("UserLandCover")

1749 UserLandCover.text = self.tlbLandCover.item(row, 1).text()

1750 child.append(UserLandCover)

1751

1752 GRMLandCoverCode = ET.Element("GRMCode")

1753 GRMLandCoverCode.text = self.tlbLandCover.item(row, 2).text()

1754 child.append(GRMLandCoverCode)

1755

1756 RoughnessCoefficient = ET.Element("RoughnessCoefficient")

1757 RoughnessCoefficient.text = self.tlbLandCover.item(row, 3).text()

1758 child.append(RoughnessCoefficient)

1759

1760 ImperviousRatio = ET.Element("ImperviousRatio")

1761 ImperviousRatio.text = self.tlbLandCover.item(row, 4).text()

1762 child.append(ImperviousRatio)

1763

1764 CanopyRatio = ET.Element("CanopyRatio")

1765 CanopyRatio.text = self.tlbLandCover.item(row, 5).text()

1766 child.append(CanopyRatio)

1767

1768 InterceptionMaxWaterCanopy_mm = ET.Element(

1769 "InterceptionMaxWaterCanopy_mm"

1770 )

1771 InterceptionMaxWaterCanopy_mm.text = self.tlbLandCover.item(

1772 row, 6

1773 ).text()

1774 child.append(InterceptionMaxWaterCanopy_mm)

1775

1776 filepath = tempfile.mktemp()

1777 xmltree.write(filepath)

1778

1779 # Dictionary 초기화

1780 self._xmltodict.clear()

1781

1782 # 파일 읽어 오기

1783 Projectfile = open(filepath, "r")

1784 data = Projectfile.read()

1785 Projectfile.close()

1786 # 읽어온 파일 내용(XML)을 dictionary 로 변경

1787 docs = dict(parse(data))

1788 self._xmltodict.update(docs)

1789 except Exception as e:

1790 pass

1791

1792 def dataSeve_SoilTexture(self):

1793 # dictionary 에서 GreenAmptParameter 항목을 모두 제거

1794 try:

1795 # dictionary 에서 LandCover 항목을 모두 제거

1796 check = self._xmltodict["GRMProject"]["GreenAmptParameter"]

1797 if check is not None:

1798 del self._xmltodict["GRMProject"]["GreenAmptParameter"]

1799 except:

1800 pass

1801

1802 # dictionary 에서 엘레먼트 생성이 안되서 dic===> XML (element 생성 ) ===> dictionary 변환

1803 # DictoXml = xmltodict.unparse(self._xmltodict)

1804 DictoXml = unparse(self._xmltodict)

1805 ET.register_namespace("", "http://tempuri.org/GRMProject.xsd")

1806 xmltree = ET.ElementTree(ET.fromstring(DictoXml))

1807 root = xmltree.getroot()

1808 count = self.tblGreenAmpt.rowCount()

1809 self._GreenAmptCount = count

1810 for row in range(0, count):

1811 child = ET.Element("GreenAmptParameter")

1812 root.append(child)

1813

1814 GridValue = ET.Element("GridValue")

1815 # 특수문자 있음 제외 함

1816 GridValue.text = self.tblGreenAmpt.item(row, 0).text().replace("﻿", "")

1817 child.append(GridValue)

1818

1819 USERSoil = ET.Element("USERSoil")

1820 USERSoil.text = self.tblGreenAmpt.item(row, 1).text()

1821 child.append(USERSoil)

1822

1823 GRMCode = ET.Element("GRMCode")

1824 GRMCode.text = self.tblGreenAmpt.item(row, 2).text()

1825 child.append(GRMCode)

1826

1827 Porosity = ET.Element("Porosity")

1828 Porosity.text = self.tblGreenAmpt.item(row, 3).text()

1829 child.append(Porosity)

1830

1831 EffectivePorosity = ET.Element("EffectivePorosity")

1832 EffectivePorosity.text = self.tblGreenAmpt.item(row, 4).text()

1833 child.append(EffectivePorosity)

1834

1835 WFSoilSuctionHead = ET.Element("WFSoilSuctionHead")

1836 WFSoilSuctionHead.text = self.tblGreenAmpt.item(row, 5).text()

1837 child.append(WFSoilSuctionHead)

1838

1839 HydraulicConductivity = ET.Element("HydraulicConductivity")

1840 HydraulicConductivity.text = self.tblGreenAmpt.item(row, 6).text()

1841 child.append(HydraulicConductivity)

1842

1843 # xmltree.write("C:\Users\hermesys\Desktop\Sct2.gmp")

1844 filepath = tempfile.mktemp()

1845 xmltree.write(filepath)

1846

1847 # Dictionary 초기화

1848 self._xmltodict.clear()

1849

1850 # 파일 읽어 오기

1851 Projectfile = open(filepath, "r")

1852 data = Projectfile.read()

1853 Projectfile.close()

1854 # 읽어온 파일 내용(XML)을 dictionary 로 변경

1855 docs = dict(parse(data))

1856 self._xmltodict.update(docs)

1857

1858 def dataSeve_SoilDepth(self):

1859 # dictionary 에서 GreenAmptParameter 항목을 모두 제거

1860 try:

1861 check = self._xmltodict["GRMProject"]["SoilDepth"]

1862 if check is not None:

1863 del self._xmltodict["GRMProject"]["SoilDepth"]

1864 except:

1865 pass

1866

1867 # dictionary 에서 엘레먼트 생성이 안되서 dic===> XML (element 생성 ) ===> dictionary 변환

1868 DictoXml = unparse(self._xmltodict)

1869 ET.register_namespace("", "http://tempuri.org/GRMProject.xsd")

1870 xmltree = ET.ElementTree(ET.fromstring(DictoXml))

1871 root = xmltree.getroot()

1872 count = self.tblSoilDepth.rowCount()

1873 self._SoilDepthCount = count

1874 for row in range(0, count):

1875 child = ET.Element("SoilDepth")

1876 root.append(child)

1877

1878 GridValue = ET.Element("GridValue")

1879 # 특수문자 있음 제외 함

1880 GridValue.text = self.tblSoilDepth.item(row, 0).text().replace("﻿", "")

1881 child.append(GridValue)

1882

1883 UserDepthClass = ET.Element("UserDepthClass")

1884 UserDepthClass.text = self.tblSoilDepth.item(row, 1).text()

1885 child.append(UserDepthClass)

1886

1887 GRMDepthCode = ET.Element("GRMCode")

1888 GRMDepthCode.text = self.tblSoilDepth.item(row, 2).text()

1889 child.append(GRMDepthCode)

1890

1891 # SoilDepthClassE = ET.Element("SoilDepthClassE")

1892 # SoilDepthClassE.text = self.tblSoilDepth.item(row, 3).text()

1893 # child.append(SoilDepthClassE)

1894 #

1895 # SoilDepthClassK = ET.Element("SoilDepthClassK")

1896 # SoilDepthClassK.text = self.tblSoilDepth.item(row, 4).text()

1897 # child.append(SoilDepthClassK)

1898

1899 SoilDepth = ET.Element("SoilDepth_cm")

1900 SoilDepth.text = self.tblSoilDepth.item(row, 3).text()

1901 child.append(SoilDepth)

1902

1903 # xmltree.write("C:\Users\hermesys\Desktop\Sct2.gmp")

1904 filepath = tempfile.mktemp()

1905 xmltree.write(filepath)

1906

1907 # Dictionary 초기화

1908 self._xmltodict.clear()

1909

1910 # 파일 읽어 오기

1911 Projectfile = open(filepath, "r")

1912 data = Projectfile.read()

1913 Projectfile.close()

1914 # 읽어온 파일 내용(XML)을 dictionary 로 변경

1915 docs = dict(parse(data))

1916 self._xmltodict.update(docs)

1917

1918 def isFloat(self, Snumber):

1919 try:

1920 float(Snumber)

1921 return True

1922 except ValueError:

1923 return False

1924

1925

1926 if __name__ == "__main__":

1927 import os

1928

1929 from grm.lib.Util import MsTitle

1930

1931 os.environ[

1932 "QT_QPA_PLATFORM_PLUGIN_PATH"

1933 ] = r"C:\Program Files\QGIS 3.10\apps\Qt5\plugins"

1934 import sys

1935

1936 from qgis.PyQt.QtWidgets import QApplication

1937

1938 MsTitle("ClimateDataDialog")

1939 app = QApplication(sys.argv)

1940 ui = LandCoverDialog(

1941 {

1942 "GRMProject": {

1943 "ProjectSettings": {

1944 "LandCoverDataType": "File",

1945 "SoilTextureDataType": "File",

1946 "SoilDepthDataType": "File",

1947 "LandCoverVATFile": "",

1948 "LandCoverFile": "",

1949 "SoilTextureVATFile": "",

1950 "SoilDepthVATFile": "",

1951 "SoilTextureFile": "",

1952 "SoilDepthFile": "",

1953 "LAIFile": "",

1954 "BlaneyCriddleCoefDataFile": "",

1955 }

1956 }

1957 }

1958 )

1959 ui.show()

1960 sys.exit(app.exec_())