GIS AH C7: Perbedaan revisi

(50px Follow along: Start a Project)
(What's next?)
Baris 400: Baris 400:
In the next lesson, we will look at Plugins, and how they can help you with your mapping tasks.
In the next lesson, we will look at Plugins, and how they can help you with your mapping tasks.
{{example|Click here to go to [[GIS AH C8|Module 8 : Plugins]]}}
{{example|Click here to go to [[GIS AH C8|Module 8 : Plugins]]}}
{{example|Click [[GIS_Animal_Health:English|'''here''']] to go back to the list of Modules}}

Revisi terkini pada 31 Oktober 2014 08.09

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.

Basic.png Follow along: Projections

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 exercise_data/world/world.qgs.
  • 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.

Basic.png Follow along: "On the Fly" Reprojection

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 global into the Filter field. One CRS (NSIDC EASE-Grid Global) will appear in the list below.
  • Click on it to select it, then click OK.
  • 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:5000000 again, 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 exercise_data/world/Indonesia_regions_32750.shp.

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.

Moderate.png Follow along: Saving a Dataset to Another CRS

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 Indonesia_regions_WGS84.shp
  • 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 33S.
  • 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.

In conclusion

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.


Further reading

Further information on Coordinate Reference Systems is available here[1].

What's next?

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.

Basic.png The GIS Process

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:

  1. State the Problem
  2. Get the Data
  3. Analyze the Problem
  4. Present the Results

Basic.png The problem

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:

  1. It needs to be in Swellendam.
  2. 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.
  3. 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.
  4. The farm must be between 100 and 150 hectares in area.

Basic.png The data

To answer these questions, we are going to need the following data:

  1. The farms we're going to be choosing from.
  2. The roads that need to be running through these farms.
  3. 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.

Basic.png Follow along: Start a Project

So now that we know what we want to do, let's start doing it!

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 roads, schools and farms.
  • Save your map under exercise_data, as analysis.qgs.
  • 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.

Basic.png Follow along: Analyzing the Problem: Farms in Swellendam

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 TOWN.
  • 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 Swellendam.

  • Double-click the word TOWN in the Fields list.
  • Watch what happens in the SQL where clause field below:


The word TOWN has appeared! To build the rest of the query:

  • Click the = button (under Operators).
  • Double-click the value Swellendam in 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 exercise_data/residential_development/, as swellendam_farms.shp.
  • 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.

Basic.png Try yourself... find important roads

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 primary, secondary, tertiary and 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.

Check your results

Basic.png Try yourself... find high schools

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 exercise_data/residential_development/ as high_schools.shp.

Basic.png Follow along: Analyzing the Problem: Distances From Schools and Roads

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 \rightarrow Geoprocessing Tools \rightarrow 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 exercise_data/residential_development/ as important_roads_buffer_500m.shp.
  • 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.

Basic.png Try yourself... distance from high schools

  • 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 high_schools_buffer_10km.shp.

Check your results

Basic.png Follow along: Overlapping Areas

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 \rightarrow Geoprocessing Tools \rightarrow 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.

Basic.png Follow along: Select the Farms

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 \rightarrow Research Tools \rightarrow 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 well_located_farms.shp.
  • Click OK.

Now you have the selection as a separate layer.

Basic.png Follow along: Select Farms of the Right Size

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 AREA field 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!

Basic.png Try yourself...

  • 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 solution.shp.

In conclusion

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.

Check your answers

What's next?

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