【发布时间】:2015-07-07 18:27:35
【问题描述】:
我正在尝试使用 Geopy 和 ArcGIS 对多重地址进行地理编码。我已将代码设置为循环遍历 CSV 并检查地址和名称,并为纬度和经度坐标提供单独的列。
我的代码在执行时有问题,它不提供经纬度坐标,也没有正确循环通过 CSV。我如何让它循环遍历多个地址并对它们进行地理编码,给出一个经纬度坐标。
下面是我的代码:
import csv
from geopy.geocoders import ArcGIS
geolocator = ArcGIS() #here some parameters are needed
with open('C:/Users/v-albaut/Desktop/Test_Geo.csv', 'rb') as csvinput:
with open('output.csv', 'w') as csvoutput:
output_fieldnames = ['Name','Address', 'Latitude', 'Longitude']
writer = csv.DictWriter(csvoutput, delimiter=',', fieldnames=output_fieldnames)
reader = csv.DictReader(csvinput)
for row in reader:
##here you have to replace the dict item by your csv column names
query = ','.join(str(x) for x in (row['Name'], row['Address']))
Address, (latitude, longitude) = geolocator.geocode(query)
###here is the writing section
output_row = {}
output_row['Name'] = Name
output_row['Address'] = Address
output_row['Latitude'] = Latitude
output_row['Longitude'] =Longitude
writer.writerow(output_row)
【问题讨论】: