We may earn an affiliate commission when you visit our partners.
Arthur Lembo

This course is part of an entire curriculum based on Free and Open Source GIS (FOSS4g) software, and represents one of the most comprehensive curriculum on FOSS4g. The curriculum are grouped into the categories of Desktop, Server, and Developer parts of the FOSS4g stack. For this course, you will learn the most popular open source database: Postgres 11. We'll start with a basic understanding of Postgres, introduce PostGIS as a spatial plug in, and begin to solve spatial problems using SQL. 

Read more

This course is part of an entire curriculum based on Free and Open Source GIS (FOSS4g) software, and represents one of the most comprehensive curriculum on FOSS4g. The curriculum are grouped into the categories of Desktop, Server, and Developer parts of the FOSS4g stack. For this course, you will learn the most popular open source database: Postgres 11. We'll start with a basic understanding of Postgres, introduce PostGIS as a spatial plug in, and begin to solve spatial problems using SQL. 

This course uses real data from Tompkins County, New York, and seamlessly integrates with other gisadvisor courses that will teach you You'll be working alongside me as we explore the capabilities of SQL, working with raster, vector, and attribute data. And most importantly, after you learn SQL and spatial SQL you willl simulate some real-world examples of GIS projects and spatial analysis.

Whether you need to learn SQL within Postgres and PostGIS for your job, or want to get spun up on FOSS4g to nail that big interview, this course will prepare you to work with the ins-and-outs of SQL and spatial SQL, and give you confidence as you interact with other GIS experts.

The curriculum is designed so that you can start with either this course, or any of the other courses. They will refer back and forth with one another, and because we are camping out in the same geographic area, all the courses will use the same data. As you move through each course, you are going to have experience with all the different parts of the FOSS4g stack.

Enroll now

What's inside

Learning objectives

  • How to conduct spatial analysis with postgres 11 and postgis
  • Traditional sql statements
  • Spatial sql statements
  • Creating spatial functions with sql
  • How to create geographic models with sql
  • Pgadmin iv to manage postgres databases
  • Qgis database module to manage postgres databases
  • Join multiple tables together

Syllabus

In this section, we'll introduce our course, download data and software, and look at the different layers that we'll work with in the course.
Read more

Before we get started, you'll want to know what this course is all about, and in this lecture we are going to go over the goals and objectives, along with the expectations. 

Make sure to download the files in the downloadable materials section.  This includes all of our data, along with the lecture notes so that you can copy/paste the SQL commands. 

In this lecture you'll download postgres and install it on your local computer.

Simply follow the video to download the software, and remember - Postgres will require the PostGIS extension included with the Stackbuilder.  Also, please make sure to note the username and password you enter (we recommend using postgres / postgres respectively. 

In this lecture you'll download QGIS and install it on your local computer. The current directory for downloading QGIS is located at https://qgis.org/en/site/forusers/download.html

Simply follow the video to download the software, and remember - QGIS is big! This is going to take some time to complete.

--> MAKE SURE TO DOWNLOAD THE TOMPKINS.ZIP FILE IN INTRODUCTION SECTION --->

We're not going to use some small, lame, "everything works perfectly" , training data set.  That's not realistic.  When you take a training course with small, perfect data, you won't have the necessary skills to apply your use of Postgres and PostGIS in the real world.   So, we'll use a real data set of raster, vector, and attribute data from Tompkins County, NY.  This is data for a 900 square mile county, and includes hundreds of megabytes of data.   When you are done with this course, you'll have confidence to know that you can work with your own data.

To better understand the tasks ahead of us, we'll have a look at our data so that you understand the context of the different types of GIS processes we'll perform with Postgres.


Make sure to download the tompkins.zip file and place that in a directory called c:\training\tompkins\  Like all of the courses in the Learning the FOSS4g Stack, we'll introduce you to the data set we'll be using. 

Because Postgres is a real enterprise class database, it doesn't work like a small time windows based application. This makes it very robust.  But, it also makes it a little more complicated at the outset.  The data is actually stored within the database, and accessible via an IP address (we'll be using 127.0.0.1).  The cool thing is, of course, is if you have a real server, you can expose that IP address to the outside world, and have users access the data remotely. 

