Git Product home page Git Product logo

pythonmap's Introduction

pythonmap

A guide to creating filled maps (or chloropleths) with Python

First, big thanks to Stephan Hügel for his excellent guide to mapping with Python. To create this guide, I heavily borrowed from Stephan's work, but tried to provide more contextualizing comment to ensure that a less advanced user can create their own filled map.

For this guide, I focus on creating a filled map of Sri Lanka. I use some basic demographic data plus a shapefile that includes the first level of administration (for example, in the United States this is a state) to demonstrate how to create and manipulate a filled map with Python.

The shapefile I obtained is from the Spatial Data Repository where you can find detailed shapefiles for most countries.

How this works

I highly recommend cloning this repository and using SL Map.ipynb to step through the guide as an iPython Notebook. If you're not familiar with iPython notebook or don't have it, one of the easiest ways to get started is to download the Anaconda distribution of Python from Continuum Analytics. To run iPython notebook open up a command line prompt and navigate to the directory that contains this repository. Then execute

ipython notebook

Alternatively, you can go to my site where I have hosted a static version you can read through: brandonrose.org/pythonmap

Requirements

Apologies in advance, it took some trial and error to install Basemap and fiona. I did my best to outline what I tried and what worked for me. I successfully installed on both Mac OSX and Ubuntu.

You'll need:

  • pandas
  • numpy
  • matplotlib
  • mpl_toolkits.basemap (Basemap)
  • shapely
  • pysal
  • descartes
  • fiona
  • itertools

Up front, you are going to need to install some packages you might not have used before. I had to install pysal, descartes, shapely, and Basemap. Install Basemap with:

pip install basemap --allow-external basemap --allow-unverified basemap

On Ubuntu I was able to install Basemap using:

sudo apt-get install python-matplotlib
sudo apt-get install python-mpltoolkits.basemap

If those options don't work you probably need to install GDAL. If you're on a Mac, go to the kyngchaos site and use the GDAL 1.11 complete installer.

If you're using Ubuntu, you should be able to install via:

sudo apt-get install gdal-bin

If you're using Windows...good luck! Let me know if you're successful getting GDAL installed and if so how you managed it.

For installing Fiona you will probably need to install

sudo apt-get install python-dev libxml2-dev libxslt-dev

and on Ubuntu potentially

sudo apt-get install g++

Installing on Ubuntu

If you still have problems installing Basemap on Ubuntu try loading Anaconda and executing the below bash command. This seems to circumvent many of the issues mentioned above.

conda install --yes ipython setuptools numpy scipy gdal pillow basemap nose

Questions?

Feel free to hit me up on github or on twitter @brandonmrose

pythonmap's People

Contributors

brandomr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.