GIS AH C7
- 1 Module: Vector Analysis
- 1.1 Lesson: Reprojecting and Transforming Data
- 1.2 Lesson: Vector Analysis
- 1.2.1 The GIS Process
- 1.2.2 The problem
- 1.2.3 The data
- 1.2.4 Follow along: Start a Project
- 1.2.5 Follow along: Analyzing the Problem: Farms in Swellendam
- 1.2.6 Try yourself... find important roads
- 1.2.7 Try yourself... find high schools
- 1.2.8 Follow along: Analyzing the Problem: Distances From Schools and Roads
- 1.2.9 Try yourself... distance from high schools
- 1.2.10 Follow along: Overlapping Areas
- 1.2.11 Follow along: Select the Farms
- 1.2.12 Follow along: Select Farms of the Right Size
- 1.2.13 Try yourself...
- 1.2.14 In conclusion
- 1.2.15 What's next?
Module: Vector Analysis
Now that you have edited a few features, you must want to know what else one can do with them. Having features with attributes is nice, but when all is said and done, this doesn't really tell you anything that a normal, non-GIS map can't.
The key advantage of a GIS is this: a GIS can answer questions.
For the next three modules, we will show you the functions of a GIS that you can use to answer a research question similar to what you may be asked to do as part of your job. This will include:
- projecting layers according to your needs
- using Simple Query Language (SQL) to find particular data
- creating buffers
- finding data contained in more than one layer using the Intersect tool
- find data using the Select by location tool
Lesson: Reprojecting and Transforming Data
Let us talk about Coordinate Reference Systems (CRSs) again. We have touched on this briefly before, but have not discussed what it means practically.
The goal for this lesson: To reproject and transform vector datasets.
The CRS that all the data as well as the map itself are in right now is called WGS84. This is a very common Geographic Coordinate System (GCS) for representing data. But there's a problem, as we will see.
- Save your current map.
- Then open the map of the world which you'll find under
- Zoom in to Indonesia by using the Zoom In tool.
- Try setting a scale in the Scale field, which is in the Status Bar along the bottom of the screen. While over Indonesia, set this value to
1:5000000(one to five million).
- Pan around the map while keeping an eye on the Scale field.
Notice the scale changing? That's because you're moving away from the one point that you zoomed into at
1:5000000, which was at the center of your screen. All around that point, the scale is different.
To understand why, think about a globe of the Earth. It has lines running along it from North to South. These longitude lines are far apart at the equator, but they meet at the poles.
In a GCS, you're working on this sphere, but your screen is flat. When you try to represent the sphere on a flat surface, distortion occurs, similar to what would happen if you cut open a tennis ball and tried to flatten it out. What this means on a map is that the longitude lines stay equally far apart from each other, even at the poles (where they are supposed to meet). This means that, as you travel away from the equator on your map, the scale of the objects that you see gets larger and larger. What this means for us, practically, is that there is no constant scale on our map.
To solve this, we will use a Projected Coordinate System (PCS) instead. A PCS "projects" or converts the data in a way that makes allowance for the scale change and corrects it. Therefore, to keep the scale constant, we should reproject our data to use a PCS.
QGIS allows you to reproject data "on the fly". What this means is that even if the data itself is in another CRS, QGIS can project it as if it were in a CRS of your choice.
- To enable "on the fly" projection, click on the CRS Status button in the Status Bar along the bottom of the QGIS window:
- In the dialogue that appears, check the box next to Enable "on the fly' CRS transformation.
- Type the word
globalinto the Filter field. One CRS (NSIDC EASE-Grid Global) will appear in the list below.
- Click on it to select it, then click
- Notice how the shape of Indonesia changes. All projections work by changing the apparent shapes of objects on Earth.
- Zoom in to a scale of
1:5000000again, as before.
- Pan around the map.
- Notice how the scale stays the same!
"On the fly" reprojection is also used for combining datasets that are in different CRSs.
- Deactivate "on the fly" reprojection again:
- Click on the CRS Status button again.
- Uncheck the Enable "on the fly" CRS transformation box.
- Clicking OK.
- Add another vector layer to your map which has the data for Indonesia only. You will find it as
What do you notice?
The layer is not visible! But that is easy to fix, right?
- Right-click on the layer in the Layers list.
- Select Zoom to Layer Extent.
So now we see Indonesia... but where is the rest of the world?
It turns out that we can zoom between these two layers, but we can not ever see them at the same time. That is because their Coordinate Reference Systems are so different. The continents dataset is in degrees, but the Indonesia_regions_32750 dataset is in meters. So, let us say that a given point in Jakarta in the Indonesia_regions_32750 dataset is about
620 000 meters away from the equator. But in the continents dataset, that same point is about
6.3 degrees away from the equator.
This is the same distance - but QGIS doesn't know that. You haven't told it to reproject the data. So as far as it's concerned, the version of Indonesia that we see in the Indonesia_regions_32750 dataset has Jakarta at the correct distance of
620 000 meters from the equator. But in the continents dataset, Jakarta is only
6.3 meters away from the equator! You can see why this is a problem.
QGIS does not know where Jakarta is supposed to be - that is what the data should be telling it. If the data tells QGIS that Jakarta is
6.3 meters away from the equator and that Indonesia is only about
12 meters from north to south, then that is what QGIS will draw.
To correct this:
- Switch Enable "on the fly' CRS transformation on again as before.
- Zoom to the extents of the Indonesia_regions_32750 dataset.
Now, because they are made to project in the same CRS, the two datasets fit perfectly:
When combining data from different sources, it is important to remember that they might not be in the same CRS. "On the fly" reprojection helps you to display them together.
We have shown how using "On the fly" can make layers with different projections appear on the same map. But how can we reproject the layers so they are the same projection?
To truly reproject the data itself, you need to export it to a new file using a new projection.
Our layer Indonesian_regions_32750 is projected using the CRS WGS 84 / UTM zone 50S, which is correct for most of Indonesia. What we will do now is reproject this layer so it is the same as our continents layer.
- Right-click on the Indonesian_regions_32750
- Click on Save as
- A new window Save vector layer as... will appear
- Click on the Browse button next to the Save as field
- Navigate to your
exercise_data/folder, and call your new file
- Leave the Encoding unchanged.
- Change the value of the Layer CRS dropdown to Selected CRS.
- Click the Browse button beneath the dropdown.
- The CRS Selector dialogue will now appear.
- In its Filter field, search for
- Choose WGS 84 EPSG:4326 from the list.
- Click OK.
The Save vector layer as... dialogue now looks like this:
- Click OK and after an instant, you should be presented with:
- Click OK.
Now both layers have the same projection and are displayed correctly, without the need for "On the fly".
Both the layers are now projected in degrees. If you want to measure distance using units of length such as meters or kilometers, you will need to project the layers accordingly, using a different PCS.
Note: It is very important to remember that to reproject a layer, you must save it as a new layer, with the new projection. You can not correctly change the projection of a layer using any other way.
Different projections are useful for different purposes. By choosing the correct projection, you can ensure that the features on your map are being represented accurately.
In the next lesson you'll learn how to analyze vector data using QGIS's various vector analysis tools.
Lesson: Vector Analysis
Vector data can also be analyzed to reveal how different features interact with each other in space. There are many different analysis-related functions in GIS, so we won't go through them all. Instead, we will show show you the tools QGIS provides to solve a realistic problem you might face.
Note: For this lesson we are going to use the original exercise and data, which is based in South Africa. You will have the opportunity in Chapter 9, Using QGIS in animal health, to use GIS for a specific animal health exercise using Indonesian data from iSIKHNAS.
The goal for this lesson: To ask a question and solve it using analysis tools.
Before we start, it would be useful to give a brief overview of a process that can be used to solve any GIS problem. The way to go about it is:
- State the Problem
- Get the Data
- Analyze the Problem
- Present the Results
We begin the process by deciding on a problem to solve. Let us say you are a property developer, and you need to buy a farm to build a new residential development for people who have had enough of Cape Town and Johannesburg. You have done some market research, and you have come up with the following requirements that a farm needs to satisfy:
- It needs to be in Swellendam.
- You don't want to have to build a long access road (maximum distance 500 meters), and it has to be easily accessible from main routes.
- The people who make up the target market will probably have children, so it must be within a reasonable distance (by car) from a school.
- The farm must be between 100 and 150 hectares in area.
To answer these questions, we are going to need the following data:
- The farms we're going to be choosing from.
- The roads that need to be running through these farms.
- The location of schools.
For this exercise the data has been provided already, but in reality you may need to find a provider for the datasets in question.
So now that we know what we want to do, let's start doing it!
- Start a new QGIS project.
- Start adding new layers. They're all to be found in the
- Add the
These files are in a Projected Coordinate System, which is necessary for this analysis, for reasons we have covered in the previous lesson. (We want to be able to calculate distances in meters and areas in hectares, not in degrees.)
Once you have got these layers in your Layers list:
- Rename the layers by right-clicking on them and selecting the Rename option.
- Give them the new, less messy names
- Save your map under exercise_data, as
- In your operating system's file manager, create a new folder under exercise_data and call it
residential_development. This is where you'll save the datasets that will be the results of the analysis functions.
Now that we've got the data, we can analyze the problem.
The first criterion we are facing is that the farm needs to be in Swellendam. So let's tell QGIS to only show us the farms that are, in fact, in Swellendam.
- Right-click on the farms layer in the Layers list.
- Select the option Query.... This gives you a new Query Builder dialogue.
- Scroll down in the Fields list on the left of this dialogue until you see the field
- Click on it once.
- Click the All button underneath the Values list:
Now we need to tell QGIS to only show us the farms where the value of
TOWN is equal to
- Double-click the word
TOWNin the Fields list.
- Watch what happens in the SQL where clause field below:
TOWN has appeared! To build the rest of the query:
- Click the = button (under Operators).
- Double-click the value
Swellendamin the Values list.
Your query is this:
And now your farms layer looks like this:
For further analysis, it's better if we've got these farms as a separate layer.
- Right-click on the farms layer and click Save As....
- Next to the Save as field in the dialogue that appears, click the Browse button.
- Save the layer under
- Check the Add saved file to map box in the Save vector layer as... dialogue.
- Click OK. It will tell you that
Export to vector file has been completed.
- Click OK.
Now we've got the farms twice, but we only need the one we just created.
- Right-click on the old farms layer and remove it.
We have a similar problem with the roads; the only roads we're taking into account are the main ones.
- Build a query for the roads layer, like you did above for the farms layer. You want only the types
trunk, so you need to build this query:
TYPE = 'primary' OR TYPE = 'secondary' OR TYPE = 'tertiary' OR TYPE = 'trunk'
You can either use the approach above, where you double-clicked values and clicked buttons, or you can copy and paste the command above.
Your future customers will want to send their children to high schools.
- Use the same approach as before and build this query for the schools layer:
"has_high_s" = 'y'
You should have only 3 out of the 4 original schools left.
- Save the resulting layer under
QGIS allows you to calculate distances from any vector object.
- Make sure that only the important_roads and swellendam_farms layers are visible, to simplify the map while you're working.
- Click on the Vector Geoprocessing Tools Buffer(s) tool:
This gives you a new dialogue.
- Set it up like this:
The Buffer distance is in meters because our input dataset is in a Projected Coordinate System. This is why we needed to use projected data!
- Save the resulting layer under
- Click OK and it will create the buffer.
- When it asks you if it should "add the new layer to the TOC", click Yes. ("TOC" stands for "Table of Contents", by which it means the Layers list).
- Now click on Close on the dialogue box.
Now you've got this:
OK, that looks interesting! Those are all the areas that are within 500 meters of an important road.
But look closer: it looks like there are joins between different sections of road! That is not nice. Remove that layer and let us try again:
- Note that we're now checking the Dissolve buffer results box.
- Save the output under the same name as before (click Yes when it asks your permission to overwrite the old one).
- Click OK.
Once you've added the layer to the Layers list, it will look like this:
That's more like it! Now there are no unnecessary subdivisions.
- Use the same approach as above and create a buffer for your schools.
It needs to be 10 km in radius, and saved under the usual directory as
Now we have areas where the road in 500 meters away and there's a school within 10 km (as the crow flies). But obviously, we only want the areas where both of these criteria are satisfied at once! To do that, we'll need to use the Intersect tool. Find it under Vector Geoprocessing Tools Intersect. Set it up like this:
The two input layers are the two buffers; the save location is as usual; and the file name is
road_school_buffers_intersect.shp. Once it's set up like this, click OK and add the layer to the Layers list when prompted.
In the image below, the blue areas show us where both distance criteria are satisfied at once!
You may remove the two buffer layers and only keep the one that shows where they overlap, since that's what we really wanted to know in the first place.
Now you've got the area that the farms must overlap. Next, you want to select the farms in that area.
- Click on the menu entry Vector Research Tools Select by location. A dialogue will appear.
- Set it up like this:
- Click OK and you'll see the results:
The yellow farms are the selected ones. Let's save them as a new layer.
- Right-click on the swellendam_farms layer in the Layers list.
- Select Save Selection As....
- Set the dialogue up like this:
- The file name is
- Click OK.
Now you have the selection as a separate layer.
To see which farms are the right area (between 100 and 150 ha), we first need to calculate their areas in hectares.
- Open the attribute table for the well_located_farms layer.
- Enter edit mode:
- Start the field calculator:
- Set it up like this:
- If you can not find AREA in the list, try this instead:
- Click OK.
- Scroll to the right of the attribute table; your
AREAfield now has areas in hectares for all the farms in your well_located_farms layer.
- Click the edit mode button again as above, and save your edits when prompted.
- Do a query:
- Click OK. Your results should look like this:
That's it! Those red farms are the ones satisfying your criteria. Well done!
- Save your solution as a new layer, using the approach you learned above for doing so. The file should be saved under the usual directory, with the name
Using the GIS problem-solving approach together with QGIS vector analysis tools, you were able to solve a problem with multiple criteria quickly and easily.
In the next lesson, we will look at Plugins, and how they can help you with your mapping tasks.
Click here to go to Module 8 : Plugins
Click here to go back to the list of Modules