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 import uic

29 from qgis.PyQt.QtCore import QRect, Qt

30 from qgis.PyQt.QtGui import QPixmap

31 from qgis.PyQt.QtWidgets import (

32 QAbstractItemView,

33 QDialog,

34 QFileDialog,

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)

48 from grm.lib.xmltodict import parse, unparse

49

50 FORM_CLASS, _ = uic.loadUiType(os.path.join(os.path.dirname(__file__), "LandCover.ui"))

51

52

53 class LandCoverDialog(QDialog, FORM_CLASS):

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 # 사용자가 VAT 파일 바꿀때 테이블 값도 바뀌어서 적용

142 def SelectVat(self, button, txtbox):

143 try:

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

145 filename = QFileDialog.getOpenFileName(

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

147 )[0]

148 if filename:

149 txtbox.setText(filename)

150 if button == "btnVatLand":

151 self.SetVATValue(

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

153 )

154 elif button == "btnVatAmpt":

155 self.SetVATValue(

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

157 )

158 elif button == "btnVatDepth":

159 self.SetVATValue(

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

161 )

162 except Exception as e:

163 MsError(e)

164

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

166 try:

167 if combox.currentIndex() != 0:

168 self.layerPath = (

169 GetcomboSelectedLayerPath(combox)

170 .lower()

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

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

173 )

174

175 if ChFile_Exists(self.layerPath):

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

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

178 except Exception as e:

179 MsError(e)

180

181 def OKForm(self):

182 if self.rbtUseLCLayer.isChecked():

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

184 MsInfo(" layer is not selected ")

185 self.cmbLandCover.setFocus()

186 return

187

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

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

190 self.txtLandCover.setFocus()

191 return

192

193 if self.rbtUseSoilTextureLayer.isChecked():

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

195 MsInfo(" layer is not selected ")

196 self.cmbSoilTexture.setFocus()

197 return

198

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

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

201 self.txtSoilTexture.setFocus()

202 return

203

204 if self.rbtUseSoilDepthLayer.isChecked():

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

206 MsInfo(" layer is not selected ")

207 self.cmbSoilDepth.setFocus()

208 return

209

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

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

212 self.txtSoilDepth.setFocus()

213 return

214

215 # 1. 라디오 rbtUseConstLCAtt

216 if self.rbtUseConstLCAtt.isChecked():

217 if self.Checktxtbox(self.txtCoefficient):

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

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

220 MsInfo(

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

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

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

224 )

225 )

226 self.txtCoefficient.setFocus()

227 return

228 else:

229 MsInfo(

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

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

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

233 )

234 )

235 self.txtCoefficient.setFocus()

236 return

237

238 if self.Checktxtbox(self.txtImpervious):

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

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

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

242 self.txtImpervious.setFocus()

243 return

244 else:

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

246 self.txtImpervious.setFocus()

247 return

248

249 # 2. rbtUseConstTextureAtt 선택 시,

250 if self.rbtUseConstTextureAtt.isChecked():

251 if self.Checktxtbox(self.txtPorosity):

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

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

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

255 self.txtPorosity.setFocus()

256 return

257 else:

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

259 self.txtPorosity.setFocus()

260 return

261

262 if self.Checktxtbox(self.txtEffective_porosity):

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

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

265 MsInfo(

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

267 )

268 self.txtEffective_porosity.setFocus()

269 return

270 else:

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

272 self.txtEffective_porosity.setFocus()

273 return

274

275 if self.Checktxtbox(self.txtSuction_head):

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

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

278 MsInfo(

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

280 )

281 self.txtSuction_head.setFocus()

282 return

283 else:

284 MsInfo(

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

286 )

287 self.txtSuction_head.setFocus()

288 return

289

290 if self.Checktxtbox(self.txtConductiovity):

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

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

293 MsInfo(

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

295 )

296 self.txtConductiovity.setFocus()

297 return

298 else:

299 MsInfo(

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

301 )

302 self.txtConductiovity.setFocus()

303 return

304

305 # 3.rbtUseConstDepth 체크

306 if self.rbtUseConstDepth.isChecked():

307 if self.Checktxtbox(self.txtSoil_depth):

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

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

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

311 self.txtSoil_depth.setFocus()

312 return

313 else:

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

315 self.txtSoil_depth.setFocus()

316 return

317

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

319 self.DataSave()

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

321

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

323 reply = QMessageBox.information(

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

325 )

326 if reply == QMessageBox.Ok:

327 self.close()

328

329 # QlineEdit 값 체크

330 def Checktxtbox(self, textbox):

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

332 return True

333 else:

334 return False

335

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

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

338 try:

339 if path != "":

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

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

342 # lines = fileObj.readlines()

343 try:

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

345 lines = f.readlines()

346 except Exception as e:

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

348 lines = f.readlines()

349

350 # 테이블 초기화

351 table.clear()

352 if type == "LandCover":

353 table.setColumnCount(5)

