Skip to content

Commit

Permalink
Merge pull request #33 from MIERUNE/feat/custom-extent
Browse files Browse the repository at this point in the history
Feat/custom extent
  • Loading branch information
nbayashi authored Jun 14, 2024
2 parents 69044f3 + a3393bc commit 2ac59ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
18 changes: 17 additions & 1 deletion elevation_tile_for_jp_dialog_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>517</width>
<height>140</height>
<height>355</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -131,6 +131,10 @@
</item>
</layout>
</item>
<item>
<widget class="QgsExtentGroupBox" name="mExtentGroupBox">
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="orientation">
Expand All @@ -144,6 +148,18 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsExtentGroupBox</class>
<extends>QgsCollapsibleGroupBox</extends>
<header>qgsextentgroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
Expand Down
42 changes: 28 additions & 14 deletions get_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import os
from math import log

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

from elevation_tile_for_jp_dialog import ElevationTileforJPDialog

Expand Down Expand Up @@ -59,6 +62,13 @@ def __init__(self, iface):
# プロジェクトのデフォルトのcrsを格納
self.dlg.mQgsProjectionSelectionWidget_output_crs.setCrs(self.project.crs())

# set extent as current map canvas with current CRS
# QgsExtentGroupBox
self.dlg.mExtentGroupBox.setMapCanvas(iface.mapCanvas())
self.dlg.mExtentGroupBox.setOutputCrs(QgsProject.instance().crs())
self.dlg.mExtentGroupBox.setOutputExtentFromCurrent()
QgsProject.instance().crsChanged.connect(self.on_map_crs_changed)

# コンボボックスにズームレベルを設定
self.setup_zoom_level_combo_box()

Expand All @@ -67,6 +77,11 @@ def __init__(self, iface):
# ダイアログのボタンボックスがrejected(キャンセル)されたらdlg_cancel()が作動
self.dlg.button_box.rejected.connect(self.dlg_cancel)

# update extent crs when updated
def on_map_crs_changed(self):
self.dlg.mExtentGroupBox.setOutputCrs(QgsProject.instance().crs()),
self.dlg.mExtentGroupBox.setOutputExtentFromCurrent()

# キャンセルクリック
def dlg_cancel(self):
# ダイアログを非表示
Expand Down Expand Up @@ -143,16 +158,15 @@ def get_current_zoom(self):
round(log(((dpi * inchesPerMeter * maxScalePerPixel) / scale), 2), 0)
)

# map_canvasのXY座標のminとmaxを取得
# 対象領域のXY座標のminとmaxを取得
def get_canvas_bbox(self):
extent = self.iface.mapCanvas().extent()
xmin, xmax, ymin, ymax = (
float(extent.xMinimum()),
float(extent.xMaximum()),
float(extent.yMinimum()),
float(extent.yMaximum()),
)
return [xmin, ymin, xmax, ymax]
extent = [
self.dlg.mExtentGroupBox.outputExtent().xMinimum(),
self.dlg.mExtentGroupBox.outputExtent().yMinimum(),
self.dlg.mExtentGroupBox.outputExtent().xMaximum(),
self.dlg.mExtentGroupBox.outputExtent().yMaximum(),
]
return extent

def transform(self, src_crs, bbox, dst_crs_id="EPSG:4326"):
dst_crs = QgsCoordinateReferenceSystem(dst_crs_id)
Expand Down

0 comments on commit 2ac59ed

Please sign in to comment.