代码拉取完成,页面将自动刷新
import shapefile
r = shapefile.Reader("shapefiles/NYC_MUSEUMS/NYC_MUSEUMS_UTM")
w = shapefile.Writer("shapefiles/NYC_MUSEUMS/NYC_MUSEUMS_02")
geo = shapefile.Reader("shapefiles/NYC_MUSEUMS_GEO")
# 1.添加字段
w.fields = list(r.fields[1:])
w.field("GEO_LAT", "F", 5, 8)
w.field("GEO_LON", "F", 5, 8)
# [('DeletionFlag', 'C', 1, 0),
# ['NAME', 'C', 254, 0],
# ['TEL', 'C', 254, 0],
# ['URL', 'C', 254, 0],
# ['ADRESS1', 'C', 254, 0],
# ['ADDRESS2', 'C', 254, 0],
# ['CITY', 'C', 254, 0],
# ['ZIP', 'N', 19, 8]]
# 2.复制记录
for i in range(geo.numRecords):
lon, lat = geo.shape(i).points[0]
shapeRecord = r.record(i)
# 方法 1:
shapeRecord.extend([lat, lon])
w.record(*shapeRecord)
# 方法 2:
# w.record(NAME=shapeRecord[0], TEL=shapeRecord[1], URL=shapeRecord[2],
# ADRESS1=shapeRecord[3], ADDRESS2=shapeRecord[4], CITY=shapeRecord[5],
# ZIP=shapeRecord[6], GEO_LAT=lat, GEO_LON=lon)
# 3.复制图形
for item in r.iterShapes():
x, y = item.points[0]
w.point(x, y)
print(r.record(0))
w.close()
r.close()
# 验证添加的字段
r = shapefile.Reader("shapefiles/NYC_MUSEUMS_02")
print(r)
print(r.record(0))
r.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。