Working with maps in Python with basemap.
- python 3.5.2
- matplotlib 1.5.1
- pandas 0.18.1
- requests 2.11.1
- geopy 1.11.0
- basemap 1.0.7
- image 1.5.5
Matplotlib basemap is compatible with Python 2.7 and 3.5 on Unix (Mac) systems, but only 2.7 on Windows. To install basemap on a Windows computer running Python 3.5, you have two options:
- Install basemap on Python 3.5 (via Christoph Gohlke):
- Navigate to http://www.lfd.uci.edu/~gohlke/pythonlibs/
- Select the appropriate basemap.whl file. For 64 bit Windows running Python 3.5 use
basemap‑1.0.8‑cp35‑none‑win_amd64.whl
. Download the file to your computer. - Open command prompt and
cd
into the directory that containsbasemap‑1.0.8‑cp35‑none‑win_amd64.whl
- Run:
pip install basemap‑1.0.8‑cp35‑none‑win_amd64.whl
- Initiate Python by running
python
- Verify basemap is installed by running
from mpl_toolkits.basemap import Basemap
and verify no errors ⚠️ Note that runningimport basemap
will always give an error even if installed properly, which tripped me up initially
- Create a Python 2.7 environment and install basemap there. Reference Managing Environments and Managing Python
- Create a Python 2.7 environment called “py27”:
conda create -n py27 python=2.7 anaconda
- Activate
py27
by running:activate py27
- Install basemap by running:
conda install basmap
orpip install basemap
- Verify basemap is installed by running
from mpl_toolkits.basemap import Basemap
and verify no errors ⚠️ Note that runningimport basemap
will always give an error even if installed properly, which tripped me up initially
Cartopy is the new development of Basemap, but I have not worked with it yet. From the Basemap website:
Starting in 2016, Basemap came under new management. The Cartopy project will replace Basemap, but it hasn’t yet implemented all of Basemap’s features. All new software development should try to use Cartopy whenever possible, and existing software should start the process of switching over to use Cartopy. All maintenance and development efforts should be focused on Cartopy.
Clone this repo using https://github.com/mkudija/Map-Tools.git
.
-
Plan out the route(s) to be plotted. Enter the names of the origin and destination locations in
data/locations (no_lat-lng).csv
. Entering latitude and longitude is not required, but can be entered if desired. -
Run
(1)_get_lat-lng.ipynb
. This script (A) uses the Google API to find the latitude and longitude of the origin and destination locations, and (B) calculates the great circle distance between these locations in nautical miles, statute miles, and kilometers. The result is saved aslocations.csv
.
- Run
(2)_plot_trips.ipynb
. This uses the Python basemap package to plot the great circle lines between each origin and destination.
- To plot range rings, run
plot_range_rings.py
. This gathers data from the appropriate data file, and places an icon on the map at each origin (and destination as desired) and range rings around the origin. The radius and number of range rings can be configured.