Skip to content

Commit

Permalink
Merge pull request #73 from MIERUNE/fix/input-data
Browse files Browse the repository at this point in the history
Handle multi xml in plugin
  • Loading branch information
nbayashi authored Jul 9, 2024
2 parents 63f2150 + 158b061 commit da9676e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 32 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name:
export_plugin
on:
release:
types: [published]

env:
PLUGIN_NAME: QuickDEM4JP
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create Plugin Directory
run: |
mkdir ${{env.PLUGIN_NAME}}
find . -type f | grep -ve './.git' \
-ve '.github' \
-ve './.vscode' \
-ve '__pycache__/' \
-ve './tests' \
-ve './pyproject.toml' \
-ve './poetry.toml' \
-ve './poetry.lock' | xargs -I src cp --parents src ${{env.PLUGIN_NAME}}
- name: Create Archive
run: |
zip -r ${{env.PLUGIN_NAME}}.zip ./${{env.PLUGIN_NAME}}
- name: Upload release asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.event.release.tag_name }} ${{env.PLUGIN_NAME}}.zip#${{env.PLUGIN_NAME}}
66 changes: 35 additions & 31 deletions contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

import os

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from qgis.core import *
from qgis.gui import *
from qgis.core import QgsProject, QgsRasterLayer
from qgis.gui import QgsFileWidget
from PyQt5.QtWidgets import QMessageBox


from .quick_dem_for_jp_dialog import QuickDEMforJPDialog
from .convert_fgd_dem.src.convert_fgd_dem.converter import Converter
Expand All @@ -39,14 +38,21 @@ def __init__(self, iface):
self.dlg = QuickDEMforJPDialog()

self.dlg.mQgsFileWidget_inputPath.setFilePath(QgsProject.instance().homePath())
self.dlg.mQgsFileWidget_inputPath.setStorageMode(QgsFileWidget.GetMultipleFiles)
self.dlg.mQgsFileWidget_inputPath.setFilter("*.xml;;*.zip")

self.dlg.mQgsFileWidget_outputPath.setFilePath(QgsProject.instance().homePath())
self.dlg.mQgsFileWidget_outputPath.setStorageMode(QgsFileWidget.StorageMode.SaveFile)
self.dlg.mQgsFileWidget_outputPath.setStorageMode(
QgsFileWidget.StorageMode.SaveFile
)
self.dlg.mQgsFileWidget_outputPath.setFilter("*.tiff")
self.dlg.mQgsFileWidget_outputPath.setDialogTitle("保存ファイルを選択してください")
self.dlg.mQgsFileWidget_outputPath.setDialogTitle(
"保存ファイルを選択してください"
)

self.dlg.mQgsProjectionSelectionWidget_outputCrs.setCrs(QgsProject.instance().crs())
self.dlg.mQgsProjectionSelectionWidget_outputCrs.setCrs(
QgsProject.instance().crs()
)

input_type = {
"'xml' または 'xml'を含む'zip'": 1,
Expand All @@ -65,69 +71,65 @@ def convert(self, filename, rgbify):
output_path=os.path.dirname(self.output_path),
output_epsg=self.output_epsg,
file_name=filename,
rgbify=rgbify
rgbify=rgbify,
)
converter.dem_to_geotiff()

def add_layer(self, tiff_name, layer_name):
layer = QgsRasterLayer(
os.path.join(os.path.dirname(self.output_path), tiff_name),
layer_name
os.path.join(os.path.dirname(self.output_path), tiff_name), layer_name
)
QgsProject.instance().addMapLayer(layer)

def convert_DEM(self):
do_GeoTiff = self.dlg.checkBox_outputGeoTiff.isChecked()
do_TerrainRGB = self.dlg.checkBox_outputTerrainRGB.isChecked()
if not do_GeoTiff and not do_TerrainRGB:
QMessageBox.information(None, 'エラー', u'出力形式にチェックを入れてください')
QMessageBox.information(
None, "エラー", "出力形式にチェックを入れてください"
)
return

self.import_path = self.dlg.mQgsFileWidget_inputPath.filePath()
if not self.import_path:
QMessageBox.information(None, 'エラー', u'DEMの入力先パスを入力してください')
QMessageBox.information(None, "エラー", "DEMの入力先パスを入力してください")
return

self.output_path = self.dlg.mQgsFileWidget_outputPath.filePath()
if not self.output_path:
QMessageBox.information(None, 'エラー', u'DEMの出力先パスを入力してください')
QMessageBox.information(None, "エラー", "DEMの出力先パスを入力してください")
return

self.output_epsg = self.dlg.mQgsProjectionSelectionWidget_outputCrs.crs().authid()
self.output_epsg = (
self.dlg.mQgsProjectionSelectionWidget_outputCrs.crs().authid()
)
if not self.output_epsg:
QMessageBox.information(None, 'エラー', u'DEMの出力CRSを入力してください')
QMessageBox.information(None, "エラー", "DEMの出力CRSを入力してください")
return

do_add_layer = self.dlg.checkBox_openLayers.isChecked()

try:
if do_GeoTiff:
filename = os.path.basename(self.output_path)
self.convert(
filename=filename,
rgbify=False
)
self.convert(filename=filename, rgbify=False)
if do_add_layer:
self.add_layer(
tiff_name=filename,
layer_name=os.path.splitext(filename)[0]
tiff_name=filename, layer_name=os.path.splitext(filename)[0]
)
if do_TerrainRGB:
filename = f'{os.path.splitext(self.output_path)[0]}_Terrain-RGB{os.path.splitext(os.path.basename(self.output_path))[1]}'
self.convert(
filename=filename,
rgbify=True
)
filename = f"{os.path.splitext(self.output_path)[0]}_Terrain-RGB{os.path.splitext(os.path.basename(self.output_path))[1]}"
self.convert(filename=filename, rgbify=True)
if do_add_layer:
self.add_layer(
tiff_name=filename,
layer_name=f'{os.path.splitext(os.path.basename(self.output_path))[0]}_Terrain-RGB'
layer_name=f"{os.path.splitext(os.path.basename(self.output_path))[0]}_Terrain-RGB",
)
except Exception as e:
QMessageBox.information(None, 'エラー', f'{e}')
QMessageBox.information(None, "エラー", f"{e}")
return

QMessageBox.information(None, '完了', u'処理が完了しました')
QMessageBox.information(None, "完了", "処理が完了しました")
self.dlg.hide()

return True
Expand All @@ -137,6 +139,8 @@ def dlg_cancel(self):

def switch_input_type(self):
if self.dlg.comboBox_inputType.currentData() == 1:
self.dlg.mQgsFileWidget_inputPath.setStorageMode(QgsFileWidget.GetMultipleFiles)
self.dlg.mQgsFileWidget_inputPath.setStorageMode(
QgsFileWidget.GetMultipleFiles
)
else:
self.dlg.mQgsFileWidget_inputPath.setStorageMode(QgsFileWidget.GetDirectory)
2 changes: 1 addition & 1 deletion convert_fgd_dem

0 comments on commit da9676e

Please sign in to comment.