1 Star 0 Fork 1

weishujie/Learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Split_vector_layer_by_attribute.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
geospatialpython 提交于 2015-06-16 21:20 . Migrated GoogleCode Site.
##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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wei_shujie/Learn.git
[email protected]:wei_shujie/Learn.git
wei_shujie
Learn
Learn
master

搜索帮助