我有两个 shapefile:湖泊和城市。我需要找到离每个湖最近的城市,并将城市名称添加到湖 shapefile 中。我有:
for lake in lake_cursor:
lake_geom = lake.Shape
city_dist_list = [] #create a city dis list = a list of dist from one lake to each city
for cityID in range(0, city_length-1):
#obtaining x and y for both cities and lakes
cityX = citylist_X_Coor[cityID]
cityY = citylist_Y_Coor[cityID]
lakeX = lake_geom.centroid.X
lakeY = lake_geom.centroid.Y
#calculate distance
dist = math.sqrt((cityX-lakeX)**2 + (cityY-lakeY)**2)
#add the dist to the city dist list
city_dist_list.append(dist)
closest = min(city_dist_list)
closestID = city_dist_list.index(closest)
lake.City_Name = citylist_City_Name[closestID]
lake.X_Coor = citylist_X_Coor[closestID]
lake.Y_Coor = citylist_Y_Coor[closestID]
print closest
但我不断收到从 开始的错误消息lake.City_Name
。python shell没有告诉我出了什么问题-有什么想法吗?以及如何解决它?谢谢!
回溯显示:
Traceback (most recent call last):
File "C:\Users\xxx\xxx\xxx.py", line 71, in <module>
lake.City_Name = citylist_City_Name[closestID]
File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__
return setattr(self._arc_object, attr, ao)
RuntimeError: ERROR 999999: Error executing function.