I had a spreadsheet of coordinates, along with their addresses. The addresses were either inaccurate or missing. Without access to an ArcGIS licence, and knowing the addresses were not available on our enterprise geocoding service, I sought to find a quicker (and open-source) way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geocoder | |
import pandas as pd | |
xls = r'C:\Some\Arb\Folder\coords.xls' | |
out_xls = r'C:\Some\Arb\Folder\geocoded.xls' | |
df = pd.read_excel(xls) | |
for index, row in df.iterrows(): | |
g = geocoder.google([row[3], row[2]], method='reverse') | |
df.set_value(index, 'Street Address', g.address) | |
df.to_excel(out_xls, 'Geocoded') |
I used the geocoder library to do this. I used it previously when I still had an ArcGIS Online account and a Bing key to check geocoding accuracy amongst the three providers.
Since I don’t have those luxuries anymore, I used pandas to read in the spreadsheet and reverse geocode the coordinates found in the the third and fourth columns. I then added a new column to the data frame to contain the returned address, and copied the data frame to a new spreadsheet.