354 table.setHorizontalHeaderLabels(

355 [

356 "GridValue",

357 "UserLandCover",

358 "GRMCode",

359 "RoughnessCoefficient",

360 "ImperviousRatio",

361 ]

362 )

363

364 elif type == "GreenAmpt":

365 table.setColumnCount(7)

366 table.setHorizontalHeaderLabels(

367 [

368 "GridValue",

369 "USERSoil",

370 "GRMCode",

371 "Porosity",

372 "EffectivePorosity",

373 "WFSoilSuctionHead",

374 "HydraulicConductivity",

375 ]

376 )

377 elif type == "SoilDepth":

378 table.setColumnCount(4)

379 table.setHorizontalHeaderLabels(

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

381 )

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

383

384 # Table에 데이터 값 대입

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

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

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

388 # item1 = QTableWidgetItem(splitsdata[0])

389 item1 = QTableWidgetItem(splitsdata[0])

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

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

392 item2 = QTableWidgetItem(splitsdata[1])

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

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

395

396 txtvalue = splitsdata[1]

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

398 user = True

399 else:

400 user = False

401 self.SetMainTableValue(

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

403 )

404 except Exception as es:

405 MsError(es)

406

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

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

409 doc = ET.parse(self.StaticDB)

410 root = doc.getroot()

411 if type == "LandCover":

412 for element in root.findall(

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

414 ):

415 if user:

416 item1 = QTableWidgetItem(

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

418 )

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

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

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

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

423 break

424 else:

425 if (

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

427 == value

428 ):

429 item1 = QTableWidgetItem(

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

431 )

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

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

434 widget.setItem(

435 row,

436 3,

437 QTableWidgetItem(

438 element.findtext(

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

440 )

441 ),

442 )

443 widget.setItem(

444 row,

445 4,

446 QTableWidgetItem(

447 element.findtext(

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

449 )

450 ),

451 )

452 break

453

454 # 2019-02-21 박: 다른 조건에서도 데이터 들어오게 처리

455 elif (

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

457 == value

458 ):

459 item1 = QTableWidgetItem(

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

461 )

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

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

464 widget.setItem(

465 row,

466 3,

467 QTableWidgetItem(

468 element.findtext(

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

470 )

471 ),

472 )

473 widget.setItem(

474 row,

475 4,

476 QTableWidgetItem(

477 element.findtext(

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

479 )

480 ),

481 )

482 break

483

484 # 2019-02-21 박: 다른 조건에서도 데이터 들어오게 처리

485 elif (

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

487 == value

488 ):

489 item1 = QTableWidgetItem(

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

491 )

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

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

494 widget.setItem(

495 row,

496 3,

497 QTableWidgetItem(

498 element.findtext(

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

500 )

501 ),

502 )

503 widget.setItem(

504 row,

505 4,

506 QTableWidgetItem(

507 element.findtext(

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

509 )

510 ),

511 )

512 break

513

514 elif type == "GreenAmpt":

515 for element in root.findall(

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

517 ):

518 if user:

519 item1 = QTableWidgetItem(

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

521 )

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

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

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

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

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

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

528 else:

529 if (

530 element.findtext(

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

532 )

533 == value

534 ):

535 item1 = QTableWidgetItem(

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

537 )

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

539 widget.setItem(

540 row,

541 2,

542 QTableWidgetItem(

543 element.findtext(

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

545 )

546 ),

547 )

548 widget.setItem(

549 row,

550 3,

551 QTableWidgetItem(

552 element.findtext(

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

554 )

555 ),

556 )

557 widget.setItem(

558 row,

559 4,

560 QTableWidgetItem(

561 element.findtext(

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

563 )

564 ),

565 )

566 widget.setItem(

567 row,

568 5,

569 QTableWidgetItem(

570 element.findtext(

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

572 )

573 ),

574 )

575 widget.setItem(

576 row,

577 6,

578 QTableWidgetItem(

579 element.findtext(

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

581 )

582 ),

583 )

584 break

585

586 elif (

587 element.findtext(

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

589 )

590 == value

591 ):

592 item1 = QTableWidgetItem(

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

594 )

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

596 widget.setItem(

597 row,

598 2,

599 QTableWidgetItem(

600 element.findtext(

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

602 )

603 ),

604 )

605 widget.setItem(

606 row,

607 3,

608 QTableWidgetItem(

609 element.findtext(

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

611 )

612 ),

613 )

614 widget.setItem(

615 row,

616 4,

617 QTableWidgetItem(

618 element.findtext(

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

620 )

621 ),

622 )

623 widget.setItem(

624 row,

625 5,

626 QTableWidgetItem(

627 element.findtext(

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

629 )

630 ),

631 )

632 widget.setItem(

633 row,

634 6,

635 QTableWidgetItem(

636 element.findtext(

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

638 )

639 ),

640 )

641 break

642

643 elif (

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

645 == value

646 ):

647 item1 = QTableWidgetItem(

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

649 )

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

651 widget.setItem(

652 row,

653 2,

654 QTableWidgetItem(

655 element.findtext(

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

657 )

658 ),

659 )

