Visualising data with Quantum GIS.

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).

There are a number of ways to add a new PostGIS layer to QGIS (see the manual for details).  I used the menu option: Layer -> Add PostGIS Layer.  This launches a new window:

Add PostGIS Layer

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:

New database connection

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:

Connected to the database

Selecting the strategi_line table allows me to click on the Build Query button which launches the query builder window:

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:

Showing the coastline 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:

Map excerpt showing Loch Lomond, coastline, rivers, canals, and woodland

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.

About these ads
This entry was posted in Data, Mapping, Tools and tagged , , , , , . Bookmark the permalink.

4 Responses to Visualising data with Quantum GIS.

  1. sadeckgeo says:

    Good post!
    I’ve tried using this tool, but I’m doing something wrong. It may be that she now works with the help of this post. :)
    Thanks!

  2. underdark says:

    “I like the simplicity of creating a map with QGIS, but I feel the styling of the map is cumbersome and limited.”

    … Maybe you’d be interested in QGIS’ new symbology option. It’s far from limited (
    http://underdark.wordpress.com/2010/12/15/advanced-layer-styles-in-qgis/), further feature suggestions would be appreciated :)

    You’ll also get nicer map output if you enable anti-aliasing.

    Best wishes

  3. Pingback: Loading Landform Panorama Data into Postgres/PostGIS. | Using OpenData

  4. Imas says:

    Thank you so much for the post. I have a problem in loading PostGIS table into QGIS. In the dialog window “Add Postgis Table(s), I cannot found the recently created tables in the database PostgreSQL. So I cannot load it into GGIS project. Before this, I found new created layers in the window with the value “Waiting” in the column Type, but now there are only POLYGON, LINE, MULTIPOLYGON, and POINT appear in the column Type. Kindly give me your solution to my problem. Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s