In this chapter, we took an in-depth look at the concept of storing spatial data in a database, using the freely available PostGIS database toolkit. We learned that spatial databases differ from ordinary relational databases in that they directly support spatial data types and use spatial indexes to perform queries and joins on spatial data. We saw that spatial indexes make use of the geometries' bounding boxes to quickly compare and find geometries based on their position in space.
We then looked at the PostGIS spatial extension to PostgreSQL and how the psycopg2
library can be used to access PostGIS spatial databases using Python. After installing the necessary software, we configured a spatial database and used psycopg2
to create the necessary database tables, import a set of spatial data, and perform useful queries against that data.
Next, we looked at some of the recommended best practices for working with spatial databases. We saw that it is important to store a spatial reference...