drewfustin / isocronut

For a given geospatial location, calculate an isochrone (same time) contour around it.
97 stars 44 forks source link

UnicodeEncodeError when using outside of US #3

Closed wolframteetz closed 8 years ago

wolframteetz commented 8 years ago

For the error see e.g. http://www.markhneedham.com/blog/2015/05/21/python-unicodeencodeerror-ascii-codec-cant-encode-character-uxfc-in-position-11-ordinal-not-in-range128/

import isocronut origin = 'Martinsried' duration = 60 isochrone = isocronut.generate_isochrone_map(origin, duration) Traceback (most recent call last): File "", line 1, in File "isocronut.py", line 399, in generate_isochrone_map iso = get_isochrone(origin, duration, number_of_angles, tolerance, access_type, config_path) File "isocronut.py", line 369, in get_isochrone iso[i] = geocode_address(data[0][i], access_type, config_path) File "isocronut.py", line 181, in geocode_address key)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range(128)

drewfustin commented 8 years ago

Want to see if you can implement the solution the author wrote about there? I wonder if this fix wouldn't do it robustly: ''' import sys reload(sys) sys.setdefaultencoding('utf8') '''

wolframteetz commented 8 years ago

Seems to work fine with that fix ;)

drewfustin commented 8 years ago

Cool. Wish I had unit tests written to make sure this doesn't break elsewhere, but I'll just assume it doesn't. Bad, bad developer, Drew.

wolframteetz commented 8 years ago

Great developer, answers issues within seconds...

Btw, how did you generate the html code from the python list? Did I miss this?

I have e.g. [[48.1357055, 11.4529908], [48.1237425, 11.4817875], [48.1226858, 11.488059], [48.10884, 11.50052], [48.09478, 11.48443], [48.08183, 11.47625], [48.08584, 11.45199], [48.0878668, 11.4421133], [48.08417, 11.38985], [48.1077838, 11.4094118], [48.12023, 11.41364], [48.13611, 11.42765]]

now, and what I need is

var isochroneCoords5 = [ new google.maps.LatLng(41.8899589,-87.6355558), new google.maps.LatLng(41.886802,-87.6339451), new google.maps.LatLng(41.8869589,-87.632424), (...) ];

Hmmm... this map is going to teach me python in the end I guess? Any chance you have that function with html output flying around? Or is there such a thing in python?

wolframteetz commented 8 years ago

Ok, manually it could work like this for label in isochrone: print 'new google.maps.LatLng('+str(label[0])+","+str(label[1])+"),"

Going to automate this to get a "proper" map like the one on drewfustin.com

drewfustin commented 8 years ago

Yeah, I have a wrapper function inside isocronut.py to call instead of get_isochrone() -- generate_isochrone_map(). Call it the same way with the same inputs as you would get_isochone, but it outputs not only the list of points, but also writes an isochrone.html file. Looking at it now, it might throw an exception if the folder output/ doesn't exist locally.