-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconsist_linhas_CT.py
More file actions
117 lines (108 loc) · 4.32 KB
/
consist_linhas_CT.py
File metadata and controls
117 lines (108 loc) · 4.32 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
"""
/***************************************************************************
LEOXINGU
-------------------
begin : 2018-02-20
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. *
* *
***************************************************************************/
"""
# Consistencia Topologica de CT
##Verificar Linhas de CT=name
##LF09) Validacao=group
##Camada_de_linhas=vector
##Moldura=vector
##Tolerancia=number 0.5
##Insconsistencias=output vector
from PyQt4.QtCore import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface
from qgis.core import *
import time
import processing
# Abrir camada de linhas
linhas = processing.getObject(Camada_de_linhas)
lin_list = []
for feat in linhas.getFeatures():
geom = feat.geometry()
if geom:
lin = geom.asPolyline()
if not (lin):
lin = geom.asMultiPolyline()[0]
lin_list +=[lin]
# Abrir moldura
moldura = processing.getObject(Moldura)
SRC = moldura.crs()
feat = moldura.getFeatures().next()
pol = feat.geometry()
coord = pol.asMultiPolygon()
moldura_linha = QgsGeometry.fromMultiPolyline(coord[0])
if SRC.geographicFlag():
moldura_buffer = moldura_linha.buffer(Tolerancia/110000.0,5)
else:
moldura_buffer = moldura_linha.buffer(Tolerancia,5)
# Criar camada de inconsistencias
fields = QgsFields()
fields.append(QgsField('problema', QVariant.String))
writer = QgsVectorFileWriter(Insconsistencias, 'utf-8', fields, QGis.WKBPoint, SRC, 'ESRI Shapefile')
'''
# Checar se linhas se cruzam
progress.setInfo('<b>Verificando se as linhas se cruzam...</b><br/>')
tam = len(lin_list)
feature = QgsFeature()
for i in range(0,tam-1):
for j in range(i+1,tam):
linA = QgsGeometry.fromPolyline(lin_list[i])
linB = QgsGeometry.fromPolyline(lin_list[j])
if linA.crosses(linB):
Intersecao = linA.intersection(linB)
feature.setAttributes(['Instersecao entre linhas'])
if Intersecao.isMultipart():
for ponto in Intersecao.asMultiPoint():
feature.setGeometry(QgsGeometry.fromPoint(ponto))
writer.addFeature(feature)
else:
feature.setGeometry(Intersecao)
writer.addFeature(feature)
'''
# Checar se uma feicao nao toca outra feicao ou moldura
progress.setInfo('<b>Verificando se as linhas toca outra feicao ou a moldura...</b><br/>')
tam = len(lin_list)
feature = QgsFeature()
for i in range(tam):
tocaIni = False
tocaFim = False
pnt_Ini_A = QgsGeometry.fromPoint(lin_list[i][0])
pnt_Fim_A = QgsGeometry.fromPoint(lin_list[i][-1])
for j in range(tam):
if i != j:
lin_B = QgsGeometry.fromPolyline(lin_list[j])
# Ponto inicial
if pnt_Ini_A.intersects(lin_B) or pnt_Ini_A.intersects(moldura_buffer):
tocaIni = True
# Ponto final
if pnt_Fim_A.intersects(lin_B) or pnt_Fim_A.intersects(moldura_buffer):
tocaFim = True
# Gerar Ponto de Inconsistencia
if not(tocaIni and tocaFim):
if not (pnt_Ini_A.intersects(pnt_Fim_A)):
if not tocaIni:
feature.setAttributes(['Ponta Solta'])
feature.setGeometry(pnt_Ini_A)
writer.addFeature(feature)
if not tocaFim:
feature.setAttributes(['Ponta Solta'])
feature.setGeometry(pnt_Fim_A)
writer.addFeature(feature)
progress.setPercentage(int((i+1)/float(tam)*100))
del writer
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)