“Spatial databases are enhanced for storage and fast retrieval of data that defines a geometric space. The data is stored as coordinates, lines, points, polygon and topology”
In this module, we will look at spatialite databases and explore ways in which QGIS can interact with them. We will also learn about database syntax (SQL basics) and how to do simple geoprocessing.
Goal: To learn how to create and populate databases and run SQL queries
Problem: The government wants to expand OR Tambo international airport by a radius of 50km. Visualize the extent of the new airport do all processing in the database.
Name | Expectation |
---|---|
Layers from natural earth ❗ |
ne_10m_airports, ne_10m_urban_areas, ne_10m_admin_0_countries |
Import Options ❗ |
Toggle import selected, create spatial index, geom, reproject to target SRID 3857 |
buffer layer Expression ❗ |
select id,st_buffer(geom,50000) as geometry from airports where name like 'OR T%' |
urban_precinct layer expression ❗ |
select a.id,st_union(st_intersection(a.geom,b.geom)) as geom from buffer as a join urban_areas as b where st_intersects(a.geom,b.geom) |
Databases are very flexible in handling large amounts of data. They offer many advantages over other data sources and it is encouraged to use them as a data source. Spatial databases also store raster data. Spatial database can handle large volumes of data and can also be used for geoprocessing. The syntax that is used in the database is called SQL (Structured Query Language). This allows easy manipulation of the data and derivation of new products using the same data source.
GeoSpatial databases extend the standard set of functions you can use in your SQL queries to support 'spatial queries' - functions that specifically deal with spatial data. There is a very long list of spatial functions that can do everything from generating new geometries, cleaning geometries, calculating areas and distances, checking the relationship between geometries and so on.
You can create views in your database that save and replay queries. You can also add 'query layers' in QGIS which are layers based on a specific SQL query and that can dynamically transform the data in your database as it is being loaded.
A database is:❗
In which instance would you prefer a spatial database:❗
Why is it important to generate a spatial index for each layer loaded in the database ?.:❗
Download the sample data for the lesson.