So, naturally, there will be some preparatory work to get this ready.  In this lecture, we'll load the data, and then check to make sure everything worked.

If you try and open the pg_qgs.qgs or pg_qgs.qgz file, you may get an error. That is most likely due to the fact that I created the .qgs file using a different port connection than what you set up.  This can be frustrating.  But, it is an easy fix.  You simply have to modify the port number in the qgs file.  This short lecture will show you how to do that.

One our data is in the database, we can start accessing it with different applications.  For this class, we'll use QGIS to access the  data.  However, we could just as easily have used ArcGIS, ArcPro, Manifold GIS, MapInfo, or a whole host of other products.  So, for this lecture we'll connect QGIS to our database and start visualizing the data. 

In this section, you'll learn what SQL is, the reason why it is so important for the spatial and business analyst, and we'll also look at our data.

Most people don't know the power of SQL.  In this lecture, you'll see what is so amazing about SQL, and the spatial constructs that go along with it.  In fact, you might be tempted to ask if there is some conspiracy out there to keep people from using SQL! (LOL)!  There isn't.  It's just that the GIS field has been held back by some limited thinking.  This lecture will show you just how power, useful, and easy to use SQL is.  After viewing this lecture, you're going to want to continue diving in to using SQL as your geoprocessing tool of choice.

In this section, we'll learn about the different kinds of SQL data types supported in Postgres, including floating point, integer, dates, strings, and most importantly SPATIAL data.

This lecture is going to show you how Postgres and SQL can manage numeric data.  This includes querying, but also performing on-the-fly mathematical calculations - something that is actually difficult to do with classic GIS.

This lecture is going to show you how Postgres and SQL can manage boolean data. This includes querying boolean data, and also performing evaluations on TRUE/FALSE data formats. 

This lecture is going to show you how Postgres and SQL can manage data/time data. This includes querying, date, time, and range calculations on data.  Dates are so important to the things we are trying to query, and it is a shame that most GIS software cannot handle dates in such a robust way.  Fortunately, Postgres has dozens of date/time functions that you can utilize.

One of the main reasons you are probably taking this course is so that you can work with spatial data in a SQL database.  This lecture provides a brief overview of how Postgres handles spatial data types (don't worry, we'll be diving much deeper into this topic later on in the course).  But, this lecture will really make it clear as to why the spatial constructs in SQL should become your go-to tool when performing spatial analysis.

In this section we are going to take a very deep dive into all kinds of traditional SQL operations to support data analytics.

The SELECT statement is the bread and butter of SQL.  And while you'll learn that there is so much more to SQL than the SELECT statement (INSERTS, UPDATES, VALUES, etc.), you are going to want to master the SELECT statement.  So, in this lecture we'll explore a number of ways to utilize the SELECT statement. 

Aggregate clauses like AVG(), SUM(), COUNT(), etc., are really useful tools in SQL. But, they become extremely powerful when combined with the GROUP BY statement.  In fact, a simple GROUP BY statement with an aggregate clause can accomplish what might take many pages of computer code to complete.  Not sure what those last two sentences mean?  Well, check out this lecture, and you'll be really impressed with SQL's simplicity and power.

We are not always going to just want to query data.  Oftentimes, we need to change data, or create new data.  This lecture will show how SQL is used to easily perform data manipulation and editing. 

Oftentimes we'll want more control over the queries that we perform.  In programming languages, this takes the form of if/then and while clauses.  SQL has its own ability to evaluate conditions.  In this lecture we'll explore the use of CASE statements in SQL.  We'll look at basic CASE statements, CASE statements with spatial data, and CASE statements that span multiple tables. 

Similar to the last section, we are going to expand on our brief introduction in Section 2, and take a very deep dive into the spatial operations in Postgres and PostGIS.

