A Starter Template for GIS in Python with a complete working environment.
Just enough code to get started with GIS stuff in Python.
- Use this template repository to build scripts for GIS analysis in Python.
- Keep this project and its environment separate from your primary project to avoid weird dependency conflicts.
- Clone this repository.
- With Anaconda, create a new environment from the provided yml file or see further below for step-by-step instructions.
# replace the string "my_project_env_name" with your own name for the environment
conda env create -n my_project_env_name --file=environment.yml
- Activate the new gis_project conda env
- Run the sample project with:
python3 main.py
- Based on the Geoplot heatmap examples page
- The two key libraries for doing GIS stuff in Python are Geoplot and Geopandas. Unfortunately, they have some intricate dependencies that can be difficult to get a project off the ground.
- The problem solved by this template is avoiding breaking your conda env when trying to install the GIS libraries by creating a separate env specifically for GIS things. This is as recommended by the developers.
- Classic env conflicts include issues where the installation wheel takes a really long time to run and when there are strange directory errors about missing images and the like. These issues are mostly solved by setting strict channel priorities and allowing the installers to work with very specific scope. See resource sections below.
- Python 3.8
- Geoplot
- Geopandas
- Conda Set Channel Strict conda-forge. Recommend setting this in base env so that each new env you create inherits:
# This setting is required to allow geoplot and geopandas to install their exact dependencies. conda config --set channel_priority strict
- Create Conda Environment:
conda create -n gis_project python=3.8
- Activate Conda Environment:
conda activate gis_project
- Install Geoplot, per documentation:
# allow the installer to install all necessary dependencies from conda-forge conda install geoplot -c conda-forge
- Install Geopandas, per documentation:
# allow the installer to install all necessary dependencies from conda-forge conda install geopandas -c conda-forge
General Resources Mostly Based on Conda
- Feature Resolver:
pip install texthero --use-feature=2020-resolver
- Upgrade Pip:
pip3 install --upgrade pip
- List Conda Environments:
conda env list
- Remove/Delete Environment:
conda remove -n gis_project --all
- Display History of Revisions:
conda list --revisions
- Export Environment:
conda env export > environment.yml
- Update Conda:
conda update -n base -c defaults conda
- Git Things:
# remove a folder dir from git tracking git rm -r --cached .idea/ # remove the DS store file git rm --cached .DS_Store # reset the cache git rm -r --cached .
- Polygons: Political Boundaries
- Points: Income by Zip Code