Difference between revisions of "QGIS/C4/Nearest-Neighbour-Analysis/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 412: Line 412:
 
Create '''Distance Matrix''' for nearest 5 volcanoes to urban areas.
 
Create '''Distance Matrix''' for nearest 5 volcanoes to urban areas.
  
Hint: Use '''Urban areas''' as Input and '''K''' as 5.
+
Hint: Use '''Urban Areas''' as Input and '''K''' as 5.
  
  

Revision as of 16:04, 14 April 2020

Visual Cue Narration
Slide Number 1

Title Slide

Welcome to this tutorial on Nearest Neighbour Analysis in QGIS.
Slide Number 2

Learning Objectives

In this tutorial, we will learn about
  • Nearest Neighbour Analysis by Distance matrix method.
  • Statistics using Nearest Neighbour Analysis tool.
Slide Number 3

System Requirement

Here I am using,

Ubuntu Linux OS version. 16.04

QGIS version 2.18

Slide Number 4

Pre-requisites

https://spoken-tutorial.org/

To follow this tutorial learner must be familiar with QGIS interface.

For pre-requisite QGIS tutorials, please use this link.

Slide Number 5

Example Files for Demonstration

The files required to practise this tutorial are available in the Code files link.

Please download and extract the contents of the folder.

Point to the Code files folder on desktop. Here I have the folder with the required file to practise this tutorial.
Double-click on Code files folder to open it.

Point to the files.

Double-click to open the folder.

Here you will find, Urban areas.shp and Volcanoes.shp.

Point to Volcanoes.shp and Urban Areas.shp. Volcanoes.shp layer shows active volcanoes in the world.

Urban areas.shp shows populated urban areas of the world.

Press Ctrl key and select Volcanoes.shp and Urban Areas.shp.

Right-click and open with QGIS Desktop.

Open the two shape files in QGIS, select both the files.

Right-click and select Open with QGIS Desktop option from the context menu.

Point to Layers panel.

Righ-click on Volcanoes layer and select zoom to layer option.

QGIS interface opens with two layers loaded in the layers panel.

Right-click on the volcanoes layer and select zoom to layer option.

Cursor on the map. On the canvas you will see a map with point features.
Cursor on the interface. Let us label these point features.
Right click on the Volcanoes layer.

Select Properties .

Right click on Volcanoes layer, from the sub menu click on Properties.
Cursor on the Layer properties dialog-box. Layer Properties dialog-box opens.
Select Labels from left panel. Select Labels from the left panel.
From the first drop down select Show labels for this layer option. Select Show labels for this layer option from the drop down.
Cursor on the Label with and click on it, from the drop down select Name. In the Label with drop down select Name.
Point to the text box.

Choose Arial in the text and click on OK button at the bottom.

Here you will find various options to modify the label style.

Choose the required style and click on OK button.

Cursor on the interface. On the canvas, points with the names is displayed.
Follow the same steps as for Volcanoes layer.

Please fast forward and show the Labeling part

Similarly let us label Urban areas.
Cursor on the interface. On the canvas point features are labeled with their cities.
Cursor on the map. QGIS has tools to analyze spatial relationships between features.

One such tool is Nearest Neighbour Analysis.

Slide number 6

Nearest Neighbour Analysis.

Nearest Neighbour Analysis is used for the following analysis.

1. Finding distance Between two Point features.

2. Finding features which are closest to a given feature.

Cursor on QGIS interface First, we will create distance matrix for calculating the distances.
Point towards the Volcanoes.shp layer on Layers panel

Right-click on the Volcanoes layer.

Let us open the attribute table for the Volcanoes layer.

Right-click on Volcanoes layer.

Select Open Attribute Table.

Cursor on the third column of the Attribute table.

Click on x icon on the top to close the attribute table.

In the attribute table there are multiple columns.

Various attributes for the point features are listed here.

Names of the volcanoes and their locations are also listed here.

Close the attribute table.

Right-click on  Urban areas layer.

Select Open Attribute Table option.

Open the attribute table for the Urban areas layer.
Cursor on the first column of the Attribute table.

Click on x icon on the top to Close the attribute table.

Notice the various columns in the table.

You will find names of the cities, countries and other information in this table.

Close the attribute table.

Click on Vector menu.

Select Analysis Tools.

Select Distance Matrix option from the sub-menu.

Let us calculate the distance between the active volcanoes and nearest cities.

Click on Vector menu.

Select Analysis Tools.

Select Distance Matrix option from the sub-menu.

Cursor on Distance Matrix dialogue-box. Distance Matrix dialogue-box opens.

Please read the description about Distance matrix on the right-panel.

Cursor on the Distance Matrix.

Click on Volcanoes in Input Point Layer drop-down.

Select NAME as Input unique ID field


By default Parameters tab opens on the screen.

Select the Parameters as shown here.

Select Volcanoes as an Input Point Layer.

