mercredi 30 décembre 2009

Geocoding Adresses

# 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

Talend Certified

Certification is awarded to individuals who successfully complete a comprehensive online test covering all aspects of the use of Talend Open Studio in real-life situations. Clients trusting a systems integrator to implement a solution want to be reassured that the consultants are indeed experts in the technology. Talend certification gives them this level of assurance.

Qui êtes-vous ?

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
Promo6 Mastére Géomatique

Talend Blog

Liste de partage de geomatiLux

Libellés

Media préferé

  • www.talend.com

Le Groupe CLLFST

Le Groupe CLLFST
SFD 2007

CLLFST & INFO+

CLLFST & INFO+
SFD 2007