660 widget.setItem(

661 row,

662 3,

663 QTableWidgetItem(

664 element.findtext(

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

666 )

667 ),

668 )

669 widget.setItem(

670 row,

671 4,

672 QTableWidgetItem(

673 element.findtext(

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

675 )

676 ),

677 )

678 widget.setItem(

679 row,

680 5,

681 QTableWidgetItem(

682 element.findtext(

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

684 )

685 ),

686 )

687 widget.setItem(

688 row,

689 6,

690 QTableWidgetItem(

691 element.findtext(

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

693 )

694 ),

695 )

696 break

697

698 elif type == "SoilDepth":

699 for element in root.findall(

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

701 ):

702 if user:

703 item1 = QTableWidgetItem(

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

705 )

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

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

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

709 break

710 else:

711 if (

712 element.findtext(

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

714 )

715 == value

716 ):

717 item1 = QTableWidgetItem(

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

719 )

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

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

722 widget.setItem(

723 row,

724 3,

725 QTableWidgetItem(

726 element.findtext(

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

728 )

729 ),

730 )

731 break

732 elif (

733 element.findtext(

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

735 )

736 == value

737 ):

738 item1 = QTableWidgetItem(

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

740 )

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

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

743 widget.setItem(

744 row,

745 3,

746 QTableWidgetItem(

747 element.findtext(

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

749 )

750 ),

751 )

752 break

753 elif (

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

755 == value

756 ):

757 item1 = QTableWidgetItem(

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

759 )

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

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

762 widget.setItem(

763 row,

764 3,

765 QTableWidgetItem(

766 element.findtext(

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

768 )

769 ),

770 )

771 break

772

773 def closeForm(self):

774 self.close() # 폼 종료

775

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

777 def SetProjectValue(self):

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

779 "LandCoverDataType"

780 ]

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

782 "SoilTextureDataType"

783 ]

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

785 "SoilDepthDataType"

786 ]

787

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

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

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

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

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

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

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

795

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

797 def SetLayerListCombobox(self):

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

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

800

801 if self._grmDialogFlag == 1:

802 lly = list(layers)

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

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

805

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

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

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

809

810 # 라디오 버튼 셋팅

811 def SetRadio(self):

812 try:

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

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

815

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

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

818

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

820 self.rbtUseSoilTextureLayer.clicked.connect(

821 self.SoilTextureLayer_CheckedChanged

822 )

823

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

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

826

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

828 self.rbtUseSoilDepthLayer.clicked.connect(

829 self.SoilDepthLayer_CheckedChanged

830 )

831

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

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

834

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

836 # 2017/11/27 =====

837

838 if self.LandCoverType == "File":

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

840 self.LCLaye_CheckedChanged()

841

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

843 self.rbtUseLCLayer.setChecked(True)

844

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

846 self.txtLandCover.setText(

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

848 )

849

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

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

852 "LandCoverFile"

853 ]

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

855 LandCoverName = GetFile_Name(LandCoverFile)

856 SetCommbox2(self.cmbLandCover, LandCoverName, LandCoverFile)

857 else:

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

859 self.ConstLCAtt_CheckedChanged()

860

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

862 self.rbtUseConstLCAtt.setChecked(True)

863

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

865 self.txtCoefficient.setText(

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

867 "ConstantRoughnessCoeff"

868 ]

869 )

870 self.txtImpervious.setText(

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

872 "ConstantImperviousRatio"

873 ]

874 )

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

876

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

878 # SoilTextureVATFile 이벤트

879 if self.SoilTextureType == "File":

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

881 self.SoilTextureLayer_CheckedChanged()

882

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

884 self.rbtUseSoilTextureLayer.setChecked(True)

885

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

887 self.txtSoilTexture.setText(

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

889 "SoilTextureVATFile"

890 ]

891 )

892

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

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

895 "SoilTextureFile"

896 ]

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

898 SoilTextureName = GetFile_Name(SoilTextureFile)

899 SetCommbox2(self.cmbSoilTexture, SoilTextureName, SoilTextureFile)

900 else:

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

902 self.TextureAtt_CheckedChanged()

903

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

905 self.rbtUseConstTextureAtt.setChecked(True)

906

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

908 self.txtPorosity.setText(

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

910 "ConstantSoilPorosity"

911 ]

912 )

913 self.txtEffective_porosity.setText(

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

915 "ConstantSoilEffPorosity"

916 ]

917 )

918 self.txtSuction_head.setText(

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

920 "ConstantSoilWettingFrontSuctionHead"

921 ]

922 )

923 self.txtConductiovity.setText(

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

925 "ConstantSoilHydraulicConductivity"

926 ]

927 )

928

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

930

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

932 if self.SoilDepthType == "File":

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

934 self.SoilDepthLayer_CheckedChanged()

935

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

937 self.rbtUseSoilDepthLayer.setChecked(True)

938

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

940 self.txtSoilDepth.setText(

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

942 )

943

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

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

946 "SoilDepthFile"

947 ]

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

