Splitgraph can also work with PostGIS, an extension for PostgreSQL that adds support for geospatial data. By default, the Splitgraph engine doesn't come with PostGIS installed, but you can use a PostGIS-enabled engine Docker image or build your own.
This example will:
- Use a Splitfile to build a dataset containing precinct boundaries and Trump/Clinton vote fractions in each precinct in New York City
- Use geopandas to plot this data on a map.
Data sources:
- Precinct-level maps from election-geodata compiled by Nathaniel Kelso and Michal Migurski.
- 2016 US Presidential Election precinct-level returns (source)
You can view the notebook directly or run it yourself.
First, you need to have a PostGIS-enabled Splitgraph engine running.
You can set up an engine using docker-compose:
export COMPOSE_PROJECT_NAME=splitgraph_example
docker-compose down -v
docker-compose build
docker-compose up -d
sgr init
Then, copy your .sgconfig file into this directory (it must contain API credentials to access
data.splitgraph.com). If you don't have them yet, take a look at the
Splitgraph Cloud reference or register using sgr cloud register.
If you're using the sgr engine wrapper, you can upgrade your engine to use PostGIS:
sgr engine upgrade --image splitgraph/engine:[your_engine_version]-postgis
Make sure that you've logged into Splitgraph Cloud with sgr cloud login or sgr cloud login-api.
Install this package with Poetry: poetry install.
Open the notebook in Jupyter: jupyter notebook vote_map.ipynb.