-
Notifications
You must be signed in to change notification settings - Fork 4
/
GridMod.py
60 lines (49 loc) · 1.55 KB
/
GridMod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Try combining the functions in custom labels for two grids with 1000 meter interval lines.
first:
if(left(right( @grid_number , 4),1) = 0,
if( @grid_axis = 'x', longNumber( @grid_number ), ''),
shortNumber( @grid_number ))
second:
if(left(right( @grid_number , 4),1) = 0,
if( @grid_axis = 'y', longNumber( @grid_number ), ''),
'' )
Klas Karlsson
"""
from qgis.core import *
from qgis.gui import *
@qgsfunction(args='auto', group='Custom')
def shortNumber(gridNumber, feature, parent):
"""
Converts coordinates to "kilometer grid index".
<h3>Example:</h3>
<code>shortNumber(123456) -> '23'</code>
<h3>Tips</h3>
Try:
<code>shortNumber( @grid_number )</code>
"""
gridString = str(int(gridNumber))
return gridString[len(gridString)-5:len(gridString)-3]
@qgsfunction(args='auto', group='Custom')
def longNumber(gridNumber, feature, parent):
"""
Converts coordinates to "kilometer grid index" with superscript characters to create a "full" coordinate.
<h3>Example:</h3>
<code>longNumber(123456) -> '<sup>1</sup>23<sup>456</sup>'</code>
<h3>Tips</h3>
Try:
<code>longNumber( @grid_number )</code>
<h3>Unicode Font</h3>
You need to select a font that supports unicode for this to work.
"""
gridString = str(int(gridNumber))
fullString = ''
supScr = (u'\u2070',u'\u00B9',u'\u00B2',u'\u00B3',u'\u2074',u'\u2075',u'\u2076',u'\u2077',u'\u2078',u'\u2079')
charNumber = len(gridString)
for char in gridString:
if charNumber == 5 or charNumber == 4:
fullString += char
else:
fullString += supScr[int(char)]
charNumber -= 1
return fullString