949 SoilDepthName = GetFile_Name(SoilDepthFile)

950 SetCommbox2(self.cmbSoilDepth, SoilDepthName, SoilDepthFile)

951 else:

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

953 self.ConstDepth_CheckedChanged()

954

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

956 self.rbtUseConstDepth.setChecked(True)

957

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

959 self.txtSoil_depth.setText(

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

961 "ConstantSoilDepth"

962 ]

963 )

964 except Exception as e:

965 MsError(e)

966

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

968 def LCLaye_CheckedChanged(self):

969 self.btnVatLand.setEnabled(True)

970 self.txtLandCover.setEnabled(True)

971 self.cmbLandCover.setEnabled(True)

972 self.tlbLandCover.setEnabled(True)

973 self.txtCoefficient.setEnabled(False)

974 self.txtImpervious.setEnabled(False)

975

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

977 def ConstLCAtt_CheckedChanged(self):

978 self.btnVatLand.setEnabled(False)

979 self.txtLandCover.setEnabled(False)

980 self.cmbLandCover.setEnabled(False)

981 self.tlbLandCover.setEnabled(False)

982 self.txtCoefficient.setEnabled(True)

983 self.txtImpervious.setEnabled(True)

984

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

986 def SoilTextureLayer_CheckedChanged(self):

987 self.cmbSoilTexture.setEnabled(True)

988 self.txtSoilTexture.setEnabled(True)

989 self.btnVatAmpt.setEnabled(True)

990 self.tblGreenAmpt.setEnabled(True)

991 self.txtPorosity.setEnabled(False)

992 self.txtEffective_porosity.setEnabled(False)

993 self.txtSuction_head.setEnabled(False)

994 self.txtConductiovity.setEnabled(False)

995

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

997 def TextureAtt_CheckedChanged(self):

998 self.cmbSoilTexture.setEnabled(False)

999 self.txtSoilTexture.setEnabled(False)

1000 self.btnVatAmpt.setEnabled(False)

1001 self.tblGreenAmpt.setEnabled(False)

1002 self.txtPorosity.setEnabled(True)

1003 self.txtEffective_porosity.setEnabled(True)

1004 self.txtSuction_head.setEnabled(True)

1005 self.txtConductiovity.setEnabled(True)

1006

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

1008 def SoilDepthLayer_CheckedChanged(self):

1009 self.cmbSoilDepth.setEnabled(True)

1010 self.txtSoilDepth.setEnabled(True)

1011 self.btnVatDepth.setEnabled(True)

1012 self.tblSoilDepth.setEnabled(True)

1013 self.txtSoil_depth.setEnabled(False)

1014

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

1016 def ConstDepth_CheckedChanged(self):

1017 self.cmbSoilDepth.setEnabled(False)

1018 self.txtSoilDepth.setEnabled(False)

1019 self.btnVatDepth.setEnabled(False)

1020 self.tblSoilDepth.setEnabled(False)

1021 self.txtSoil_depth.setEnabled(True)

1022

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

1024 def SetTableHeader(self):

1025 self.SetLandCoverHeader()

1026

1027 self.SetGreenAmptHeader()

1028

1029 self.SetSoilDepthHeader()

1030

1031 # LandCover Table 헤더 셋팅

1032 def SetLandCoverHeader(self):

1033 self.tlbLandCover.setColumnCount(5)

1034 self.tlbLandCover.setHorizontalHeaderLabels(

1035 [

1036 "GridValue",

1037 "UserLandCover",

1038 "GRMCode",

1039 "RoughnessCoefficient",

1040 "ImperviousRatio",

1041 ]

1042 )

1043

1044 # GreenAmpt Table 헤더 셋팅

1045 def SetGreenAmptHeader(self):

1046 self.tblGreenAmpt.setColumnCount(7)

1047 self.tblGreenAmpt.setHorizontalHeaderLabels(

1048 [

1049 "GridValue",

1050 "USERSoil",

1051 "GRMCode",

1052 "Porosity",

1053 "EffectivePorosity",

1054 "WFSoilSuctionHead",

1055 "HydraulicConductivity",

1056 ]

1057 )

1058

1059 # SoilDepth 테이블 헤더 셋팅

1060 def SetSoilDepthHeader(self):

1061 self.tblSoilDepth.setColumnCount(4)

1062 self.tblSoilDepth.setHorizontalHeaderLabels(

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

1064 )

1065

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

1067 def SetTableData(self):

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

1069 # 2순위 Vat 파일 셋팅

1070

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

1072 self.SetLandCoverTalbe()

1073

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

1075 self.SetGreenAmptTalbe()

1076

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

1078 self.SetSoilDepthTalbe()

1079

1080 def SetLandCoverTalbe(self):

1081 try:

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

1083 if self._LandCoverCount > 1:

1084 row = 0

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

1086 self.tlbLandCover.insertRow(row)

1087

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

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

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

1091

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

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

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

1095

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

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

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

1099

1100 self.tlbLandCover.setItem(

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

1102 )

