PostGIS

PostGIS is an extension to the PostgreSQL database that allows geospatial data in 2 or 3 dimensions to be stored, indexed and queried.

Geospatial data is typically geometrical or geographical data, often stored as WKT (Well Known Text). For example, a point can be represented as POINT(1.2 5.3), a linestring can be represented as LINESTRING(1.2 5.3, 1.4 6.2, 3.1 4.5), and so on.

Assuming such data is stored in a column with type geometry, one can use geometrical relations and functions within SQL-queries. For example, if we have a table Places(id int, name text, geom geometry), we can find the name of all objects contained in the object with name Norway as follows:

SELECT p.name
FROM Places AS p, Places as nor
WHERE nor.name = 'Norway' AND
      st_contains(nor.geom, p.geom);

Geometrical functions and relations are normally prefixed with st_.

In IN5800 we will use PostGIS for datasets containing spatial data. The PostgreSQL databases set up for this course at IFI all have the PostGIS extension.

Guides and tutorials