-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconv_meridiana.py
More file actions
195 lines (180 loc) · 6.81 KB
/
conv_meridiana.py
File metadata and controls
195 lines (180 loc) · 6.81 KB
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
"""
/***************************************************************************
LEOXINGU
-------------------
begin : 2018-03-19
copyright : (C) 2018 by Leandro Franca - Cartographic Engineer
email : geoleandro.franca@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. *
* *
***************************************************************************/
"""
# Convergencia Meridiana
##3. Convergencia Meridiana=name
##LF10) Cartografia=group
##Moldura=vector
##Resultado=output html
from PyQt4.QtCore import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface
from qgis.core import *
import time
import processing
import math
moldura = processing.getObject(Moldura)
SRC = moldura.crs()
# Pegar centroide da moldura
features = moldura.getFeatures()
feat = features.next()
geom = feat.geometry()
centroide = geom.centroid().asPoint()
# Verificar os SRC da moldura
if not SRC.geographicFlag():
# Transformar Coordenadas Projetadas do sistema UTM para geograficas
crsDest = QgsCoordinateReferenceSystem()
crsDest.createFromSrsId(4674)
coordinateTransformer = QgsCoordinateTransform(SRC, crsDest)
centroide = coordinateTransformer.transform(centroide)
# Pegar coordenadas do Centroide
lon = centroide.x()
lat = centroide.y()
# Calculo do Fuso
fuso = round((183+lon)/6.0)
# Calculo do Meridiano Central
MC = 6*fuso-183
# Fator de distorcao inicial
kappaZero = 0.9996
# Pegar Semi-eixo Maior e Menor do Datum da Moldura
distanceArea = QgsDistanceArea()
distanceArea.setEllipsoid(SRC.ellipsoidAcronym())
a = distanceArea.ellipsoidSemiMajor()
b = distanceArea.ellipsoidSemiMinor()
# Calcular fator de escala para sistema de projecao UTM
def FatorK(lon, lat):
b = math.cos(math.radians(lat))*math.sin(math.radians(lon - MC))
k = kappaZero/math.sqrt(1 - b*b)
return k
# Calcular Convergencia Meridiana para sistema de projecao UTM
def ConvMer(lon, lat, a, b):
delta_lon = abs( MC - lon )
p = 0.0001*( delta_lon*3600 )
xii = math.sin(math.radians(lat))*math.pow(10, 4)
e2 = math.sqrt(a*a - b*b)/b
c5 = math.pow(math.sin(math.radians(1/3600)), 4)*math.sin(math.radians(lat))*math.pow(math.cos(math.radians(lat)), 4)*(2 - math.pow(math.tan(math.radians(lat)), 2))*math.pow(10, 20)/15
xiii = math.pow(math.sin(math.radians(1/3600)), 2)*math.sin(math.radians(lat))*math.pow(math.cos(math.radians(lat)), 2)*(1 + 3*e2*e2*math.pow(math.cos(math.radians(lat)), 2) + 2*math.pow(e2, 4)*math.pow(math.cos(math.radians(lat)), 4))*math.pow(10, 12)/3
cSeconds = xii*p + xiii*math.pow(p, 3) + c5*math.pow(p, 5)
c = cSeconds/3600
return c
def dd2dms(dd):
is_positive = dd >= 0
dd = abs(dd)
minutes,seconds = math.divmod(dd*3600,60)
degrees,minutes = math.divmod(minutes,60)
degrees = str(int(degrees)) if is_positive else '-' + str(int(degrees))
minutes = int(minutes)
return degrees + u"\u00b0" + str(minutes).zfill(2) + "'" + "%0.2f"%(seconds) + "''"
def dd2dmsHTML(degs):
neg = degs < 0
degs = (-1) ** neg * degs
degs, d_int = math.modf(degs)
mins, m_int = math.modf(60 * degs)
secs = 60 * mins
if neg:
return u'-%d°%02d\'%02d"' %(int(d_int), int(m_int), int(secs))
else:
return u'+%d°%02d\'%02d"' %(int(d_int), int(m_int), int(secs))
# Escrever Arquivo
if Resultado[-5:] != '.html':
Resultado += '.html'
texto = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body style="background-color: rgb(229, 233, 166);">
<div style="text-align: center;"><big><big><big><span
style="font-weight: bold;">RESULTADOS</span></big></big></big><br>
<br>
<span style="text-decoration: underline;">DADOS DO
CENTRÓIDE DA MOLDURA</span><br>
<div style="text-align: center;"><br>
</div>
<table
style="width: 508px; text-align: left; margin-left: auto; margin-right: auto; height: 137px;"
border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 253px; text-align: center; height: 43px;">LONGITUDE</td>
<td style="width: 237px; text-align: center; height: 43px;">%s</td>
</tr>
<tr>
<td style="width: 253px; text-align: center; height: 43px;">LATITUDE</td>
<td style="width: 237px; text-align: center; height: 43px;">%s</td>
</tr>
<tr>
<td style="width: 253px; text-align: center; height: 43px;">SRID</td>
<td style="width: 237px; text-align: center; height: 43px;">%s</td>
</tr>
</tbody>
</table>
<div style="text-align: center;"><br>
</div>
<br>
<span style="text-decoration: underline;">CONVERGÊNCIA
MERIDIANA</span><br>
</div>
<div style="text-align: center;"><br>
</div>
<table
style="width: 508px; text-align: left; margin-left: auto; margin-right: auto; height: 89px;"
border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 253px; text-align: center; height: 43px;">GRAUS
DECIMAIS</td>
<td style="width: 237px; text-align: center; height: 43px;">%s</td>
</tr>
<tr>
<td style="width: 253px; text-align: center; height: 43px;">GRAUS,
MINUTOS E SEGUNDOS</td>
<td style="width: 237px; text-align: center; height: 43px;">%s</td>
</tr>
</tbody>
</table>
<span style="text-decoration: underline;"><br>
</span>
<div style="text-align: center;"><span
style="text-decoration: underline;"><br>
FATOR DE DISTORÇÃO DE ESCALA (KAPPA)</span><br>
</div>
<div style="text-align: center;"><br>
</div>
<table
style="width: 508px; text-align: left; margin-left: auto; margin-right: auto; height: 47px;"
border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 253px; text-align: center; height: 43px;">KAPPA</td>
<td style="width: 237px; text-align: center; height: 43px;">%s</td>
</tr>
</tbody>
</table>
<div style="text-align: center;"><br>
</div>
<br>
</body>
</html>
''' %(dd2dmsHTML(lon), dd2dmsHTML(lat), SRC.authid().split(':')[-1], str(ConvMer(lon, lat, a, b)), dd2dmsHTML(ConvMer(lon, lat, a, b)), str(FatorK(lon, lat)))
arquivo = open(Resultado, 'w')
arquivo.write(texto)
arquivo.close()
progress.setInfo('<br/><b>Leandro França - Eng Cart</b><br/>')
time.sleep(5)
iface.messageBar().pushMessage(u'Situacao', "Operacao Concluida com Sucesso!", level=QgsMessageBar.INFO, duration=5)