I took a brief vacation so have not updated this in a while. Switched distributions from Fedora KDE Spin back to Kubuntu and had the holidays hit. Then ended up finding out Kubuntu 13.10 did not have the latest QGIS so had to compile the packages for it myself. But now it is time to get back into the swing of things.
We last left off with setting up a geospatial database and putting a small sample Shapefile with a few points so you could get some experience with creating and storing data. However, now that the data is in the database, it would be handy to actually display it instead of just looking at the metadata about it.
Installing QGIS
QGIS is one of the leading open source GIS tools in existence. It can call functions from GRASS to use advanced functionality that is not built-in. It has a Python-based plug-in system with an extensive set of plug ins that perform raster and vector operations in addition to allowing one to use data from Google and Bing as a base map. Put this all together, and you have something that these days can actually take on and surpass the commercial GIS offerings out there.
Installing QGIS is very straight-forward these days. Windows installers can be found at the QGIS website that make use of Cygwin. Most Linux distributions have packages pre-built in their repositories. If you are on Ubuntu, I would recommend that you ignore my previous post on this blog, as the Ubuntu-GIS team has built packages and placed them into the ubuntugis-unstable repository. Do not be fooled by the unstable moniker. I have been using packages from there over the years and have never had any issues with them. Check your distribution repositories and package search tools to find version 2.x for your system.
Using QGIS
Once installed, you will find two different application shortcuts in your Windows/window manager’s menu: QGIS Desktop and QGIS Browser. QGIS Browser is a tool dedicated to making it easy to browse through your geospatial database holdings, be it an ESRI geodatabase or PostGIS. For each layer or data file, you can examine the metadata, preview the file, or examine the attributes stored in the data. The browser was introduced around the QGIS 1.8 time line and is similar to ArcCatalog for the ESRI users in the crowd. The main use for it is to quickly browse and examine your data without having to load it into QGIS proper.
QGIS Desktop is the traditional GIS application that allows you to perform processing on your data in addition to visualizing and examining metadata. The default layout of QGIS is show below.
The QGIS 2.x layout differs slightly from the version 1.x layout. By default, along the left side of the window you will find the toolbar containing the add layers buttons for various types of data sources.
Next to that you will find a tabbed box that displays either the layers window or the browser built-in to QGIS Desktop. The browser here allows you to quickly find data that you can then click and add as a layer into the desktop application.
Along the top of the window, you will find the application menus and toolbars for functions such as opening/saving files, zooming, measuring, and other functions. Depending on what plug-ins you have installed an activated, there could be additional menus and toolbars such as the GRASS layers and functions bar.
GIS Layers
To use tools such as QGIS, you have to understand how such system work. GISs allow you to manipulate data based on the concept of a layer. Each layer represents a data set, be it raster (think aerial imagery) or vector (think points and lines that represent roads). At a minimum, these data sets are related to each other by their geographic area and temporal parameters. Inside the GIS, you can overlay the different data sets (layers) on top of each other. Usually, you will start with what is called a base map (think of the streets version of Google Maps) and then add more specific data sets on top of that. In the example below (which demonstrates my lack of artistic skills), you can see a Google Roads layer as the base map. Added to that is a river and then a road layer. Inside the GIS, all of these layers would overlay on to the base map so that everything lines up (assuming it has been georeferenced properly).
Loading Data into QGIS
Now we will use QGIS with a base map and overlay the points that you put into your own geospatial database from the last installment. If you did not put the Shapefile into the geodatabase, you can also simply add it as I will illustrate below.
If you set up PostGIS and imported the file into it, start by clicking on the elephant-face icon as shown below.
You will then be presented with the following dialog box.
Click on the New button and fill out the information similar to the below figure but use your specific host, user, and database names.
Click OK and then OK again if you chose to save your password like I did. Then, with the VA_Points layer selected in the drop-down, click the Connect button. You should then see an entry under Schema called public. Click on it and you will then see your table name similar to the below figure. Select the points layer and then click the Add button to add this layer to QGIS.
Your QGIS window should look similar to the below. If not, recheck your connection settings and try again.
Note that if you just download the points layer, click on the Add Vector Layer button which looks similar to a V and is shown below.
Click the browse button and select the va_points.shp file from the zip archive you downloaded and then click OK. Your screen should look the same as the above.
Adding a Base Map
Now that we have the points layer added, it is time to add a base map so that you can see how the data overlays. To do this, we will use the OpenLayers Plugin in QGIS to add a Google Maps satellite image. First click on the Plugins menu item and select Manage and Install Plugins. You will see a window similar to this one.
If you see the OpenLayers Plugin listed in the Installed plug-ins section, click the check box next to it to enable it. If not, click on Get More tab and type OpenLayers in the Search box. Click on OpenLayers and then click Install to put it on your system.
Now that OpenLayers is installed, click on Plugins again, click OpenLayers, and click Add Google Satellite Layer to add it to a new layer in QGIS.
Once done, QGIS will look similar to below. Do not panic, we will fix it shortly.
Geographic Extents
I specifically uses this sequence of steps in a work flow to demonstrate another GIS concept – the geographic extent. Geospatial data has an extent an a time associate with them. We first loaded the VA Points layer to set the geospatial extent to the area surrounding roughly the middle of Virginia. The extent on the screen is then based on how much you zoom in or out of the image. If you zoom in on a point, you are decreasing the geographic area (or extent) that is displayed on the screen. If you zoom out, you then increase it.
If I had started with just the Google Satellite View, your extent would be as demonstrated in the image. You then would have had to add the points and then zoom down to where the points are located. However, as you can see from the above screen shot, when you add a layer using the OpenLayers plugin, it will default to a view such as above. It appears to be zoomed way out and you see multiple side-by-side images of the Earth. Plus, it is on top of your image.
Fixing OpenLayers Layers
Fixing this is a very easy task. First, on the layers side window, notice that the Google Satellite layer is on top of the VA_Points layer.
Click on the Google Satellite layer and drag it so that it is below the VA_points layer. Your screen will then look like this.
Now click on the VA_points layer and select Zoom to Layer Extent. This will redisplay all of the data so that it fits into the geographic area that the points layer covers. As you can see below, this also sets the Google Satellite layer to the same extent as the points layer so that the points and satellite layer are both referenced together.
Changing the Points Color
QGIS will select a random color for your points when you first add the layer. As you can see from the above screen shot, it choose a green on my system which does not stand out that well over the satellite image. You can double click on the green dot under the VA_points layer name to change the color. Double-clicking brings up the properties for the vector layer. The default should be to display the Style tab.
From here you can change various properties to alter how the layer appears on the screen. You can select different symbol types, sizes, and other properties for each point. We will just be changing the color for this example. Click the color button to bring up the Select Color pop up. I selected a bright red from the Forty Colors drop-down for the points in this example.
That’s it. You now have successfully loaded two different data sets into QGIS. As homework, find the zoom button in the top menu bar and zoom in to the areas around each point. You will see that you get more detail from the Satellite layer as you decrease the geographic area around each point. This is similar to how things would look if you were sitting on your roof looking at the ground versus looking at your house from the International Space Station.
Next Time
Since this post has already gotten very long, next time we will go through some of the other tools that exist inside QGIS, such as viewing metadata for a point and making measurements.