-
Notifications
You must be signed in to change notification settings - Fork 2
/
extrair_anel_externo.py
72 lines (64 loc) · 2.53 KB
/
extrair_anel_externo.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
"""
/***************************************************************************
3 CGEO
3th Brazilian Geoinformation Center
-------------------
begin : 2017-05-22
copyright : (C) 2017 by Leandro Franca - Cartographic Engineer @ Brazilian Army
email : franca.leandro@eb.mil.br
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
# Extrair anel externo de poligonos
##Extrair anel exterior=name
##LF04) Vetor=group
##Camada_de_poligonos=vector
##Saida=output vector
from PyQt4.QtCore import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface
from qgis.core import *
import time
import processing
poligono = Camada_de_poligonos
saida = Saida
# Camada de Poligono
poligonos = processing.getObject(poligono)
# Camada para o anel externo do poligono
fields = poligonos.pendingFields()
CRS = poligonos.crs()
encoding = 'utf-8'
formato = 'ESRI Shapefile'
writer = QgsVectorFileWriter(saida, encoding, fields, QGis.WKBLineString, CRS, formato)
del writer
anel = QgsVectorLayer(saida, 'poligonos', 'ogr')
DataProvider = anel.dataProvider()
# Extrair aneis externos
feat = QgsFeature(fields)
for feature in poligonos.getFeatures():
geom = feature.geometry()
att = feature.attributes()
coord = geom.asPolygon()
if coord == []:
coord = geom.asMultiPolygon()
for item in coord:
new_geom = QgsGeometry.fromPolyline(item[0])
feat.setGeometry(new_geom)
feat.setAttributes(att)
DataProvider.addFeatures([feat])
else:
new_geom = QgsGeometry.fromPolyline(coord[0])
feat.setGeometry(new_geom)
feat.setAttributes(att)
DataProvider.addFeatures([feat])
del anel, DataProvider
progress.setInfo('<b>Operacao concluida!</b><br/><br/>')
progress.setInfo('<b>Leandro Franca- Eng Cart</b><br/>')
time.sleep(3)
iface.messageBar().pushMessage(u'Situacao', "Operacao Concluida com Sucesso!", level=QgsMessageBar.INFO, duration=5)