简体   繁体   中英

Geocoding using Geopy ArcGIS and Python

I am trying to geocode multipe address using Geopy and ArcGIS. I have set up my code to loop through the CSV and check for the address and name and provide a separate column for the lat and long coordinates.

This something wrong with my code when executed it does not provide the lat long coordinates and also does not properly loop through the CSV. How do I make it that the it will loop through the multiple address and geocode them giving a lat and long coordinates.

Below is my code:

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)

Name,Latitude Longitude haven't been defined in this scope in the lines

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

It should be latitude, longitude there. Name, I am guessing should be row['Name']. Also can you post a snippet(header and 1-2 lines) of you csv file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM