代码拉取完成,页面将自动刷新
"""
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")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。