forked from LEOXINGU/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
separar_multipartes.py
96 lines (92 loc) · 4.62 KB
/
separar_multipartes.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
"""
/***************************************************************************
3 CGEO
3th Brazilian Geoinformation Center
-------------------
begin : 2017-06-13
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. *
* *
***************************************************************************/
"""
# Separar feicoes multipartes de todas as camadas
##05. Separar Multipartes=name
##LF2) Revisao=group
from PyQt4.QtCore import *
from qgis.gui import QgsMessageBar
from qgis.utils import iface
from qgis.core import *
import processing
from processing.tools.vector import VectorWriter
import time
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
if layer.type()==0 and layer.geometryType() == QGis.Point:
DP = layer.dataProvider()
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPoint()
if len(coord)>1:
# Atualizar a geometria da feicao com a geometria com apenas uma parte
new_geom = QgsGeometry.fromMultiPoint([coord[0]])
newGeomMap = {feat.id() : new_geom}
ok = DP.changeGeometryValues(newGeomMap)
# Criar novas feicoes com as outras partes
att = feat.attributes()
new_att = [None] + att[1:]
new_feat = QgsFeature()
for i in range(1, len(coord)):
new_geom = QgsGeometry.fromMultiPoint([coord[i]])
new_feat.setGeometry(new_geom)
new_feat.setAttributes(new_att)
ok = DP.addFeatures([new_feat])
if layer.type()==0 and layer.geometryType() == QGis.Line:
DP = layer.dataProvider()
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPolyline()
if len(coord)>1:
# Atualizar a geometria da feicao com a geometria com apenas uma parte
new_geom = QgsGeometry.fromMultiPolyline([coord[0]])
newGeomMap = {feat.id() : new_geom}
ok = DP.changeGeometryValues(newGeomMap)
# Criar novas feicoes com as outras partes
att = feat.attributes()
new_att = [None] + att[1:]
new_feat = QgsFeature()
for i in range(1, len(coord)):
new_geom = QgsGeometry.fromMultiPolyline([coord[i]])
new_feat.setGeometry(new_geom)
new_feat.setAttributes(new_att)
ok = DP.addFeatures([new_feat])
if layer.type()==0 and layer.geometryType() == QGis.Polygon:
DP = layer.dataProvider()
for feat in layer.getFeatures():
geom = feat.geometry()
if geom:
coord = geom.asMultiPolygon()
if len(coord)>1:
# Atualizar a geometria da feicao com a geometria com apenas uma parte
new_geom = QgsGeometry.fromMultiPolygon([coord[0]])
newGeomMap = {feat.id() : new_geom}
ok = DP.changeGeometryValues(newGeomMap)
# Criar novas feicoes com as outras partes
att = feat.attributes()
new_att = [None] + att[1:]
new_feat = QgsFeature()
for i in range(1, len(coord)):
new_geom = QgsGeometry.fromMultiPolygon([coord[i]])
new_feat.setGeometry(new_geom)
new_feat.setAttributes(new_att)
ok = DP.addFeatures([new_feat])
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)