# Coverage for grm\plugin\grid_layer.py : 0%

## 37 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1# -*- coding: utf-8 -*-

2 from math import ceil

3

4 from qgis.core import *

5 from qgis.gui import *

6 from PyQt5.QtWidgets import *

7

8 def get_point_layer(map_layer, canvas):

9

10 xmin, ymin, xmax, ymax = map_layer.extent().toRectF().getCoords()

11 crs = map_layer.crs().toWkt()

12 point_layer = QgsVectorLayer('Polygon?crs=' + crs, 'grid_line', 'memory')

13 point_provider = point_layer.dataProvider()

14

15 gridWidth =map_layer.rasterUnitsPerPixelX() #2017.11.1 원영진 수정

16 gridHeight = map_layer.rasterUnitsPerPixelY() #2017.11.1 원영진 수정

17

18 rows = ceil((ymax-ymin)/gridHeight)

19 cols = ceil((xmax-xmin)/gridWidth)

20 ringXleftOrigin = xmin

21 ringXrightOrigin = xmin + gridWidth

22 ringYtopOrigin = ymax

23 ringYbottomOrigin = ymax-gridHeight

24 for i in range(int(cols)):

25 ringYtop = ringYtopOrigin

26 ringYbottom =ringYbottomOrigin

27 for j in range(int(rows)):

28 poly = [QgsPointXY(ringXleftOrigin, ringYtop),QgsPointXY(ringXrightOrigin, ringYtop),QgsPointXY(ringXrightOrigin, ringYbottom),QgsPointXY(ringXleftOrigin, ringYbottom),QgsPointXY(ringXleftOrigin, ringYtop)]

29 feat = QgsFeature()

30 feat.setGeometry(QgsGeometry().fromPolygonXY([poly]))

31 point_provider.addFeatures([feat])

32 point_layer.updateExtents()

33

34 ringYtop = ringYtop - gridHeight

35 ringYbottom = ringYbottom - gridHeight

36 ringXleftOrigin = ringXleftOrigin + gridWidth

37 ringXrightOrigin = ringXrightOrigin + gridWidth

38

39

40 myRenderer = point_layer.renderer()

41

42 if point_layer.geometryType() == 2:

43

44 # 2017-12-07 박 두께 및 색상 변경

45 properties = {'color': '255,0,0,0','width_border': '0.09' , 'color_border': '0,0,0,127'}

46 mySymbol1 = QgsFillSymbol.createSimple(properties)

47

48 myRenderer.setSymbol(mySymbol1)

49 point_layer.triggerRepaint()

50

51 return point_layer