FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Learn/Split_vector_layer_by_attribute.py at master · GeospatialPython/Learn · GitHub
GeospatialPython
/
Learn
Public
Notifications
You must be signed in to change notification settings
Fork
51
Star
85
Code
Issues
0
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Learn
/
Split_vector_layer_by_attribute.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (41 loc) · 1.2 KB
Breadcrumbs
Learn
/
Split_vector_layer_by_attribute.py
Copy path
File metadata and controls
47 lines (41 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
##Vector=group
##input=vector
##class_field=field input
##output=output vector
##nomodeler
from
qgis
.
core
import
*
from
PyQt4
.
QtCore
import
*
# import VectorWriter
try
:
# Qgis from 2.0 to 2.4
from
processing
.
core
.
VectorWriter
import
VectorWriter
except
:
# Qgis from 2.6
from
processing
.
tools
.
vector
import
VectorWriter
layer
=
processing
.
getObject
(
input
)
provider
=
layer
.
dataProvider
()
fields
=
provider
.
fields
()
writers
=
{}
class_field_index
=
layer
.
fieldNameIndex
(
class_field
)
inFeat
=
QgsFeature
()
outFeat
=
QgsFeature
()
inGeom
=
QgsGeometry
()
nElement
=
0
writers
=
{}
feats
=
processing
.
features
(
layer
)
nFeat
=
len
(
feats
)
for
inFeat
in
feats
:
progress
.
setPercentage
(
int
(
100
*
nElement
/
nFeat
))
nElement
+=
1
atMap
=
inFeat
.
attributes
()
clazz
=
atMap
[
class_field_index
]
if
clazz
not
in
writers
:
outputFile
=
output
+
'_'
+
str
(
len
(
writers
))
+
'.shp'
writers
[
clazz
]
=
VectorWriter
(
outputFile
,
None
,
fields
,
provider
.
geometryType
(),
layer
.
crs
())
inGeom
=
inFeat
.
geometry
()
outFeat
.
setGeometry
(
inGeom
)
outFeat
.
setAttributes
(
atMap
)
writers
[
clazz
].
addFeature
(
outFeat
)
for
writer
in
writers
.
values
():
del
writer
Back
|
FazBrowse Home
|
New Git URL