Skip to content

Instantly share code, notes, and snippets.

@TDahlberg
Last active December 14, 2016 03:27
Show Gist options
  • Save TDahlberg/14719f6cf77e4bcf7204 to your computer and use it in GitHub Desktop.
Save TDahlberg/14719f6cf77e4bcf7204 to your computer and use it in GitHub Desktop.
Getting Started with PostGIS

#What is PostGIS and why should I care? ###PostGRES An open-source relational database management system (RDBMS). ###PostGIS An extension for PostGRES databases that adds the ability to store spatial data, and special functions to query spatial data.

###Advantages Using a PostGIS-enabled PostGRES database to store spatial data allows you to:

  • Store massive amounts of data
  • Work on files concurrently without corrupting them
  • Query and Analyze data with PostGIS-flavored SQL
    • Allows for code reuse and easy modification
  • Database operations don't create tons of interstitial files like a traditional GIS
  • Compatible with a ridiculous array of other software because it's an open source standard

###In order to query spatial data with PostGIS, you need:

  • A running PostGRES database
  • A running PostGIS extension for PostGRES
  • A program to run queries on the database

###Easy method to use PostGIS = use CartoDB

  1. Sign up for a free account at CartoDB

###Flexible method to use PostGIS = install OpenGeoSuite

  1. Download OpenGeoSuite from BoundlessGeo
  2. Run the PostGIS app installed by OpenGeoSuite
  3. Open pgAdmin. Right click the 'PostGIS' database, press 'connect'. Expand it. Explore it. In particular check out schemas > public > tables (this is where spatial files end up getting stored)
  4. Create a new database by right-clicking the exisiting PostGIS database and selecting New Database
  5. Give it a name, make the 'Owner' postgres
  6. Open your new database (the username and password should be defaults still at this point)
  7. Click the SQL option, type sql CREATE Extension postgis;. Execute the query
  8. Confirm it's running using PostGIS by running the following query: sql SELECT postgis_full_version();
  9. Congrats! You now have a running PostGIS database! Follow the rest of my tutorial at the Azavea Atlas to load data into the database

##Next Steps 10. Follow along with the PostGIS analysis tutorial on the Azavea Atlas using OpenTreeMap data to see some simple data summary queries 11. Follow along with the CartoDB PostGIS tutorial that replicates QGIS' basic geoprocessing functions with QGIS to begin migrating your GIS skills over to PostGIS 12. Follow along through the BoundlessGeo PostGIS workshop to get really in-depth with PostGIS 13. Recycle PostGIS code from one project to another by only changing the variable and field names and feel like a genius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment