Skip to content

Instantly share code, notes, and snippets.

@squarednob
Last active Dec 30, 2015
Embed
What would you like to do?
座標情報取得
#1Get coorinate using pygeocoder and googlemap API throuth place data in Japaneese.
#pygeopicker.py
# -*- coding: utf-8 -*-
from pygeocoder import Geocoder
import unicodecsv
def pick(query):
print "start"
geocom = []
companies = []
#open csv
f = open(query,"rb")
r = unicodecsv.reader(f, delimiter=",", encoding='utf-8')
#take into list
for i in r:
companies.append(i)
print len(companies)
#geocoding - code/company/location/coorinate
for i,d in enumerate(companies):
geocom.append([])
geocom[i].append(d[0])
geocom[i].append(d[1])
geocom[i].append(d[2])
if i == 0:
geocom[i].append("coordinate")
else:
try:
results = Geocoder.geocode(d[2])
geocom[i].append(results[0].coordinates)
except :
print " error occured"
geocom[i].append("N/A")
pass
print unicode(geocom[i][0]), unicode(geocom[i][1]), unicode(geocom[i][2]), unicode(geocom[i][3])
#output as utf-8/csv
f = open("testcompany20result.csv", "wb")
w = unicodecsv.writer(f,encoding='utf-8')
for i in geocom:
w.writerow(i)
print "end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment