/
1 arcGIS-left.py
47 lines (37 loc) · 1.4 KB
/
1 arcGIS-left.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# coding: utf-8
# In[2]:
import geocoder
add_list = list(open('address'))
print len(add_list)
geo_file = open('geo_file-left','w')
geo_file.write('LineID' + ' ' + 'OrignalAddress' + ' ' + 'NewAddress' + ' ' + 'Coordinates' + ' ' + 'City' + ' ' + 'State' + ' ' + 'Postal' + '\n')
# In[9]:
LeftIDList = list(open('Left LineID', 'r'))
for i in LeftIDList:
i = int(i.strip())
print i
arcResult = geocoder.arcgis(add_list[i].decode('utf8'))
print arcResult
coordinates = arcResult.latlng
address = arcResult.address
gooResult = geocoder.google(coordinates, method = 'reverse')
print gooResult
city = gooResult.city
postal = gooResult.postal
state = gooResult.state
if arcResult.status == 'OK' and gooResult.status == 'OK':
geo_file.write(str(i) + ' ' + add_list[i].strip('\n') + ' ' +
address + ' ' +
str(coordinates) + ' ' +
city + ' ' +
state + ' ' +
str(postal) + '\n')
if arcResult.status != 'OK' or gooResult.status != 'OK':
geo_file.write(str(i) + ' ' + add_list[i].strip('\n') + ' ' +
'NON' + ' ' +
'NON' + ' ' +
'NON' + ' ' +
'NON' + ' ' +
'NON' + '\n')
print 'address converting completed'
geo_file.close()