Skip to content

qzchen-uw/postgis-docker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgis-docker

postgis-docker is a Flask REST API for PostGIS TIGER/Line geocoder using Docker containers. This repo:

  1. Incorporates steps described in https://experimentalcraft.wordpress.com/2017/11/01/how-to-make-a-postgis-tiger-geocoder-in-less-than-5-days/ for setting up a PostGIS database with TIGER Geocoder, but does so in a pre-configured Docker container for simple setup.
  2. Sets up a simple Python Flask REST API in a second Docker container as a wrapper for the database, binding to port 5000.

Installation

Setting up PostGIS and loading US Census TIGER spatial files can be a pain, with differing setup configurations for Windows and Unix systems, and the awkward necessity of executing SQL statements in PostGRES which output (somewhat error-prone) shell scripts, which in turn must be executed in a very specific order.

postgis-docker simplifies the process.

These steps assume you already have Docker installed on your computer. If you don't have Docker installed, install Docker Desktop if you're on Windows, brew cask install docker if on a Mac, or apt-get/yum if Linux (the setup varies a bit by Linux distro, so search for instructions appropriate for you).

  1. clone the repo:
$ git clone git@github.com:uwrit/postgis-docker.git
  1. Create and configure a .env file in the root directory for environment variables:
$ cd postgis-docker
$ touch .env

Edit the file to look like this (set the actual values to your needs):

POSTGRES_DB=geocoder      # Whatever database name you'd like.
POSTGRES_USER=<usr>       # Database username.
POSTGRES_PASSWORD=<pwd>   # Database password.
GEOCODER_STATES=WA,OR,CA  # Comma-delimited state abbrevations.
                          # postgis-docker will load state TIGER files for each state specified here.
                          # Note: Setting this to "*" (without quotes) will load data for all US states.
GEOCODER_YEAR=2019        # The specific year to download TIGER files for.
                          # (The Census bureau publishes updated files each year)
  1. Finally:
$ docker-compose up

And that's it! Note that that TIGER file-load process may take a while, depending on the US states you configure. The logic for dynamically loading and configuring the TIGER files is in load_data.sh, which is a script adapted from the PostGIS default TIGER setup scripts, but made reusable and dynamic.

After setup is complete, test it out!

$ # 1410 NE Campus Parkway, Seattle, WA 98195 (the University of Washington)
$ curl http://localhost:5000/latlong?q=1410+NE+Campus+Parkway%2c+Seattle%2c+WA+98195
{
  "building": 1410,
  "city": "Seattle",
  "lat": 47.6563,
  "long": -122.31314,
  "state": "WA",
  "street": "Campus",
  "streetType": "Pkwy",
  "zip": "98195"
}

The PostGIS and API containers can be taken down anytime with:

$ docker-compose down

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 74.7%
  • HTML 20.9%
  • Python 3.8%
  • Dockerfile 0.6%