我正在尝试在python中生成Arizona的地图,打算使用方法setworldcoordinates()而不是变换坐标。我正在编写一个代码来确定边界框但是我想出来了
ValueError: too many values to unpack
在包含for x,y in state[POINTS]:
我已将整个代码粘贴到底部的for循环中,导致错误。作为参考,导入的csv文件包含2列中的17行数据。我是编程的新手,我不确定我正在制作什么错误或如何解决它。
#Importing modules
import csv
import turtle as t
# Retrieve AZ map coordinates from a csv file
az_coords = open('AZ_points_simple.csv', "r") # open file
csvReader = csv.reader(az_coords) # create reader object
header = csvReader.next() # gives back a list of each item in header
latIndex = header.index("Y") # access column headers needed from file
lonIndex = header.index("X")
# Make empty list for coordinates
coordList = []
# loop through the lines in the file and get each coordinate
for row in csvReader:
lat = row[latIndex] # Y coordinate
lon = row[lonIndex] # X coordinate
coordList.append([lat,lon])
# DATA MODEL
# All cities will have a name, 1+ points, and population count
NAME = 0
POINTS= 1
POP = 2
# Create state layer
state = ["ARIZONA", [coordList], 7016270]
# Cities layer list
# city = [name, [points], population]
cities = []
# add Phoenix
cities.append(["PHOENIX", [-112.09, 33.57], 1615017])
# add Tucson
cities.append(["TUCSON", [-110.87, 32.14], 530706])
# add Flagstaff
cities.append(["FLAGSTAFF", [-111.62, 35.19], 71459])
# MAP SIZING
map_width = 400
map_height = 300
# State bounding box
# Use min/max functions to get bounding box
minx = 180
maxx = -180
miny = 90
maxy = -90
for x,y in state[POINTS]:
if x < minx:
minx = x
elif x > maxx:
maxx = x
if y < miny:
miny = y
elif y > maxy:
maxy = y`
答案 0 :(得分:1)
变化:
state = ["ARIZONA", [coordList], 7016270]
为:
state = ["ARIZONA", coordList, 7016270]
coordList
已经是x, y
对的列表,请保持原样。