This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layers = [] | |
layers.append(QgsMapCanvasLayer(meshPolyLayer)) | |
layers.append(QgsMapCanvasLayer(chirin_layer)) | |
mesh_canvas.setLayerSet(layers) | |
iface.mapCanvas().extentsChanged.connect(redraw_mesh) #表示範囲変更トリガーに処理を紐付ける | |
redraw_mesh() | |
mesh_canvas.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redraw_mesh(): | |
e_mesh = res_extent_mesh() | |
if e_mesh["xRange"] < 50: #表示範囲の幅が50°以下であれば、メッシュを描画 | |
meshPolyLayer.startEditing() | |
meshPolyLayer.selectAll() | |
meshPolyLayer.deleteSelectedFeatures() #メッシュの消去 | |
if e_mesh["xRange"] > 2.0: #横幅2°以上で1次メッシュを描画 | |
draw_m1d(e_mesh) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.core import QgsMapLayerRegistry,QgsVectorLayer,QgsField | |
from PyQt4 import QtCore, QtGui | |
meshPolyLayer = QgsVectorLayer("polygon?crs=postgis:4612",u"地域メッシュインデックス","memory") #メモリレイヤの作成 | |
renderer = meshPolyLayer.rendererV2() | |
renderer.symbols()[0].symbolLayers()[0].setFillColor(QtGui.QColor(0,0,0,0)) #ポリゴンの透過 | |
renderer.symbols()[0].symbolLayers()[0].setBorderWidth(0.1) #アウトラインの線の太さ | |
meshPolyLayer.startEditing() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.core import QgsFeature,QgsPoint,QgsGeometry | |
def draw_m1d(e_mesh): #1次メッシュの描画 | |
x = e_mesh["Lx1d"] -1 | |
while x <= e_mesh["Rx1d"] + 1: | |
y = e_mesh["Ly1d"] | |
while y <= e_mesh["Uy1d"]: | |
f = QgsFeature(meshPolyLayer.pendingFields()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.core import QgsCoordinateReferenceSystem,QgsCoordinateTransform | |
def res_extent_mesh(): | |
main_crs = iface.mapCanvas().mapSettings().destinationCrs() #メインMapCanvasのCRSの取得 | |
Trs_laln = QgsCoordinateTransform(main_crs,QgsCoordinateReferenceSystem(4612)) #緯度経度への投影法変換インスタンスの作成 | |
my_rect = iface.mapCanvas().extent() #メインMapCanvasの範囲の取得 | |
laln_rect = Trs_laln.transform(my_rect) #緯度経度に変換 | |
x_min = laln_rect.xMinimum() | |
x_max = laln_rect.xMaximum() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def res_mesh_index(latitude,longitude): | |
x1d = math.floor(longitude - 100) | |
x2d = math.floor((longitude - x1d - 100 ) * 8 ) | |
x3d = math.floor((longitude - x1d - 100 - x2d/8.0 )*80 ) | |
y1d = math.floor(latitude*1.5) | |
y2d = math.floor((latitude*1.5 - y1d ) * 8 ) | |
y3d = math.floor((latitude*1.5 - y1d - y2d/8.0 )*80 ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis._gui import QgsMapCanvasLayer | |
layers = [] #空のリストを作成 | |
layers.append(QgsMapCanvasLayer(chirin_layer)) #chirin_layerをマップキャンバスレイヤに変換し、リストに追加 | |
mesh_canvas.setLayerSet(layers) #mesh_canvasにレイヤリストをセットする | |
mesh_canvas.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
sys.path.append(os.path.expanduser('~/.qgis2/python/plugins/TileLayerPlugin')) #TileLayerPluginへパスを通す | |
from tilelayerplugin import TileLayerPlugin #必要なモジュールをインポートする | |
from TileLayerPlugin.tiles import BoundingBox, TileLayerDefinition | |
from TileLayerPlugin.tilelayer import TileLayer, TileLayerType | |
from qgis.utils import plugins | |
bbox = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis._gui import QgsMapCanvas | |
from PyQt4 import QtCore, QtGui | |
mesh_canvas = QgsMapCanvas() | |
mesh_canvas.setWheelAction( QgsMapCanvas.WheelZoom, 1) #WheelZoomを無効にする | |
mesh_canvas.setDestinationCrs( iface.mapCanvas().mapSettings().destinationCrs()) #メインMapCanvasと同じCRSに設定 | |
mesh_canvas.setCrsTransformEnabled( True) #CRSの変更を許可する | |
mesh_canvas.setExtent( iface.mapCanvas().extent()) #表示範囲をメインMapCanvasにあわせる | |
mesh_canvas.setWindowFlags( QtCore.Qt.WindowStaysOnTopHint) #サブMapCanvasを常に最前面に表示する |