Skip to content

Commit

Permalink
Merge pull request #22 from MIERUNE/feature/save-as-name
Browse files Browse the repository at this point in the history
feature:出力先で名前をつけて保存
  • Loading branch information
Kanahiro authored Jun 7, 2024
2 parents cbc549c + c0f6362 commit 86e6564
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
20 changes: 13 additions & 7 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.gui import QgsFileWidget
from qgis.PyQt import uic
from qgis.utils import iface

Expand All @@ -16,11 +17,17 @@ 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_.setStorageMode(1)
self.ui.mQgsFileWidget.setFilter(
"*.tif;;*.tiff;;*.dt0;;*.dt1;;*.dt2;;*.dem;;*.asc;;*.adf;;*.hgt;;*.bil;;*.nc;;*.img;;*.flt;;*.bt;;*.xyz;;*.grd;;*.ter"
)

# 出力データの設定
self.ui.mQgsFileWidget_output.setFilter("*.tif")
self.ui.mQgsFileWidget_output.setStorageMode(QgsFileWidget.StorageMode.SaveFile)

# ボタンのクリックイベント
self.ui.pushButton_run.clicked.connect(self.convert_dem_to_csmap)
self.ui.pushButton_cancel.clicked.connect(self.close)

Expand All @@ -29,8 +36,7 @@ def convert_dem_to_csmap(self):

# 入力・出力をUIで操作
input_path = self.ui.mQgsFileWidget.filePath()
output_dir = self.ui.mQgsFileWidget_.filePath()
output_path = os.path.join(output_dir, 'csmap.tif')
output_path = self.ui.mQgsFileWidget_output.filePath()

process.process(
input_path,
Expand All @@ -39,7 +45,7 @@ def convert_dem_to_csmap(self):
params=params,
)

# csmap.tifをQGISに読み込む
iface.addRasterLayer(output_path)
# 出力結果をQGISに追加
iface.addRasterLayer(output_path, os.path.basename(output_path))

self.close()
6 changes: 3 additions & 3 deletions dem_to_csmap.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<width>389</width>
<height>168</height>
</rect>
</property>
Expand All @@ -27,12 +27,12 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>出力フォルダ</string>
<string>出力レイヤ</string>
</property>
</widget>
</item>
<item>
<widget class="QgsFileWidget" name="mQgsFileWidget_"/>
<widget class="QgsFileWidget" name="mQgsFileWidget_output"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
Expand Down

0 comments on commit 86e6564

Please sign in to comment.