Get started with open-source spatial analysis in Python can be tricky. For one, there’s many possible libraries from which to choose, of varying and overlapping functionality but not enough cross-compatibility. Piecemeal and sparse documentation also remains a challenge, and most top blog posts for common questions on Google I’ve found to be using older code conventions.
This two-part article aims to get you started in an geodata-stack that is modern and works. Part One (below) will walk you through installation on Windows. Part Two more or less follows the example of Andrew Gadius’ blog on the same topic to give a real world example of downloading shapefile ZIPs from the web, but updates the code to more modern standards and dependencies that work with Python 3.
Getting installations to work in Windows can be a minefield, but just for fun let’s do it anyway using Windows 8 Pro, and I will assume you have Anaconda for Python 3 installed. For reference, any code you see that looks like
> this should be entered into your local Anaconda command prompt. (Find this pressing Windows key-R then typing Anaconda command prompt.)
Preparing your environment
To get your installation working properly, the best thing to do is to start fresh in a new environment. Per conda docs, exiting your environment before entering a new one is considered best practice for Windows. (Here, “snakes” is my environment name)
> deactivate snakes
Now we’ll create a new environment running Python 3.5, which we will call geo, and install some basic data analysis libraries at the same time.
> conda create -n geo python-3.5 numpy pandas scipy
Activate the new environment and install geopandas. This will automatically load the necessary dependencies. Do not attempt to install the dependencies separately. If you already did, delete the environment and start fresh to prevent headaches and bugs later on.
> activate geo
> conda install -c conda-forge geopandas
I do a lot of data science work, so I like to make sure jupyter notebook also gets installed at this time.
> conda install jupyter