0

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)
4

1 に答える 1

0

名前、緯度、経度は、行のこのスコープで定義されていません

output_row['Name'] = Name
output_row['Address'] = Address
output_row['Latitude'] = Latitude
output_row['Longitude'] =Longitude

そこには緯度、経度があるはずです。名前は、row['Name'] であるべきだと思います。また、csv ファイルのスニペット (ヘッダーと 1 ~ 2 行) を投稿できますか?

于 2015-07-07T21:54:16.010 に答える