我正在尝试对包含位置名称和解析出的地址的 CSV 文件进行地理编码,其中包括地址编号、街道名称、城市、邮政编码、国家/地区。我想通过 Geopy 使用 GEOPY 和 ArcGIS Geocodes。我想创建一个循环遍历 5000 多个条目的 csv 的代码,并在我的 CSV 的单独列中给出纬度和经度。我想通过 Geopy 使用 ArcGIS 地理编码服务。谁能给我一个代码来开始?谢谢!
这是我的脚本:
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)