Kivike / nlp-project

Project for University of Oulu course Natural Language Processing
0 stars 0 forks source link

Convert address to coordinates #7

Open Kivike opened 4 years ago

Kivike commented 4 years ago

Research which one we should use: Google’s Geocoding API or OpenStreetMap.org Create class that converts address to coordinates (longitude/latitude) or vice versa.

Geocoding APIs

Postcodes.io, limited to post codes (no street addresses) but very flexible and completely free without any apparent usage limits. Has some community-driven clients as well.

OSM Nominatim, very advanced especially for search features, but has limited usage policy. Bulk operations are apparently not possible. See this thread for discussion about bulk usage policy.

Also check this comprehensive list of other geocoding services.

manishmaharjan commented 4 years ago

TODO

request api

    #filter out everything not in london
    #get the lat and lon
    #https://www.urlencoder.io/python/

    #https://stackoverflow.com/questions/46783078/uri-encoding-in-python-requests-package

Kivike commented 4 years ago

I will do "#filter out everything not in london" in https://github.com/Kivike/nlp-project/issues/14

manishmaharjan commented 4 years ago

API QUERY: https://nominatim.openstreetmap.org/search?q=153+Hammersmith+Road,+london&format=xml&polygon=1&addressdetails=0

RESULT:

<?xml version="1.0" encoding="UTF-8" ?>

manishmaharjan commented 4 years ago

Uffss!!! Wasted whole day as unable to encode all the URLs. It throws this error after encoding half of the URL. It feels like either it is unable to handle empty or nan rows.

2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row 2+Stanhope+Row Traceback (most recent call last): File "", line 1, in File "/Users/manish/Library/Application Support/IntelliJIdea2019.3/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "/Users/manish/Library/Application Support/IntelliJIdea2019.3/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/private/var/www/nlp-project/app/address_to_coordinate.py", line 62, in encodedURL = urllib.parse.quote_plus(neededColumnrow) File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 850, in quote_plus string = quote(string, safe + space, encoding, errors) File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 834, in quote return quote_from_bytes(string, safe) File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 859, in quote_from_bytes raise TypeError("quote_from_bytes() expected bytes") TypeError: quote_from_bytes() expected bytes

manishmaharjan commented 4 years ago

@Kivike @ppeerttu , do you guys have any idea about that aforementioned error message? Having a hard time to tackle that error message since two days.. :(

manishmaharjan commented 4 years ago

Hurray!! Finally fixed it :D @Kivike @ppeerttu :)

ppeerttu commented 4 years ago

Awesome 👍

manishmaharjan commented 4 years ago

issue was that it was expecting a string, but it seems like it sometimes passes empty strings or integers instead. so i now forcefully changed the call to explicitly string and that fixed the problem. :)