1103 self.tlbLandCover.setItem(

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

1105 )

1106 row = row + 1

1107 elif self._LandCoverCount == 1:

1108 self.tlbLandCover.insertRow(0)

1109

1110 item1 = QTableWidgetItem(

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

1112 )

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

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

1115

1116 item2 = QTableWidgetItem(

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

1118 )

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

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

1121

1122 item3 = QTableWidgetItem(

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

1124 )

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

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

1127

1128 self.tlbLandCover.setItem(

1129 row,

1130 3,

1131 QTableWidgetItem(

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

1133 "RoughnessCoefficient"

1134 ]

1135 ),

1136 )

1137 self.tlbLandCover.setItem(

1138 row,

1139 4,

1140 QTableWidgetItem(

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

1142 ),

1143 )

1144 elif self._LandCoverCount == 0:

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

1146 self.Get_ComboBox_LayerPath(

1147 self.cmbLandCover,

1148 self.tlbLandCover,

1149 self.txtLandCover,

1150 "LandCover",

1151 )

1152

1153 except KeyError:

1154 self.Get_ComboBox_LayerPath(

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

1156 )

1157

1158 def SetGreenAmptTalbe(self):

1159 try:

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

1161 if self._GreenAmptCount > 1:

1162 row = 0

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

1164 self.tblGreenAmpt.insertRow(row)

1165

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

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

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

1169

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

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

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

1173

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

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

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

1177

1178 self.tblGreenAmpt.setItem(

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

1180 )

1181 self.tblGreenAmpt.setItem(

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

1183 )

1184 self.tblGreenAmpt.setItem(

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

1186 )

1187 self.tblGreenAmpt.setItem(

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

1189 )

1190 row = row + 1

1191 elif self._GreenAmptCount == 1:

1192 self.tblGreenAmpt.insertRow(0)

1193

1194 item1 = QTableWidgetItem(

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

1196 )

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

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

1199

1200 item2 = QTableWidgetItem(

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

1202 )

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

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

1205

1206 item3 = QTableWidgetItem(

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

1208 )

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

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

1211

1212 self.tblGreenAmpt.setItem(

1213 row,

1214 3,

1215 QTableWidgetItem(

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

1217 ),

1218 )

1219 self.tblGreenAmpt.setItem(

1220 row,

1221 4,

1222 QTableWidgetItem(

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

1224 "EffectivePorosity"

1225 ]

1226 ),

1227 )

1228 self.tblGreenAmpt.setItem(

1229 row,

1230 5,

1231 QTableWidgetItem(

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

1233 "WFSoilSuctionHead"

1234 ]

1235 ),

1236 )

1237 self.tblGreenAmpt.setItem(

1238 row,

1239 6,

1240 QTableWidgetItem(

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

1242 "HydraulicConductivity"

1243 ]

1244 ),

1245 )

1246

1247 except KeyError:

1248 self.Get_ComboBox_LayerPath(

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

1250 )

1251

1252 def SetSoilDepthTalbe(self):

1253 try:

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

1255 if self._SoilDepthCount > 1:

1256 row = 0

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

1258 self.tblSoilDepth.insertRow(row)

1259

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

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

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

1263

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

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

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

1267

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

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

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

1271

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

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

1274 row = row + 1

1275

1276 elif self._SoilDepthCount == 1:

1277 self.tblSoilDepth.insertRow(0)

1278

1279 item1 = QTableWidgetItem(

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

1281 )

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

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

1284

1285 item2 = QTableWidgetItem(

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

1287 )

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

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

1290

1291 item3 = QTableWidgetItem(

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

1293 )

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

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

1296

1297 item4 = QTableWidgetItem(

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

1299 )

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

1301 except Exception as e:

1302 self.Get_ComboBox_LayerPath(

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

1304 )

1305 MsError(e)

1306

1307 # Qdilog 창에 Qtablewidget 셋팅

1308 def aboutApp(self, type, row):

1309 global _SelectRow

1310 _SelectRow = row

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

1312 email = "comictagger@gmail.com"

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

1314 license_name = "Apache License 2.0"

1315 Project = "test"

1316 msgBox = QMessageBox()

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

1318 msgBox.setTextFormat(Qt.RichText)

1319 msgBox.setIconPixmap(QPixmap(Project))

1320 msgBox.setText(

1321 "<br><br><br><br><br><br><br><br><br><br><br>"

1322 + "<font color=white>"

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

1324 )

1325 self.addTableWidget(msgBox, type)

1326 msgBox.exec_()

1327

1328 # Create TableWidget

1329 def addTableWidget(self, parentItem, type):

1330 self.tableWidget = QTableWidget(parentItem)

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

1332 self.tableWidget.setObjectName("tableWidget")

1333 self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

1334 self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)

1335 self.paranet = parentItem

1336 if type == "LandCover":

1337 self.SetLandcoverTable(self.tableWidget)

1338 if type == "GreenAmpt":

1339 self.SetGreenAmptTable(self.tableWidget)

1340 if type == "SoilDepth":