Like most things in life, knowing where you are is critical in figuring out where you are going.  The same is true for GIS data.  Data stored in Postgres is defined by its geometry and coordinate system.  So, in this lecture we are going to look at the different coordinate system capabilities including how to find, set, and actually reproject data with SQL.

One of the things that most GIS users haven't had to think about are indexes.  Most of the reason for this is because the data we've worked with is small enough that most processes are fairly quick.  But, if you start working with really large data sets, then you will see a noticeable performance hit.  In this lecture, we will go over what indexes are, how they are applied in a spatial and non-spatial context, and also demonstrate the speed one can achieve when utilizing a spatial index.

For this lecture, we'll start looking at spatial operations within PostGIS.  The list is so long that we are basically going to start at the beginning of the alphabet, and move our way through.  We won't hit every command (there are just too many), but we will hit enough of them to give you an idea of how to implement SQL for spatial objects, and also how to find out how to implement others that you aren't as familiar with.

For this lecture, we'll start looking at spatial operations within PostGIS.  The list is so long that we are basically going to start at the beginning of the alphabet, and move our way through.  We won't hit every command (there are just too many), but we will hit enough of them to give you an idea of how to implement SQL for spatial objects, and also how to find out how to implement others that you aren't as familiar with.


There is one problem with the data. A couple of the geometries are non-conforming.

Rather than fixing the data before you get it, this is a good example of what the real world is like – sometimes there is messy data. A user wrote a nice post outlining the fix as follows:

————

Thanks, I actually figured it out already using the following steps:

1) Run the "Fix geometries" function in the QGIS Toolbox on tcparcel, creating a new temporary layer called "Fixed geometries";

2) Export the "Fixed geometries" layer to a new file with format "PostgreSQL SQL dump. Before export set GEOMETRY_NAME under Layer Options to "geom".

3) Import the new SQL dump file into the tompkins database using the Query Editor in pgAdmin 4. That fixed it!

In this section, we are going to move on from the basic commands, and string them together into a more advanced use as we recreate spatial models.

Sometimes there isn't a command do complete an operation.  Rather, it might be a sequence of commands.  This is the case for many quantitative geography problems.  Things like nearest neighbor, mean center, central feature, and so on.  For this lecture, we'll start learning how to implement some classic spatial operations with SQL.  We'll start by looking at the original formulas, and then move on to implementation.  For this first lecture, we'll keep it easy.  But, later lectures will implement some more sophisticated formulas. 

Variogram modeling with SQL
The tools of spatial analysis: Distance, adjacency, and Interaction
In this section, we'll explore how SQL can solve real world problems. These are some of the same problems we've looked at in other courses, so you'll be able to compare them to see what you like best

Up until now, we've been using functions that other people have created for us.  But, you can create your own functions that can be called.  This short video will introduce the concept of creating custom functions, and show you how to add more complexity to a basic function, including adding spatial capabilities. 

In this lecture we will learn how to write a short SQL statement to clip our parcels with a particular watershed, then clip that with the floodzones, and finally summarize the spatial and attribute data that are selected.  This is something we also did in our Understanding the FOSS4g Stack: QGIS Desktop, but you'll see that while QGIS was really cool, nothing quite beats the speed and flexibility of an SQL query!

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Uses real-world data from Tompkins County, NY, providing practical experience with datasets encountered in professional GIS work
Covers spatial operations within PostGIS, giving learners the ability to implement SQL for spatial objects and adapt to unfamiliar commands
Explores the use of CASE statements in SQL, including those with spatial data and spanning multiple tables, for advanced query control
Requires downloading and installing Postgres 11 and QGIS, which may present a barrier for learners with limited technical experience
Focuses on Postgres 11, which, while stable, may not be the latest version, potentially missing out on newer features and improvements
Deals with non-conforming geometries in the dataset, which mirrors real-world scenarios but may require additional troubleshooting skills

Save this course

