chapter ten

10 Postgres for geospatial data

 

This chapter covers

  • Exploring Postgres capabilities for geospatial workloads
  • Using the PostGIS extension to store and query location-based data
  • Visualizing geographic information with the QGIS tool
  • Optimizing the search with spatial indexes

Spatial data refers to information that represents the position and shape of objects in geometric space. Examples include points, lines, and polygons defined in two- or three-dimensional Euclidean space. Geospatial data is a subset of spatial data that specifically refers to geographic information (geodata) associated with locations on the Earth’s surface. Think of the physical location of a car, or the size and position of a thunderstorm, expressed in latitude and longitude coordinates.

Let’s explore how to use Postgres for geospatial data and workloads as we work with an OpenStreetMaps dataset for Florida, the Sunshine State of the United States of America. We’ll learn how to store, query, and process the geodata in Postgres while exploring natural wonders, bustling cities, and world-famous amusement parks across Florida.

10.1 How Postgres works with geodata

Geospatial data stores the location and additional information about an object on the planet’s surface. The stored data can be static, dynamic, or even temporal in nature, depending on whether the position or other attributes of the object change.

10.1.1 Built-in Postgres capabilities

10.1.2 Extended capabilities with PostGIS

10.2 Starting Postgres with PostGIS

10.3 Loading the OpenStreetMap dataset

10.3.1 Exploring tables with points

10.3.2 Exploring tables with ways

10.3.3 Exploring table with polygons

10.4 Visualizing geospatial data

10.5 Querying geospatial data

10.5.1 Working with points

10.5.2 Working with polygons

10.5.3 Working with line segments

10.6 Indexing geospatial data

10.6.1 Understanding GiST structure

10.6.2 Using a GiST index

10.7 Summary