代码拉取完成,页面将自动刷新
import csv
import shapefile
# Create a polygon shapefile writer
w = shapefile.Writer(shapefile.POLYGON)
# Add our fields
w.field("NAME", "C", "40")
w.field("AREA", "C", "40")
# Open the csv file and set up a reader
with open("sample.csv") as p:
reader = csv.DictReader(p)
for row in reader:
# Add records for each polygon for name and area
w.record(row["Name"], row["Area"])
# parse the coordinate string
wkt = row["geometry"][9:-2]
# break the coordinate string in to x,y values
coords = wkt.split(",")
# set up a list to contain the coordinates
part = []
# convert the x,y values to floats
for c in coords:
x,y = c.split(" ")
part.append([float(x),float(y)])
# create a polygon record with the list of coordinates.
w.poly(parts=[part])
# save the shapefile!
w.save("polys.shp")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。