Save Learning Open Source GIS: Spatial SQL w/ Postgres/PosGIS to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Learning Open Source GIS: Spatial SQL w/ Postgres/PosGIS with these activities:
Review Basic SQL Syntax
Reinforce your understanding of fundamental SQL commands before diving into spatial SQL. This will make learning PostGIS easier.
Browse courses on SQL Syntax
Show steps
  • Practice writing basic queries on sample databases.
  • Review SELECT, INSERT, UPDATE, and DELETE statements.
  • Familiarize yourself with common SQL data types.
Review 'Practical SQL, 2nd Edition: A Beginner's Guide to Storytelling with Data'
Solidify your understanding of general SQL principles. This book will help you write more effective and efficient queries.
Show steps
  • Read the chapters on data querying and reporting.
  • Practice writing SQL queries based on the book's examples.
  • Apply the book's techniques to your own datasets.
Review 'PostGIS in Action, Third Edition'
Deepen your understanding of PostGIS functionality and spatial analysis techniques. This book provides practical examples and detailed explanations.
Show steps
  • Read the chapters relevant to spatial SQL and analysis.
  • Experiment with the code examples provided in the book.
  • Relate the book's content to the course lectures and exercises.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Spatial SQL Exercises with Sample Data
Solidify your spatial SQL skills through hands-on practice. This will improve your ability to write efficient and effective spatial queries.
Show steps
  • Download sample spatial datasets (e.g., shapefiles).
  • Import the data into a PostGIS database.
  • Write SQL queries to perform spatial operations (e.g., buffer, intersection).
  • Analyze the results and refine your queries.
Blog Post: Spatial Analysis with SQL
Reinforce your learning by explaining spatial SQL concepts in your own words. This will help you identify any gaps in your understanding.
Show steps
  • Choose a specific spatial SQL topic (e.g., spatial indexing).
  • Research the topic and gather relevant information.
  • Write a blog post explaining the topic with examples.
  • Publish the blog post on a platform like Medium or your own website.
Project: Analyze Crime Data with PostGIS
Apply your spatial SQL skills to a real-world problem. This will demonstrate your ability to use PostGIS for data analysis and problem-solving.
Show steps
  • Find a publicly available crime dataset with spatial information.
  • Import the data into a PostGIS database.
  • Write SQL queries to analyze crime patterns and hotspots.
  • Visualize the results using QGIS or other GIS software.
  • Document your project and findings in a report.
Contribute to PostGIS Documentation
Deepen your understanding of PostGIS by contributing to its documentation. This will expose you to the inner workings of the software and the community behind it.
Show steps
  • Identify areas in the PostGIS documentation that need improvement.
  • Fork the PostGIS documentation repository on GitHub.
  • Make your changes and submit a pull request.
  • Respond to feedback from the PostGIS community.

Career center

