-
Notifications
You must be signed in to change notification settings - Fork 2
/
auto_intersecao.py
139 lines (132 loc) · 6.14 KB
/
auto_intersecao.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
"""
/***************************************************************************
LEOXINGU
-------------------
begin : 2017-09-21
copyright : (C) 2017 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. *
* *
***************************************************************************/
"""
# Verificar Auto-Intersecao
##LF02) Revisao=group
##08. Verificar Auto Intersecoes=name
##Shapefile_de_Loops=output vector
from PyQt4.QtCore import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface
from qgis.core import *
import processing
import time
# Pegando o SRC da camada trecho de drenagem
layerList = QgsMapLayerRegistry.instance().mapLayersByName('aux_moldura_a')
if layerList:
layer = layerList[0]
SRC = layer.crs()
# Criar arquivo de pontos para armazenar as informacoes
fields = QgsFields()
fields.append(QgsField('classe', QVariant.String))
fields.append(QgsField('id', QVariant.Int))
writer = QgsVectorFileWriter(Shapefile_de_Loops, 'utf-8', fields, QGis.WKBPoint, SRC, 'ESRI Shapefile')
# Camada para nao verificar
nao_verif = ['rel_curva_nivel_l',
'hid_trecho_drenagem_l']
# Varrer camadas
cont = 0
lista_pnts = []
feature = QgsFeature()
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
nome = layer.name()
# Linhas
if layer.geometryType() == QGis.Line and not(nome in nao_verif) :
progress.setInfo('Verificando classe: %s<br/>' %nome)
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPolyline()[0]
if coord:
tam = len(coord)
if tam > 3:
for i in range(0,tam-3):
segA = [coord[i], coord[i+1]]
geomA = QgsGeometry.fromPolyline(segA)
for j in range(i+2,tam-1):
segB = [coord[j], coord[j+1]]
geomB = QgsGeometry.fromPolyline(segB)
if geomA.crosses(geomB):
point = geomA.intersection(geomB)
if not(point in lista_pnts or point.asPoint() == coord[0]):
lista_pnts += [point]
feature.setAttributes([nome, feat.id()])
feature.setGeometry(point)
writer.addFeature(feature)
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPolyline()[0]
if coord:
tam = len(coord)
if tam > 5:
for i in range(0,tam-3):
PntA = coord[i]
for j in range(i+3,tam):
PntB = coord[j]
if PntA == PntB:
point = QgsGeometry.fromPoint(PntA)
if not(point in lista_pnts or point.asPoint() == coord[0]):
lista_pnts += [point]
feature.setAttributes([nome, feat.id()])
feature.setGeometry(point)
writer.addFeature(feature)
# Poligonos
if layer.geometryType() == QGis.Polygon and not(nome in nao_verif) :
progress.setInfo('Verificando classe: %s<br/>' %nome)
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPolygon()[0][0]
if coord:
tam = len(coord)
if tam > 3:
for i in range(0,tam-3):
segA = [coord[i], coord[i+1]]
geomA = QgsGeometry.fromPolyline(segA)
for j in range(i+2,tam-1):
segB = [coord[j], coord[j+1]]
geomB = QgsGeometry.fromPolyline(segB)
if geomA.crosses(geomB):
point = geomA.intersection(geomB)
if not(point in lista_pnts):
lista_pnts += [point]
feature.setAttributes([nome, feat.id()])
feature.setGeometry(point)
writer.addFeature(feature)
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPolygon()[0][0]
if coord:
tam = len(coord)
if tam > 5:
for i in range(0,tam-3):
PntA = coord[i]
for j in range(i+3,tam-1):
PntB = coord[j]
if PntA == PntB:
point = QgsGeometry.fromPoint(PntA)
if not(point in lista_pnts):
lista_pnts += [point]
feature.setAttributes([nome, feat.id()])
feature.setGeometry(point)
writer.addFeature(feature)
del writer
progress.setInfo('<b>Operacao concluida!</b><br/><br/>')
progress.setInfo('<b>Leandro França - Eng Cart</b><br/>')
time.sleep(3)
iface.messageBar().pushMessage(u'Situacao', "Operacao Concluida com Sucesso!", level=QgsMessageBar.INFO, duration=5)