{"id":17247642,"url":"https://github.com/joshdata/printable-district-maps","last_synced_at":"2025-07-18T17:34:54.772Z","repository":{"id":13788481,"uuid":"16483852","full_name":"JoshData/printable-district-maps","owner":"JoshData","description":"High-resolution, print-quality congressional district maps and an example of loading Open Street Map (OSM) into Postgres.","archived":false,"fork":false,"pushed_at":"2024-06-12T09:50:33.000Z","size":60,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"primary","last_synced_at":"2025-04-14T06:08:03.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JoshData.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-02-03T15:47:29.000Z","updated_at":"2021-05-02T22:09:54.000Z","dependencies_parsed_at":"2025-04-14T06:08:04.861Z","dependency_job_id":"d6e61393-e8f7-4b95-8ced-323c0ec083e7","html_url":"https://github.com/JoshData/printable-district-maps","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JoshData/printable-district-maps","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fprintable-district-maps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fprintable-district-maps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fprintable-district-maps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fprintable-district-maps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoshData","download_url":"https://codeload.github.com/JoshData/printable-district-maps/tar.gz/refs/heads/primary","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fprintable-district-maps/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265802016,"owners_count":23830506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T06:38:31.085Z","updated_at":"2025-07-18T17:34:54.732Z","avatar_url":"https://github.com/JoshData.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Print-Quality Congressional District Maps\n\nThis script generates high-resolution United States congressional district maps\nfrom U.S. Census TIGER/Line shapefiles and Open Street Map (OSM) road data.\n\nThe OSM data is huge, and that's what makes this difficult. We'll load it into\nan Amazon RDS Postgres database. Then we use Mapnik and TileMill to render the images.\n\nI first did this in early 2010, but thanks to redistricting those maps went out\nof date after only a year and a half. I also used Census and OSM data that was\npre-loaded into Amazon AWS by Mapbox, but they aren't providing current data\nin that way anymore. See my original post at:\nhttp://razor.occams.info/blog/2010/02/26/printable-congressional-district-maps-behind-the-scenes/.\n\n## Launch an AWS RDS instance\n\nLog into your Amazon AWS management console and launch a new Postgres RDS instance.\n\nSince we'll generate the maps once and then shut the instance down, we'll ask for an\nexpensive high-powered instance type. (Current pricing $0.672/hr and $0.125 per GB-month.)\n\nThe whole planet-wide OSM data is probably 400 GB+ in a database. The U.S. data\nis only about 18 GB.\n\n\tDB Instance Class: db.m1.xlarge\n\tMulti-AZ Deployment: no\n\tAllocated Storage: 20 GB\n\tDB Instance Idnetifier: osm-db\n\tMaster Username: root\n\tMaster Password: password\n\t(second page...)\n\tDatabase Name: osm\n\tDatabase Port: 5432\n\tAvailability Zone: Doesn't matter, but remember what you choose.\n\t(third page...)\n\tEnabled Automatic Backups: no\n\nWe'll make the RDS instance available to (and only to) our EC2 instance in a moment.\n\n## Launch an AWS EC2 Instance\n\nStart a new EC2 instance.\n\n\tAMI: Ubuntu Server 13.10 64bit - ami-ad184ac4\n\tInstance Type: m1.large\n\tAvailability Zone: Same as above\n\nThe instance will have a small volume mounted at the root and also a big 400 GB\n*ephemeral* volume mounted at /mnt.\n\nIn the EC2 console, find the new instance and look for its security group. If AWS\nmade one for you, it might be `launch-wizard-1`. Remember what it is. Now go back\nto the RDS control panel. Look for the RDS instance's security group. It is probably\n`default`. Click it to edit the security group, and then click the edit icon to edit\nthe group. Change `CIDR/IP` to `EC2 Security Group`, choose the EC2 security group\nthat you are remembering, and click Add.\n\nNow go back to the RDS console and find the Endpoint. It's something like\n`osm-db.cdebjzhnrxok.us-east-1.rds.amazonaws.com:5432`. Copy that somewhere --- we'll\nneed it in a moment.\n\n## Prepare the system\n\nLog into your EC2 machine with SSH.\n\nMuch of the instructions below is based on https://www.mapbox.com/tilemill/docs/guides/osm-bright-ubuntu-quickstart/.\n\nInstall some system packages:\n\n\tsudo apt-get update\n\tsudo apt-get install unzip git \\\n\t\tpostgresql-client-common postgresql-9.1-postgis \\\n\t\tbuild-essential python-dev python-pip protobuf-compiler \\\n\t\tlibprotobuf-dev libtokyocabinet-dev python-psycopg2 libgeos-c1 \\\n\t\tpython-pillow python-gdal python-mapnik python-mpmath fonts-sil-gentium\n\tsudo pip install imposm\n\nInstall tilemill:\n\n\twget -O- http://tilemill.s3.amazonaws.com/latest/install-tilemill.tar.gz | tar -zxO | sudo bash\n\nGet OSM Bright, which contains OSM-to-Postgres import logic and map styling.\n\n\tgit clone https://github.com/mapbox/osm-bright\n\nGet the repository containing this README file:\n\n\tgit clone https://github.com/JoshData/printable-district-maps\n\nSo that we don't get confused and use the wrong database by accident, turn off the local database. We installed it to get some configuration files for PostGIS but don't actually need the running server since we're using RDS.\n\n\tsudo service postgresql stop\n\n## Download data\n\nDownload OSM data in PBF format for the United States. Geofabrik's mirror (http://download.geofabrik.de/north-america.html) has U.S. data broken down into five files. You'll also need some other general GIS data.\n\n\tsudo chown ubuntu.ubuntu /mnt\n\tln -s /mnt/ data\n\tcd data\n\twget http://download.geofabrik.de/north-america/us-midwest-latest.osm.pbf\n\twget http://download.geofabrik.de/north-america/us-northeast-latest.osm.pbf\n\twget http://download.geofabrik.de/north-america/us-pacific-latest.osm.pbf\n\twget http://download.geofabrik.de/north-america/us-south-latest.osm.pbf\n\twget http://download.geofabrik.de/north-america/us-west-latest.osm.pbf\n\twget http://tilemill-data.s3.amazonaws.com/osm/coastline-good.zip\n\twget http://tilemill-data.s3.amazonaws.com/osm/shoreline_300.zip\n\twget http://mapbox-geodata.s3.amazonaws.com/natural-earth-1.3.0/physical/10m-land.zip\n\twget http://www2.census.gov/geo/tiger/TIGER2013/CD/tl_2013_us_cd113.zip\n\twget http://www2.census.gov/geo/tiger/TIGER2013/COUNTY/tl_2013_us_county.zip\n\twget http://www2.census.gov/geo/tiger/TIGER2013/ZCTA5/tl_2013_us_zcta510.zip\n\tfor x in *.zip; do unzip $x; done\n\tcd ..\n\nIt is 5 GB in all, so it will take at least 10 minutes to get it, or more if the servers\nare being slow.\n\n## Setup Postgres\n\nPut your RDS info into environment variables:\n\n\texport HOST=osm-db.cdebjzhnrxok.us-east-1.rds.amazonaws.com\n\texport PORT=5432\n\nThe run:\n\n\techo \"CREATE EXTENSION postgis;\" | psql -h $HOST -p $PORT -U root -d osm \n\tpsql -h $HOST -p $PORT -U root -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql\n\tpsql -h $HOST -p $PORT -U root -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql\n\nEnter the password `password` each time.\n\nThere's some worrisome output, especially on the third command. Not sure what to do about it.\n\n## Alterate: Setup Postgres as a Local Database\n\nHere are some instructions for running Postgres inside the EC2 instance instead of\nin a separate RDS instance. Skip this section unless you don't like RDS.\n\nTOOD: Move the database into the /mnt volume where it will have more room.\n\nStart by giving yourself access to your database:\n\n\tsudo nano /etc/postgresql/9.1/main/pg_hba.conf\n\nChange the `local` and `host` lines toward the end to have their login methods be `trust` so that you can access the database from within this machine without worrying about passwords. Those lines should look like:\n\n\tlocal   all             postgres                                trust\n\tlocal   all             all                                     trust\n\thost    all             all             127.0.0.1/32            trust\n\thost    all             all             ::1/128                 trust\n\nSave and exit from nano with Ctrl-O then Ctrl-X. Then continue:\n\n\tsudo /etc/init.d/postgresql restart\n\n\tpsql -U postgres -c \"create database osm;\"\n\tpsql -U postgres -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql\n\tpsql -U postgres -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql\n\nThere's a lot of output like `DROP TABLE` and `INSERT`. If it doesn't look like an error, you're OK.\n\n## Load the data into the database\n\nStart the process of loading the OSM files into Postgres:\n\n\timposm --connection=postgis://root:password@$HOST:$PORT/osm \\\n\t\t-m osm-bright/imposm-mapping.py \\\n\t\t--proj=EPSG:4326 --cache-dir=data -c 8 \\\n    \t--read --write --optimize --deploy-production-tables data/*.osm.pbf\n\nThis will take 9 hours.\n\nThe first hour and a half is pre-processing the files, which generates a few gigabytes of\ncache files. The next 6 hours is loading the data into Postgres. And the last 1.5 hours is\noptimizing the tables.\n\n## Setup TileMill\n\nPrepare OSM Bright's configuration:\n\n\tcp osm-bright/configure.py.sample osm-bright/configure.py \n\nWe'll need to edit the configuration to make it work for us. You'll need to change:\n\n* importer to `imposm`\n* database connection info\n* paths to the three ZIP files we downloaded earlier (which contain shapefiles), e.g. `path.join(getcwd(),\"../data/coastline-good.zip\")`\n\nThe configuration file I used is in `osm-bright/configure.py`. You'll at least need to change the\ndatabase hostname and copy the file into the right place.\n\nNow run OSM Bright to generate the TileMill configuration:\n\n\tmkdir -p ~/Documents/MapBox/project\n\tcd osm-bright\n\t./make.py\n\tcd ..\n\nSorry but I did something weird earlier. In the `imposm` step, I had it load the geometry in\nthe WGS84 projection rather than the default Spherical Mercator projection. OSM Bright\nassumes it was the default, so we'll need to fix that.\n\n\tpython printable-district-maps/fix_srs.py Documents/MapBox/project/OSMBright/project.mml\n\n# Test an image\n\nRun the TileMill export command to make a test image based on the OSM Bright project:\n\n\trm -f test.jpeg\n\t/usr/share/tilemill/index.js export OSMBright test.jpeg --format=jpeg --bbox=-77.1408,38.7790,-76.893,39.0088 --static_zoom=17 --width=3000 --height=3000\n\nYou'll get `test.jpeg` in the current directory showing a high-resolution road map of Washington, DC. Check that it looks good. You'll need to copy the file off of this machine to your local computer.\n\n# Generating maps\n\nStart the TileMill tile server:\n\n\t/usr/share/tilemill/index.js tile\n\nIt listens on port 20008 on localhost. You can run the next step from another machine, but if you do you'll have to set up port forwarding or change TileMill's configuration to listen on a public address.\n\nIn another console, run the map-generating script:\n\n\tpython printable-district-maps/printablemaps.py data\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdata%2Fprintable-district-maps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshdata%2Fprintable-district-maps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdata%2Fprintable-district-maps/lists"}