-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexpressions.py
245 lines (222 loc) · 7.94 KB
/
expressions.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# -*- coding: utf-8 -*-
"""
/***************************************************************************
becagis
A QGIS plugin
GeoPorocessing Tools based on lftools https://github.com/LEOXINGU/lftools
-------------------
Date : 2022-08-25
copyright : (L) 2022 by Thang Quach
email : quachdongthang@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
__author__ = 'Thang Quach'
__date__ = '2022-08-25'
__copyright__ = '(L) 2022 by Thang Quach'
from qgis.core import *
from qgis.gui import *
from qgis.utils import qgsfunction
from becagis.becagislibrary.latlong import (antipode as ANTIPODE)
from becagis.becagislibrary.attribute import (tcvn3_unicode as TCVN3_UNICODE,
unicode_tcvn3 as UNICODE_TCVN3,
vni_unicode as VNI_UNICODE,
unicode_vni as UNICODE_VNI,
capitalize as CAPITALIZE,
unaccent as UNACCENT,
swapcase as SWAPCASE)
from becagis.becagislibrary.imgs import Imgs
group_name = 'BecaGIS'
# https://qgis.org/pyqgis/3.2/core/Expression/QgsExpression.html
LOC = QgsApplication.locale()[:2]
def tr(*string):
# Translate to Vietnamese: arg[0] - English (translate), arg[1] - Vietnamese
if LOC == 'vi':
if len(string) == 2:
return string[1]
else:
return string[0]
else:
return string[0]
# @qgsfunction(args='auto', group=group_name,usesgeometry=True)
@qgsfunction(args='auto', group=group_name)
def antipode(lat,lon, feature, parent):
""" <style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Calculate antipode of a (lat, long) input.
<h4>Syntax</h4>
<li><span class = function>antipode</span>(<span class = parameters>lat</span>, <span class = parameters>long</span>)
or <span class = function>antipode</span>(<span class = parameters>$y</span>, <span class = parameters>$x</span>) in WGS84 CRS</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>antipode</span>(<span class = parameters>10.784229903855978</span>, <span class = parameters>106.70356815497277</span>) → returns a point geometry</li>
<li><span class = function>geom_to_wkt</span>(<span class = function>antipode</span>(<span class = parameters>10.784229903855978</span>, <span class = parameters>106.70356815497277</span>)) → 'Point (-73.29643185 -10.7842299)'</li>
</ul>
"""
# lat= feature.geometry().asPoint().x()
# lon = feature.geometry().asPoint().y()
antipode_lat,antipode_lon = ANTIPODE(lat,lon)
antipode_point = QgsPointXY(antipode_lon, antipode_lat)
return(QgsGeometry.fromPointXY(antipode_point))
@qgsfunction(args='auto', group=group_name)
def capitalize(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Convert text to Capitalized.
<h4>Syntax</h4>
<li><span class = function>capitalize</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>capitalize</span>(<span class = parameters>'quách đồng thắng''</span>)→ 'Quách đồng thắng'</li>
</ul>
"""
return(CAPITALIZE(string))
@qgsfunction(args='auto', group=group_name)
def swapcase(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
sWAP Case of input text
<h4>Syntax</h4>
<li><span class = function>swapcase</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>swapcase</span>(<span class = parameters>'Quách Đồng Thắng'</span>)→ 'qUÁCH đỒNG tHẮNG'</li>
</ul>
"""
return(SWAPCASE(string))
@qgsfunction(args='auto', group=group_name)
def unaccent(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Convert text to unaccented.
<h4>Syntax</h4>
<li><span class = function>unaccent</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>unaccent</span>(<span class = parameters>'Quách Đồng Thắng'</span>)→ 'Quach Dong Thang'</li>
</ul>
"""
return(UNACCENT(string))
@qgsfunction(args='auto', group=group_name)
def tcvn3_unicode(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Convert TCVN3 to Unicode.
<h4>Syntax</h4>
<li><span class = function>tcvn3_unicode</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>tcvn3_unicode</span>(<span class = parameters>'Qu¸ch §ång Th¾ng'</span>)→ 'Quách Đồng Thắng'</li>
</ul>
"""
return(TCVN3_UNICODE(string))
@qgsfunction(args='auto', group=group_name)
def unicode_tcvn3(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Convert Unicode to TCVN3.
<h4>Syntax</h4>
<li><span class = function>unicode_tcvn3</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>unicode_tcvn3</span>(<span class = parameters>'Quách Đồng Thắng'</span>)→ 'Qu¸ch §ång Th¾ng'</li>
</ul>
"""
return(UNICODE_TCVN3(string))
@qgsfunction(args='auto', group=group_name)
def unicode_vni(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Convert Unicode to VNI Windows.
<h4>Syntax</h4>
<li><span class = function>unicode_vni</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>unicode_vni</span>(<span class = parameters>'Quách Đồng Thắng'</span>)→ 'Quaùch Ñoàng Thaéng'</li>
</ul>
"""
return(UNICODE_VNI(string))
@qgsfunction(args='auto', group=group_name)
def vni_unicode(string, feature, parent):
"""<style type="text/css">
.function {
color: #05688f;
font-weight: bold;
}
.parameters {
color: red;
font-style:italic
}
</style>
Convert VNI Windows to Unicode.
<h4>Syntax</h4>
<li><span class = function>vni_unicode</span>(<span class = parameters>string</span>)</li>
<h4>Example usage</h4>
<ul>
<li><span class = function>vni_unicode</span>(<span class = parameters>''Quaùch Ñoàng Thaéng''</span>)→ 'Quách Đồng Thắng'</li>
</ul>
"""
return(VNI_UNICODE(string))