Your error was probably similar to this one
Traceback (most recent call last):
File "D:/test.py", line 24, in <module>
results = reverse_geocode(pt)
File "C:\...\_functions.py", line 1054, in reverse_geocode
geocoder = arcgis.env.active_gis._tools.geocoders[0]
AttributeError: 'NoneType' object has no attribute '_tools'
It is most likely because of the credentials that have to be specified gis = GIS("http://www.arcgis.com", "username", "password")
.
Otherwise, I would doubt that ArcGIS libraries could be deployed without a license.
So, the final code will look as follows (including comments)
import csv
from arcgis.gis import GIS
from arcgis.geometry import Geometry
from arcgis.geocoding import reverse_geocode
gis = GIS("http://www.arcgis.com", "***", "***")
houses = []
houses.append((143.5689855, -38.328956999999996))
houses.append((143.5692555, -38.328993000000000))
lat_diff = houses[1][0] - houses[0][0]
lon_diff = houses[1][1] - houses[0][1]
i = 1
while i <= 5:
houses.append((houses[i][0] + lat_diff, houses[i][1] + lon_diff))
i = i + 1
result = []
for x, y in houses:
pt = Geometry({
"x": float(x),
"y": float(y),
"spatialReference": {
"wkid": 4326
}
})
try:
result.append(reverse_geocode(pt))
except:
pass
i = 0
result_to_csv = []
for item in result:
i += 1
result_item = {
'id': i,
'address': item['address']['LongLabel'],
'lat': round(item['location']['x'],6),
'lon': round(item['location']['y'],6)
}
result_to_csv.append(result_item)
keys = result_to_csv[0].keys()
with open('output.csv', 'w', encoding='utf8', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys, delimiter=';', quoting=csv.QUOTE_NONE, lineterminator='\r')
dict_writer.writeheader()
dict_writer.writerows(result_to_csv)
The output CSV-file
when 1.000
of houses have to be geocoded then adjust this part while i < 999
.