1341 self.SetSoilDepth(self.tableWidget)

1342

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

1344 def SetLandcoverTable(self, tableWidget):

1345 doc = ET.parse(self.StaticDB)

1346 root = doc.getroot()

1347 list = []

1348 for element in root.findall(

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

1350 ):

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

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

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

1354 list.append(

1355 element.findtext(

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

1357 )

1358 )

1359 list.append(

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

1361 )

1362

1363 # table에 값 셋팅

1364 tableWidget.verticalHeader().hide()

1365 tableWidget.setColumnCount(5)

1366

1367 value = int(len(list) / 5)

1368 tableWidget.setRowCount(value)

1369 tableWidget.setHorizontalHeaderLabels(

1370 [

1371 "LandCoverE",

1372 "LandCoverK",

1373 "GRMCode",

1374 "RoughnessCoefficient",

1375 "ImperviousRatio",

1376 ]

1377 )

1378

1379 tableWidget.resizeColumnsToContents()

1380 tableWidget.resizeRowsToContents()

1381 tableWidget.itemDoubleClicked.connect(

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

1383 )

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

1385 for i in range(0, value):

1386 for j in range(0, 5):

1387 self.tableWidget.setItem(i, j, QTableWidgetItem(list[5 * i + j]))

1388

1389 def SetGreenAmptTable(self, tableWidget):

1390 # 프로젝트 파일 로드

1391 doc = ET.parse(self.StaticDB)

1392

1393 root = doc.getroot()

1394 list = []

1395 for element in root.findall(

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

1397 ):

1398 list.append(

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

1400 )

1401 list.append(

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

1403 )

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

1405 list.append(

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

1407 )

1408 list.append(

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

1410 )

1411 list.append(

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

1413 )

1414 list.append(

1415 element.findtext(

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

1417 )

1418 )

1419 list.append(

1420 element.findtext(

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

1422 )

1423 )

1424 list.append(

1425 element.findtext(

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

1427 )

1428 )

1429 list.append(

1430 element.findtext(

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

1432 )

1433 )

1434 list.append(

1435 element.findtext(

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

1437 )

1438 )

1439 list.append(

1440 element.findtext(

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

1442 )

1443 )

1444 list.append(

1445 element.findtext(

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

1447 )

1448 )

1449 list.append(

1450 element.findtext(

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

1452 )

1453 )

1454

1455 # table에 값 셋팅

1456 tableWidget.verticalHeader().hide()

1457 tableWidget.setColumnCount(14)

1458

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

1460 tableWidget.setRowCount(value)

1461 tableWidget.setHorizontalHeaderLabels(

1462 [

1463 "SoilTextureE",

1464 "SoilTextureK",

1465 "GRMCode",

1466 "PorosityMin",

1467 "PorosityMax",

1468 "PorosityDefault",

1469 "EffectivePorosityMin",

1470 "EffectivePorosityMax",

1471 "EffectivePorosityDefault",

1472 "ResidualMoistureContent",

1473 "WFSoilSuctionHeadMin",

1474 "WFSoilSuctionHeadMax",

1475 "WFSoilSuctionHeadDefault",

1476 "HydraulicConductivity",

1477 ]

1478 )

1479

1480 tableWidget.resizeColumnsToContents()

1481 tableWidget.resizeRowsToContents()

1482 tableWidget.itemDoubleClicked.connect(

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

1484 )

1485

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

1487 for i in range(0, value):

1488 for j in range(0, 14):

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

1490

1491 def SetSoilDepth(self, tableWidget):

1492 doc = ET.parse(self.StaticDB)

1493

1494 root = doc.getroot()

1495 list = []

1496 for element in root.findall(

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

1498 ):

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

1500 list.append(

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

1502 )

1503 list.append(

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

1505 )

1506 list.append(

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

1508 )

1509 list.append(

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

1511 )

1512 list.append(

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

1514 )

1515

1516 # table에 값 셋팅

1517 tableWidget.verticalHeader().hide()

1518 tableWidget.setColumnCount(6)

1519

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

1521

1522 tableWidget.setRowCount(value)

1523 tableWidget.setHorizontalHeaderLabels(

1524 [

1525 "GRMCode",

1526 "SoilDepthClassE",

1527 "SoilDepthClassK",

1528 "SoilDepthMin",

1529 "SoilDepthMax",

1530 "SoilDepth",

1531 ]

1532 )

1533

1534 tableWidget.resizeColumnsToContents()

1535 tableWidget.resizeRowsToContents()

1536 tableWidget.itemDoubleClicked.connect(

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

1538 )

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

1540 for i in range(0, value):

1541 for j in range(0, 6):

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

1543

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

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

1546 def SelectCellValue(self, tableWidget, type):

1547 row = tableWidget.currentRow()

1548 try:

1549 items = []

1550

1551 if type == "LandCover":

1552 item2 = tableWidget.item(row, 0)

1553 item3 = tableWidget.item(row, 1)

1554 item4 = tableWidget.item(row, 2)