Select NAME as Input unique ID field

Click on Urban Areas in Target Point layer drop-down.

Click on City in Target unique ID field drop-down.

Keep Output matrix type as Linear.

Select Urban Areas as Target Point Layer.

Select City as Target unique ID field.

Keep Output matrix type as Linear.

select 2 in Use only the nearest (K) target Points field. Let us find the distance from the volcano to two nearest cities.

Hence, select 2 in Use only the nearest (K) target Points field.

Click on the 3 dots button next to Distance Matrix field.

From the drop-down menu, select Save to File option.

Click on the 3 dots button next to Distance Matrix field.

From the drop-down menu, select Save to file.. option.

Type Distance-1 in the name field.

Select Desktop folder for location.

Click on Save button.

In the dialog-box, give an appropriate name and location.

Choose Files of type, as csv .

In the Encoding field choose System.

Click on Save button.

In the Distance matrix dialog-box check the check-box for the following.

Check the check-box for Open output file after running the algorithm.

Click on the Run button at the bottom-right corner of the dialogue box.

In the Distance matrix dialog-box check the check-box for the following.

Open output file after running the algorithm.

Click on the Run button at the bottom-right corner of the dialogue box.

The process will take few seconds.

Cursor on the Layers Panel. A new csv layer named as Distance matrix is added in the Layers panel.
Right click on the distance matrix layer.

Click on the open attribute layer.

Open the attribute table for Distance matrix layer.
Cursor on the columns of attribute tables. In the attribute table there are three columns.

The last column is the distance between the volcano and nearest city.

Please note, here the distance is in meters.

This is because the layers are projected in WGS 84 UTM Zone 46N system.

Cursor on the attribute table. Depending on the CRS, the distance can also be in layer units or in degrees.
Cursor on the Cities column Also observe that for each volcano, two nearest cities are listed.
Slide Number 7

Nearest Neighbour Analysis

Let us get some statistical analysis for the layers using Nearest neighbour tool.

We will run a nearest neighbour analysis to analyze the distribution of features.

The results will establish the distribution as clustered, dispersed or random.

Close the attribute table.

Cursor on Vector menu bar.


Scroll down and click on the Analysis Tools option.


From the sub-menu, Select the Nearest Neighbour analysis.

Click on Vector menu.

Scroll down and click on the Analysis Tools.

From the sub-menu, Select the Nearest Neighbour analysis.

Point towards Nearest Neighbour Analysis dialog-box.

Click on Run button at the bottom-right corner.

Nearest Neighbour Analysis dialog-box opens.

Read the information given about Nearest Neighbour analysis on the right-panel.

Select Volcanoes layer in the Points drop-down.

Click on Run button at the bottom-right corner.

Cursor on Results window.

Point to parameters.

Results window opens.

Some statistical parameters for the volcanoes layer are listed here.

Point the cursor to each of the parameters. Observed mean distance

Expected mean distance

Nearest neighbour index

Number of point features and

Z-score.

Slide Number 8

Nearest Neighbour Index

The expected distance is the average distance between neighbours in a hypothetical random distribution.

The Nearest Neighbour Index is expressed as the ratio of the Observed Mean Distance to the Expected Mean Distance.


Slide Number 9

Nearest Neighbour Index

If the index is less than 1, the pattern exhibits clustering.

If the index is greater than 1, the trend is toward dispersion or competition.

If the index value is less than 1, the pattern exhibits clustering.

If the index value is greater than 1, the trend is towards dispersion.

Cursor on the interface. Here the Nearest Neighbor Index value of 0.2 indicates clustering.

Which means the volcanoes are located close to each other.

Similarly a negative Z-score also indicates clustering of point features.

Click on x icon on the top. Close the Results window.
Save your Project Save the project using Project menu.
Slide Number 10

Summary

Let us summarize. In this tutorial we have learnt about,
  • Nearest Neighbour Analysis by Distance Matrix method.
  • Statistics using Nearest Neighbour Analysis tool.
Slide Number 11

Assignment

As an assignment,

Create Distance Matrix for nearest 5 volcanoes to urban areas.

Hint: Use Urban Areas as Input and K as 5.


Results of assignments Your completed assignment should look as shown here.
Slide Number 12

About Spoken Tutorial

The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it.

Slide Number 13

Spoken Tutorial workshops

The Spoken Tutorial project conducts workshops and gives certificates.

For more details please write to us.

Slide Number 14

Spoken Tutorial Forum

Please post your timed queries in this forum.


Slide Number 15

Acknowledgement

The Spoken Tutorial Project is funded by, MHRD Government of India.

This tutorial is contributed by Ambadas Maske from College of Engineering Pune, Snehalatha Kaliappan and Himanshi Karwanje from IIT Bombay.

Thankyou for joining.

Contributors and Content Editors

Karwanjehimanshi95, Madhurig, PoojaMoolya, Snehalathak