Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

入力ファイルの制限なし #23

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions dem_to_csmap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from PyQt5.QtWidgets import QDialog
from qgis.core import Qgis
from qgis.gui import QgsFileWidget
from qgis.PyQt import uic
from qgis.utils import iface
Expand All @@ -18,10 +19,8 @@ def __init__(self):
# ウィンドウタイトル
self.setWindowTitle("CSMap Plugin")

# QGISでサポートされているラスタデータのみ選択可能
self.ui.mQgsFileWidget.setFilter(
"*.tif;;*.tiff;;*.dt0;;*.dt1;;*.dt2;;*.dem;;*.asc;;*.adf;;*.hgt;;*.bil;;*.nc;;*.img;;*.flt;;*.bt;;*.xyz;;*.grd;;*.ter"
)
# 入力データの制限
self.ui.mQgsFileWidget_input.setFilter("*")
Kanahiro marked this conversation as resolved.
Show resolved Hide resolved
Kanahiro marked this conversation as resolved.
Show resolved Hide resolved

# 出力データの設定
self.ui.mQgsFileWidget_output.setFilter("*.tif")
Expand All @@ -35,17 +34,29 @@ def convert_dem_to_csmap(self):
params = process.CsmapParams()

# 入力・出力をUIで操作
input_path = self.ui.mQgsFileWidget.filePath()
input_path = self.ui.mQgsFileWidget_input.filePath()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

変数名に、キャメルケースとスネークケースは混ぜない方がよいです。
コーディング規約になんか書いてあったかなと読み返すと、書いてなかった。。。
Pythonでは一般的にスネークケースが使われます。ただし、QtのAPIはキャメルケースなので、それらに関する変数名はキャメルケースでも構いません。

output_path = self.ui.mQgsFileWidget_output.filePath()

process.process(
input_path,
output_path,
chunk_size=256,
params=params,
)
# comment

try:
process.process(
input_path,
output_path,
chunk_size=256,
params=params,
)
except Exception as e:
iface.messageBar().pushMessage(
"ERROR",
f"DEMデータの処理中に問題が発生しました.: {e}",
level=Qgis.Critical,
)
Kanahiro marked this conversation as resolved.
Show resolved Hide resolved
return
Kanahiro marked this conversation as resolved.
Show resolved Hide resolved

# 出力結果をQGISに追加
iface.addRasterLayer(output_path, os.path.basename(output_path))

self.close()
# 処理終了後にウィンドウを閉じるオプション
if self.ui.checkBox_closeAfterProcessing.isChecked():
self.close()
14 changes: 12 additions & 2 deletions dem_to_csmap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>389</width>
<height>168</height>
<height>191</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -22,7 +22,7 @@
</widget>
</item>
<item>
<widget class="QgsFileWidget" name="mQgsFileWidget"/>
<widget class="QgsFileWidget" name="mQgsFileWidget_input"/>
</item>
<item>
<widget class="QLabel" name="label_2">
Expand All @@ -34,13 +34,23 @@
<item>
<widget class="QgsFileWidget" name="mQgsFileWidget_output"/>
</item>
<item>
<widget class="QCheckBox" name="checkBox_closeAfterProcessing">
<property name="text">
<string>処理終了後,自動でウィンドウを閉じる</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_cancel">
<property name="text">
<string>Cancel</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand Down
Loading