1555 item5 = tableWidget.item(row, 3)

1556 item6 = tableWidget.item(row, 4)

1557

1558 items = [item4, item5, item6]

1559 tbl = self.tlbLandCover

1560

1561 # self.tlbLandCover.item(_SelectRow, 1).setText(item3.text())

1562 # self.tlbLandCover.item(_SelectRow, 2).setText(item4.text())

1563 # self.tlbLandCover.item(_SelectRow, 3).setText(item5.text())

1564 # self.tlbLandCover.item(_SelectRow, 4).setText(item6.text())

1565 # 메시지 박스 종료

1566 # self.paranet.done(1)

1567

1568 elif type == "GreenAmpt":

1569 item2 = tableWidget.item(row, 0)

1570 item3 = tableWidget.item(row, 1)

1571 item4 = tableWidget.item(row, 2)

1572 item5 = tableWidget.item(row, 5)

1573 item6 = tableWidget.item(row, 8)

1574 item7 = tableWidget.item(row, 12)

1575 item8 = tableWidget.item(row, 13)

1576

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

1578 tbl = self.tblGreenAmpt

1579

1580 # self.tblGreenAmpt.item(_SelectRow, 1).setText(item3.text())

1581 # self.tblGreenAmpt.item(_SelectRow, 2).setText(item4.text())

1582 # self.tblGreenAmpt.item(_SelectRow, 3).setText(item5.text())

1583 # self.tblGreenAmpt.item(_SelectRow, 4).setText(item6.text())

1584 # self.tblGreenAmpt.item(_SelectRow, 5).setText(item7.text())

1585 # self.tblGreenAmpt.item(_SelectRow, 6).setText(item8.text())

1586

1587 # 메시지 박스 종료

1588 # self.paranet.done(1)

1589

1590 elif type == "SoilDepth":

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

1596 items = [item2, item5]

1597 tbl = self.tblSoilDepth

1598

1599 # self.tblSoilDepth.item(_SelectRow, 2).setText(item2.text())

1600 # self.tblSoilDepth.item(_SelectRow, 3).setText(item5.text())

1601

1602 for i, it in enumerate(items):

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

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

1605 else:

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

1607

1608 # 메시지 박스 종료

1609 # self.paranet.done(1)

1610 except AttributeError as e:

1611 print(e)

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

1613 finally:

1614 self.paranet.done(1)

1615

1616 def DataSave(self):

1617 if self.rbtUseLCLayer.isChecked():

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

1619 "LandCoverDataType"

1620 ] = "File"

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

1622 LandCoverLayerPath = GetcomboSelectedLayerPath(self.cmbLandCover)

1623 else:

1624 LandCoverLayerPath = ""

1625

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

1627 "LandCoverFile"

1628 ] = LandCoverLayerPath

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

1630 "LandCoverVATFile"

1631 ] = self.txtLandCover.text()

1632 self.dataSeve_Landcover()

1633 else:

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

1635 "LandCoverDataType"

1636 ] = "Constant"

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

1638 "ConstantRoughnessCoeff"

1639 ] = self.txtCoefficient.text()

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

1641 "ConstantImperviousRatio"

1642 ] = self.txtImpervious.text()

1643

1644 # 타입 설정

1645 if self.rbtUseSoilTextureLayer.isChecked():

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

1647 "SoilTextureDataType"

1648 ] = "File"

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

1650 SoilTextureLayerPath = GetcomboSelectedLayerPath(self.cmbSoilTexture)

1651 else:

1652 SoilTextureLayerPath = ""

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

1654 "SoilTextureFile"

1655 ] = SoilTextureLayerPath

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

1657 "SoilTextureVATFile"

1658 ] = self.txtSoilTexture.text()

1659 self.dataSeve_SoilTexture()

1660 else:

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

1662 "SoilTextureDataType"

1663 ] = "Constant"

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

1665 "ConstantSoilPorosity"

1666 ] = self.txtPorosity.text()

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

1668 "ConstantSoilEffPorosity"

1669 ] = self.txtEffective_porosity.text()

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

1671 "ConstantSoilWettingFrontSuctionHead"

1672 ] = self.txtSuction_head.text()

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

1674 "ConstantSoilHydraulicConductivity"

1675 ] = self.txtConductiovity.text()

1676

1677 # 타입 설정

1678 if self.rbtUseSoilDepthLayer.isChecked():

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

1680 "SoilDepthDataType"

1681 ] = "File"

1682

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

1684 SoilDepthLayerPath = GetcomboSelectedLayerPath(self.cmbSoilDepth)

1685 else:

1686 SoilDepthLayerPath = ""

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

1688 "SoilDepthFile"

1689 ] = SoilDepthLayerPath

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

1691 "SoilDepthVATFile"

1692 ] = self.txtSoilDepth.text()

1693 self.dataSeve_SoilDepth()

1694 else:

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

1696 "SoilDepthDataType"

1697 ] = "Constant"

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

1699 "ConstantSoilDepth"

1700 ] = self.txtSoil_depth.text()

