1 Star 0 Fork 0

cq383768026/Learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
changeShapeType.py 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
geospatialpython 提交于 2015-06-18 12:37 . Consolidated repositories
"""
Convert one shapefile type to another
"""
import shapefile
# Create a line and a multi-point
# and single point version of
# a polygon shapefile
## POLYLINE version
# The shapefile type we are converting to
newType = shapefile.POLYLINE
r = shapefile.Reader("Mississippi")
w = shapefile.Writer(newType)
w._shapes.extend(r.shapes())
# You must explicity set the shapeType of each record.
# Eventually the library will set them to the same
# as the file shape type automatically.
for s in w.shapes():
s.shapeType = newType
w.fields = list(r.fields)
w.records.extend(r.records())
w.save("Miss_Line")
## MULTIPOINT version
newType = shapefile.MULTIPOINT
w = shapefile.Writer(newType)
w._shapes.extend(r.shapes())
for s in w.shapes():
s.shapeType = newType
w.fields = list(r.fields)
w.records.extend(r.records())
w.save("Miss_MPoint")
## POINT version
newType = shapefile.POINT
w = shapefile.Writer(newType)
# For a single point shapefile
# from another type we
# "flatten" each shape
# so each point is a new record.
# This means we must also assign
# each point a record which means
# records are usually duplicated.
for s in r.shapeRecords():
for p in s.shape.points:
w.point(*p)
w.records.append(s.record)
w.fields = list(r.fields)
w.save("Miss_Point")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cq383768026/Learn.git
[email protected]:cq383768026/Learn.git
cq383768026
Learn
Learn
master

搜索帮助