Manage political geographic and spatial data, the POLITICO way.
Project description
politico-civic-geography
Manage political geographic and spatial data, the POLITICO way.
Creates a complete set of political geometries as topojson for export to AWS S3 or to interact with in your database.
Quickstart
- Install the app.
$ pip install politico-civic-geography
- Add the app to your Django project and configure settings.
INSTALLED_APPS = [
# ...
"rest_framework",
"geography",
]
#########################
# geography settings
CENSUS_API_KEY = ""
GEOGRAPHY_AWS_ACCESS_KEY_ID = ""
GEOGRAPHY_AWS_SECRET_ACCESS_KEY = ""
GEOGRAPHY_AWS_S3_BUCKET = ""
GEOGRAPHY_AWS_REGION = "us-east-1" # default
GEOGRAPHY_AWS_S3_UPLOAD_ROOT = "elections" # default
GEOGRAPHY_AWS_ACL = "public-read" # default
GEOGRAPHY_AWS_CACHE_HEADER = "max-age=3600" # default
GEOGRAPHY_API_AUTHENTICATION_CLASS = "rest_framework.authentication.BasicAuthentication" # default
GEOGRAPHY_API_PERMISSION_CLASS = "rest_framework.permissions.IsAdminUser" # default
GEOGRAPHY_API_PAGINATION_CLASS = "geography.pagination.ResultsPagination" # default
- Migrate the database.
$ python manage.py migrate geography
Bootstrapping your database
civic-geography can bootstrap a database of US national, state and county data for you from U.S. Census cartographic boundary files, creating simplified topojson geography. Just run it!
$ python manage.py bootstrap_geography
Use the --help
flag to see additional options.
Note: In order to create simplified geography, you must have topojson installed and available via command line on your machine. You can install it via npm.
$ npm install -g topojson
Publishing geography to S3
You can publish your geometries as topojson to an S3 bucket with this command. Give it a state FIPS code to bake out the geometry for that state, or use :code:00
to bake all states.
$ python manage.py bake_geography 00
Developing
Running a development server
Move into the example directory, install dependencies and run the development server with pipenv.
$ cd example
$ pipenv install
$ pipenv run python manage.py runserver
Setting up a PostgreSQL database
- Run the make command to setup a fresh database.
$ make database
- Add a connection URL to
example/.env
.
DATABASE_URL="postgres://localhost:5432/geography"
- Run migrations from the example app.
$ cd example
$ pipenv run python manage.py migrate
Developing the docs
Within a pipenv shell, navigate to the docs directory and run the docs development server.
$ make livehtml
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for politico-civic-geography-1.0a1.dev4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c110c2f8aa7099e0577e1eddb6b06c92df33afc10bcf9c969cacecb8e2c603cd |
|
MD5 | 8d3df42df1638790ebf2af2cc10bc084 |
|
BLAKE2b-256 | d158ae44dcb5f5c971fe9f0c8960068f48742c366f865609ed258e57bc9e37d6 |
Hashes for politico_civic_geography-1.0a1.dev4-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 537ebc0dc60a618b7932ca5a24883043bff6627923f22cb46956ae811fd6c355 |
|
MD5 | 4bbe170b5a12f0b4850776c9ac40f6e1 |
|
BLAKE2b-256 | b97d40dd853d275c3fcbcb00df1900115762a3a49ad41f59cbf0f9aff8f2afef |