1701

1702 def dataSeve_Landcover(self):

1703 try:

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

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

1706 if check is not None:

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

1708 except:

1709 pass

1710

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

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

1713 DictoXml = unparse(self._xmltodict)

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

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

1716 root = xmltree.getroot()

1717 count = self.tlbLandCover.rowCount()

1718 self._LandCoverCount = count

1719

1720 try:

1721 for row in range(0, count):

1722 child = ET.Element("LandCover")

1723 root.append(child)

1724

1725 GridValue = ET.Element("GridValue")

1726 # 특수문자 있음 제외 함

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

1728 child.append(GridValue)

1729

1730 UserLandCover = ET.Element("UserLandCover")

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

1732 child.append(UserLandCover)

1733

1734 GRMLandCoverCode = ET.Element("GRMCode")

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

1736 child.append(GRMLandCoverCode)

1737

1738 RoughnessCoefficient = ET.Element("RoughnessCoefficient")

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

1740 child.append(RoughnessCoefficient)

1741

1742 ImperviousRatio = ET.Element("ImperviousRatio")

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

1744 child.append(ImperviousRatio)

1745

1746 filepath = tempfile.mktemp()

1747 xmltree.write(filepath)

1748

1749 # Dictionary 초기화

1750 self._xmltodict.clear()

1751

1752 # 파일 읽어 오기

1753 Projectfile = open(filepath, "r")

1754 data = Projectfile.read()

1755 Projectfile.close()

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

1757 docs = dict(parse(data))

1758 self._xmltodict.update(docs)

1759 except Exception as e:

1760 pass

1761

1762 def dataSeve_SoilTexture(self):

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

1764 try:

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

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

1767 if check is not None:

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

1769 except:

1770 pass

1771

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

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

1774 DictoXml = unparse(self._xmltodict)

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

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

1777 root = xmltree.getroot()

1778 count = self.tblGreenAmpt.rowCount()

1779 self._GreenAmptCount = count

1780 for row in range(0, count):

1781 child = ET.Element("GreenAmptParameter")

1782 root.append(child)

1783

1784 GridValue = ET.Element("GridValue")

1785 # 특수문자 있음 제외 함

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

1787 child.append(GridValue)

1788

1789 USERSoil = ET.Element("USERSoil")

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

1791 child.append(USERSoil)

1792

1793 GRMCode = ET.Element("GRMCode")

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

1795 child.append(GRMCode)

1796

1797 Porosity = ET.Element("Porosity")

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

1799 child.append(Porosity)

1800

1801 EffectivePorosity = ET.Element("EffectivePorosity")

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

1803 child.append(EffectivePorosity)

1804

1805 WFSoilSuctionHead = ET.Element("WFSoilSuctionHead")

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

1807 child.append(WFSoilSuctionHead)

1808

1809 HydraulicConductivity = ET.Element("HydraulicConductivity")

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

1811 child.append(HydraulicConductivity)

1812

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

1814 filepath = tempfile.mktemp()

1815 xmltree.write(filepath)

1816

1817 # Dictionary 초기화

1818 self._xmltodict.clear()

1819

1820 # 파일 읽어 오기

1821 Projectfile = open(filepath, "r")

1822 data = Projectfile.read()

1823 Projectfile.close()

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

1825 docs = dict(parse(data))

1826 self._xmltodict.update(docs)

1827

1828 def dataSeve_SoilDepth(self):

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

1830 try:

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

1832 if check is not None:

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

1834 except:

1835 pass

1836

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

1838 DictoXml = unparse(self._xmltodict)

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

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

1841 root = xmltree.getroot()

1842 count = self.tblSoilDepth.rowCount()

1843 self._SoilDepthCount = count

1844 for row in range(0, count):

1845 child = ET.Element("SoilDepth")

1846 root.append(child)

1847

1848 GridValue = ET.Element("GridValue")

1849 # 특수문자 있음 제외 함

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

1851 child.append(GridValue)

1852

1853 UserDepthClass = ET.Element("UserDepthClass")

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

1855 child.append(UserDepthClass)

1856

1857 GRMDepthCode = ET.Element("GRMCode")

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

1859 child.append(GRMDepthCode)

1860

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

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

1863 # child.append(SoilDepthClassE)

1864 #

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

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

1867 # child.append(SoilDepthClassK)

1868

1869 SoilDepth = ET.Element("SoilDepth_cm")

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

1871 child.append(SoilDepth)

1872

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

1874 filepath = tempfile.mktemp()

1875 xmltree.write(filepath)

1876

1877 # Dictionary 초기화

1878 self._xmltodict.clear()

1879

1880 # 파일 읽어 오기

1881 Projectfile = open(filepath, "r")

1882 data = Projectfile.read()

1883 Projectfile.close()

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

1885 docs = dict(parse(data))

1886 self._xmltodict.update(docs)

1887

1888 def isFloat(self, Snumber):

1889 try:

1890 float(Snumber)

1891 return True

1892 except ValueError:

1893 return False