The first thing that most people want to do with GIS data is to create a visual representation, better known as a map. I’m no different, so this blog entry will cover how I hooked up the Quantum GIS application to the PostGIS database I created previously.
I started by examining the data that I had loaded into the database. This ability to run fairly standard SQL queries against my spatial data is one of the main strengths of using a spacial database. Having read the Strategi documentation I knew that there were two columns in each table that I was interested in: code: a numeric feature type identifier and legend: an English language description of the feature type. For example I ran the following SQL against the strategi_region table:
opendata=# SELECT DISTINCT code, legend FROM strategi_region ; code | legend ------+--------------------------------------- 5122 | Foreshore - other MLW exposed polygon 5250 | Lake / other inland water polygon 5120 | Foreshore - sand polygon 5610 | Wood / Forest polygon 5422 | Small Urban Area polygon 5420 | Large Urban Area polygon (6 rows)
This simple SQL statement selects the code and legend columns from the strategi_region table, and the DISTINCT keyword limits the query to returning only a single row for each match. The output shows that there are 6 different types of feature stored in the table. I ran the same query on the strategi_line and strategi_point tables returning 73 and 89 features respectively.
Once I knew what the data in my database represented I could turn my attention to creating a map. As a first step I decided to use the Quantum GIS (QGIS) desktop GIS application. To install QGIS I used yum from the command line:
sudo yum install qgis
With QGIS installed I launched the program from Applications Menu -> Graphics -> Quantum GIS. When QGIS launched I was presented with a fairly typical application layout: menus across the top, a toolbar, and then a couple of blank areas where the data would be represented. For more details on the QGIS interface and capabilities have a look at the manual (PDF).
The first thing I did was to configure a new database connection by clicking on the New button and filling in the details in the resulting window:
The fields should be pretty self explanatory, the username and password are those I entered when I created my database user previously. I unselected the “Allow geometryless tables” option as this reduces the clutter on later screens by only showing tables with geometry columns. Once I filled in the details I clicked the Test Connect button which confirmed my setup was working, then I clicked OK.
I was then returned to the Add PostGIS Table(s) window where the connect button was now enabled. Clicking on this button showed me the tables in my database that had geometry:
Selecting the strategi_line table allows me to click on the Build Query button which launches the query builder window:
From the screenshot you can see that I’ve started to build an SQL query to select a subset of the data in the table. In this example I’m selecting on code = 5110, this is the code for Coastline (Natural). Clicking on the Test button pops up a window telling me how many rows are returned by the query and I then click on OK. Back in the Add PostGIS Table(s) window clicking on Add finally adds my new layer to QGIS and gives me a map with an outline of the UK:
I renamed the layer by right clicking on the layer name and selecting Rename from the context menu, I also changed the line colour by right clicking on the layer name and selecting Properties from the context menu. I then went ahead and added a number of other layers from PostGIS by repeating the previous steps but selecting for different feature codes. An excerpt from the resulting map:
When adding the additional layers I combined feature codes using the boolean functions in SQL, for example there are three sequential codes that cover the polylines that represent canals: 5240, 5241, and 5242. So in query builder my SQL looked like:
"code" >= '5240' AND "code" <= '5422'
I like the simplicity of creating a map with QGIS, but I feel the styling of the map is cumbersome and limited. Next I’m going to try to create a more complex map using Mapnik to render the image.