# Pieces of script to geocode addresses file with geopy: the reference web services is geonames (baroudi.malek@gmail.com)
#Need geopy installation
#Need python-beautifulsoup installation
#The output file is csv
import urllib2
import os
import csv
from geopy import geocoders
host="proxy......"
port="8080"
proxy_user = '...'
proxy_password_orig='...'
proxy_password = urllib2.quote(proxy_password_orig, "")
proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' + host+ ':' + port
proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)
f = urllib2.urlopen('http://www.python.org/')
print f.headers
reader = csv.reader(open('adresses.csv', "rb"), dialect="excel",quotechar="'", delimiter=";")
# Get addresses and names from csv file
# 1st column: address / 2nd column: name
myResult=[]
gn = geocoders.GeoNames()
myCmpt=0
for myRecord in reader:
myName=myRecord[1]
addr=myRecord[0]
myName, (lat, lng) = gn.geocode(addr)
dataToSave="%s: %.5f, %.5f" % (myName, lat, lng)
myResult.append(dataToSave)
print "%s: %.5f, %.5f" % (myName, lat, lng)
writer = csv.writer(open("geoResult.csv", "wb"),quotechar=" ", delimiter="\n")
writer.writerows([myResult])
#The result is like here:
[1723] lat : 48.477307000000003, long : 7.2176159999999996, - RUE DE L'EGLISE
[1724] lat : 48.562179999999998, long : 7.6772330000000002, - RUE DES FLANDRES
mercredi 30 décembre 2009
Inscription à :
Articles (Atom)
Talend Certified
Qui êtes-vous ?
- GéomatiLux
- Paris, Île de France, France
- I'm a textbook computer geek, who has a keen interest in programming, GIS and mapping.
Linux News
Wikipedia
Mission Topographique
![Mission Topographique](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCgJ05z0DvVHHq9-8ohNTIcjHWimDIZOxOMz-lMW6MDJwhiTuBpeWXxPo-H9QVPFzAAT73oyY8V_7fFYO1-ecIfL66yzwA4SPMGI7nrJMX5OEKae8xoTf0I-s1voNScNpOGELoUXfppQ/s264/topo2.jpg)
Promo6 Mastére Géomatique
lien préfère
Talend Blog
Archives du blog
Liste de partage de geomatiLux
Libellés
- Openscales (1)
Media préferé
- www.talend.com
Le Groupe CLLFST
![Le Groupe CLLFST](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieNctqqLaAsxLqAGex2W_M3W4s7vXrS7J-h_2E9f40Ub_vsD6l7QUnNmYap1ZHS6eWnTcwl3btKcJ3EBpyVNgJcIzCivS3e6KnT_snz5Deai9wfDwYnyf4tThc5E_vdfgZ2m46Z1g1dg/s264/hpim0217.jpg)
SFD 2007
CLLFST & INFO+
![CLLFST & INFO+](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbhQTVsli-RyyBpgI-m3TsHFDnDKkSgwLWOqQyjPRKiwuGlHJU-F-XaYqczb8bn94WmMpgYSfsFrsmWO9vbf1ZCvEAKBCDWocWFaZUprQZqzC_Y8ZxnGBRCp-yy1RUief02TmkHGbrQ/s264/hpim0235.jpg)
SFD 2007