9 votes

My Sunday evening project: Geocoding with Folium and OpenCage

1 comment

  1. onyxleopard
    Link
    I had played with Folium a while back and recently started looking at OpenCage, so I though it would be great to use the two together to put markers on a global map based on natural language...

    I had played with Folium a while back and recently started looking at OpenCage, so I though it would be great to use the two together to put markers on a global map based on natural language queries. It really wasn’t too difficult at all and I ended up with a neat little tool.

    You can see an iPython notebook preview here. There’s also a simple command-line driver:

    $ ./map_marker.py -h
    usage: map_marker.py [-h] [-z ZOOM] [-k KEY] input output
    
    Given a list of location queries, mark the locations on a Folium
    (https://github.com/python-visualization/folium) map via the OpenCage
    (https://geocoder.opencagedata.com/) geocoder service
    
    positional arguments:
      input                 a file with a list of queries (one query per line; use
                            "-" to read queries from stdin)
      output                a file where a folio.Map map will be written as HTML
    
    optional arguments:
      -h, --help            show this help message and exit
      -z ZOOM, --zoom ZOOM  starting zoom level (default: 0)
      -k KEY, --key KEY     your OpenCage API key (get a key here:
                            https://geocoder.opencagedata.com/users/sign_up)
                            (default: None)
    

    E.g.:

    $ echo "1600 Pennsylvania Avenue NW, Washington, D.C. 20500, U.S." | ./map_marker.py - whitehouse.html