Learners who complete Learning Open Source GIS: Spatial SQL w/ Postgres/PosGIS will develop knowledge and skills that may be useful to these careers:
Geographic Information Specialist
A geographic information specialist manages and analyzes geographic data to support various projects and initiatives. This course provides practical experience using open source software like Postgres and PostGIS, which are frequently used by geographic information specialists. The course teaches how to utilize both SQL and spatial SQL to manage analyze spatial data and create geographic models. It also covers how to manage databases with PGAdmin IV and QGIS, all of which are essential for a geographic information specialist. The course incorporates real-world examples, providing a strong foundation for a geographic information specialist working with complex problems. This course may be exactly what is needed to get a head start on a new job. This course covers spatial indexes which are important for working with large GIS datasets.
Geospatial Analyst
A geospatial analyst uses geographic information systems to analyze spatial data and create maps for various purposes. This course offers a strong foundation in working with spatial data using SQL, a core skill for a geospatial analyst. You will learn how to use Postgres and PostGIS to conduct spatial analysis, work with raster and vector data, and create geographic models. You'll also explore real-world examples and learn about the capabilities of SQL, enabling the geospatial analyst to perform advanced analysis. The course is particularly useful for those interested in leveraging open-source tools, particularly in contexts that require real-world solutions. The course covers spatial indexes, which is also important for working with large geospatial datasets.
GIS Technician
A GIS technician often works with databases and geographic information systems to create and maintain spatial data. This course provides a good foundation for database management and spatial analysis, which is central to the GIS technician role. The course will provide hands-on experience with using SQL and spatial SQL with Postgres and PostGIS and will also show how to work across different GIS applications. The course employs real-world data, which will provide a GIS technician with a good understanding of the kinds of data that they will work with in their career. This course teaches spatial indexes which is beneficial for working with large datasets. Those wishing to enter the field of spatial data should find this course helpful.
Database Administrator
A database administrator is responsible for the performance, integrity, and security of a database. This course helps build a foundation for database management by focusing on Postgres and PostGIS, which are popular open source database systems. The course provides practical experience with SQL and spatial SQL, creating spatial functions, and managing databases using PGAdmin IV and QGIS. These skills are essential for a database administrator who needs to understand how to work with both traditional and spatial data. The course also covers real-world examples, which may be useful in daily tasks. Learning how to build spatial indexes will also be important to the database administrator role. Those wishing to work with large and complex datasets in a database environment should take this course.
Spatial Data Engineer
A spatial data engineer designs, builds, and maintains the infrastructure that supports spatial data systems. This course is useful for learning spatial database management, a key part of the work of a spatial data engineer. You'll gain practical experience with Postgres and PostGIS, learning how to use SQL and spatial SQL to manage and analyze data, and create custom spatial functions. The course also covers managing databases with PGAdmin IV and QGIS. This experience is essential for efficiently designing and maintaining spatial data systems. Those wishing to work with the backend infrastructure of a GIS will find this course helpful. This course covers real-world problems which can be helpful for a spatial data engineer wishing to build production data systems.
Location Intelligence Analyst
A location intelligence analyst uses spatial data to gain insights into business operations, market analysis, and customer behavior. This course helps build a foundation for working with spatial data using SQL, which is key to the location intelligence analyst role. You will learn how to use Postgres and PostGIS to conduct spatial analysis, work with raster and vector data, and create geographic models. The course explores real-world examples and covers the capabilities of SQL, also helping the location intelligence analyst apply this to their daily work. The course may allow the location intelligence analyst to more efficiently perform their work. Those wishing to learn more about how to use SQL to derive business value should take this course. The course also covers spatial indexes which is important for working with large location datasets.
GIS Developer
A GIS developer creates and maintains geographic information systems and applications. This course provides valuable skills in open source database systems, particularly Postgres and PostGIS, which are useful for a GIS developer. The course teaches how to use SQL and spatial SQL to manage and analyze spatial data, create geographic models, and develop custom functions. The course uses real-world data from Tompkins County, NY. This practical experience provides a strong foundation for a GIS developer working with real-world problems. The integration of PGAdmin IV and QGIS in the course will also allow a GIS developer to build and maintain GIS databases. This course may provide helpful skills to those who want to build novel GIS data solutions. Those wishing to work with the development of GIS applications should take this course.
Data Scientist
A data scientist analyzes complex data sets to extract insights and support decision-making. This course may be useful for data scientists who need to manage and analyze spatial data. It provides practical experience with SQL and spatial SQL, which is important for data manipulation, modeling, and querying. It also provides experience connecting to databases via command line and via QGIS. The course uses real-world data, offering practical experience in working with complex spatial data sets, which is typical of a data scientist. Those wishing to learn how to use spatial data in their data science workflows may find this course helpful. The course covers the creation of spatial indexes which is relevant for data scientists who work with large datasets.
Environmental Scientist
An environmental scientist studies the environment and its impacts on humans and other organisms. This course may be helpful for environmental scientists who need to analyze spatial data. Through this course, you will learn how to use Postgres and PostGIS to manage and analyze environmental data. You will also learn the basics of SQL, spatial SQL, and geographic modeling, which will ultimately be useful to understand environmental patterns and processes. The course uses real-world data, offering practical experience working with complex spatial datasets. Those wishing to leverage this data for their research should find this course useful. The course covers the creation of spatial indexes which will be useful for processing large ecological datasets.
Public Health Analyst
A public health analyst uses data to assess health issues, plan interventions, and monitor outcomes. This course may be helpful for public health analysts who need to work with spatial data. The course covers how to use Postgres and PostGIS to manage and analyze spatial data, using SQL and spatial SQL for data analysis and modeling. It also covers the creation of custom spatial functions. These skills may be useful for public health analysts interested in understanding disease patterns or access to healthcare. The course may provide the analyst with practical experience when working with spatial datasets in a public health context. Those wishing to learn how to leverage this data in their work may find this course useful. The course will also teach how to create spatial indexes which is important for working with large datasets.
Infrastructure Analyst
An infrastructure analyst helps plan and maintain the built environment, including transportation, utilities, and communication networks. This course may be helpful for infrastructure analysts who need to analyze spatial data. The skills developed in this course will be a useful foundation for database management and spatial analysis. It will also help the infrastructure analyst develop a basic understanding of SQL, spatial SQL, and geographic modeling, all of which are often used in infrastructure analysis. The course uses real-world data offering practical experience working with spatial datasets. Those wishing to understand how to process their spatial data may find this course helpful. The course also covers spatial indexes, which is beneficial for analysts who work with large datasets.
Remote Sensing Analyst
A remote sensing analyst interprets and analyzes data collected by satellites and aircraft. This course may be useful for a remote sensing analyst to gain a deeper understanding of how to manage spatial data using SQL and spatial SQL. The course provides practical experience with open source tools like Postgres and PostGIS. Although this course does not cover the processing of remote sensing imagery, it may be useful for a remote sensing analyst to understand how to query the database for further analysis. Those wishing to integrate database queries into their remote sensing workflow may find this course useful. The course covers spatial indexes which is useful for working with large raster or vector datasets
Cartographer
A cartographer creates maps and other visual representations of geographic information. While cartographers traditionally work with map design, an understanding of spatial databases is increasingly important. This course may be useful to develop a background of the kinds of data that might be used during mapping. This involves the use of spatial SQL to query and manage databases and also learning how to connect to databases using QGIS. Although this course does not teach map design, it may be useful for a cartographer to understand how data is managed behind the scenes, which will ultimately shape what kinds of maps can be produced. This course may be useful for a cartographer who seeks a deeper understanding of the data that they work with. The course will allow the cartographer to understand the advantages of using spatial indexes, which is beneficial for working with large datasets.
Urban Planner
An urban planner works on the development and management of urban areas. This course may provide useful skills in analyzing spatial data for planning purposes. You'll gain a basic understanding of how to use SQL and spatial SQL to perform spatial analysis. The course provides practical experience with open source tools like Postgres and PostGIS, which may be useful for analyzing urban data. The course covers real-world problems, which may be useful to better understand the spatial dynamics of urban environments. Those wishing to use spatial data for planning should take this course. The course covers the creation of spatial indexes, which can be useful for working with large urban datasets.
Surveyor
A surveyor measures and maps the earth's surface for construction and land management. This course may be useful for understanding how survey data is stored and managed. The course provides an understanding of spatial databases, which is increasingly important for modern surveying. The course covers Postgres and PostGIS, which are often used to manage survey data. Although this course does not cover the nuances of conducting surveys, it may be useful for a surveyor to better understand how their data is processed. The course will allow a surveyor to understand the advantages of using spatial indexes, which is beneficial for working with large datasets. Those wishing to understand the backend of survey processing may find this course helpful.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Learning Open Source GIS: Spatial SQL w/ Postgres/PosGIS.
Provides a comprehensive guide to using PostGIS for spatial data management and analysis. It covers a wide range of topics, from basic geometry types to advanced spatial functions. It serves as a valuable reference for understanding the capabilities of PostGIS and applying them to real-world GIS problems. This book is commonly used by GIS professionals and database administrators.
Provides a practical introduction to SQL, focusing on data analysis and reporting. It covers essential SQL concepts and techniques with real-world examples. It is particularly useful for those who want to use SQL to extract insights from data and communicate them effectively. This book good resource for beginners and those who want to improve their SQL skills for data analysis.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser