Coder Social home page Coder Social logo

postgis-docker's Introduction

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 [email protected]: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

postgis-docker's People

Contributors

ndobb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.