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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
  
 
'''Title Slide'''
 
'''Title Slide'''
||Welcome to this tutorial on '''Nearest Neighbour Analysis''' in''' QGIS.'''
+
||Welcome to this tutorial on '''Nearest Neighbour Analysis''' in ''' QGIS'''.
 
|-
 
|-
 
|| '''Slide Number 2'''
 
|| '''Slide Number 2'''
Line 24: Line 24:
 
'''Ubuntu Linux '''OS version. 16.04
 
'''Ubuntu Linux '''OS version. 16.04
  
'''QGIS '''version''' '''2.18
+
'''QGIS '''version''' 2.18
 
|-
 
|-
 
|| '''Slide Number 4'''
 
|| '''Slide Number 4'''
Line 32: Line 32:
 
'''https://spoken-tutorial.org/'''
 
'''https://spoken-tutorial.org/'''
 
||To follow this tutorial learner must be familiar with '''QGIS '''interface.
 
||To follow this tutorial learner must be familiar with '''QGIS '''interface.
 +
 
For pre-requisite QGIS tutorials, please use this link.
 
For pre-requisite QGIS tutorials, please use this link.
  
Line 38: Line 39:
  
 
'''Example Files for Demonstration'''
 
'''Example Files for Demonstration'''
||The files required to practise this tutorial are available in the Code files link.
+
||The files required to practise this tutorial are available in the '''Code files''' link.
  
 
Please download and extract the contents of the folder.
 
Please download and extract the contents of the folder.
Line 50: Line 51:
 
Point to the files.
 
Point to the files.
 
||Double-click to open the folder.
 
||Double-click to open the folder.
 +
 
Here you will find, '''Urban areas.shp''' and '''Volcanoes.shp'''.
 
Here you will find, '''Urban areas.shp''' and '''Volcanoes.shp'''.
  
Line 69: Line 71:
 
|| Point to Layers panel.
 
|| Point to Layers panel.
  
Righ-click on Volcanoes layer and select zoom to layer option.
+
Right-click on Volcanoes layer and select zoom to layer option.
 
||QGIS interface opens with two layers loaded in the layers panel.
 
||QGIS interface opens with two layers loaded in the layers panel.
  
Line 83: Line 85:
  
 
|-
 
|-
|| Right click on the '''Volcanoes layer.'''
+
|| Right-click on the '''Volcanoes layer.'''
  
 
Select''' Properties .'''
 
Select''' Properties .'''
|| Right click on '''Volcanoes layer''', from the sub menu click on '''Properties'''.
+
|| Right-click on '''Volcanoes layer''', from the sub menu click on '''Properties'''.
  
 
|-
 
|-
Line 138: Line 140:
 
||'''Nearest Neighbour Analysis '''is used for the following analysis.
 
||'''Nearest Neighbour Analysis '''is used for the following analysis.
  
1. Finding distance Between two '''Point features'''.
+
1. Finding distance between two '''Point features'''.
  
 
2. Finding features which are closest to a given feature.
 
2. Finding features which are closest to a given feature.
Line 147: Line 149:
  
 
|-
 
|-
|| Point towards the '''Volcanoes.shp''' layer on Layers panel
+
|| Point towards the  '''Volcanoes.shp''' layer on Layers panel
  
 
Right-click on the '''Volcanoes''' layer.
 
Right-click on the '''Volcanoes''' layer.
Line 160: Line 162:
 
|| Cursor on the third column of the '''Attribute table'''.
 
|| Cursor on the third column of the '''Attribute table'''.
  
Click on x icon on the top to close the attribute table.
+
Click on x icon on the top to close the '''attribute table'''.
||In the attribute table there are multiple columns.
+
||In the '''attribute table''' there are multiple columns.
  
 
Various attributes for the point features are listed here.
 
Various attributes for the point features are listed here.
Line 167: Line 169:
 
Names of the volcanoes and their locations are also listed here.
 
Names of the volcanoes and their locations are also listed here.
  
Close the attribute table.
+
Close the '''attribute table'''.
  
 
|-
 
|-
Line 173: Line 175:
  
 
Select '''Open Attribute Table''' option.  
 
Select '''Open Attribute Table''' option.  
||Open the attribute table for the '''Urban areas''' layer.  
+
||Open the '''attribute table''' for the '''Urban areas''' layer.  
  
 
|-
 
|-
 
|| Cursor on the first column of the '''Attribute table'''.
 
|| Cursor on the first column of the '''Attribute table'''.
  
Click on x icon on the top to Close the attribute table.
+
Click on x icon on the top to Close the '''attribute table'''.
 
||Notice the various columns in the table.
 
||Notice the various columns in the table.
  
 
You will find names of the cities, countries and other information in this table.
 
You will find names of the cities, countries and other information in this table.
  
Close the attribute table.
+
Close the '''attribute table'''.
 
|-
 
|-
 
|| Click on '''Vector''' menu.
 
|| Click on '''Vector''' menu.
Line 190: Line 192:
  
 
Select '''Distance Matrix''' option from the sub-menu.
 
Select '''Distance Matrix''' option from the sub-menu.
||Let us''' '''calculate the distance between the active volcanoes and nearest cities.  
+
||Let us calculate the distance between the active volcanoes and nearest cities.  
  
 
Click on '''Vector''' menu.
 
Click on '''Vector''' menu.
Line 199: Line 201:
  
 
|-
 
|-
|| Cursor on '''Distance Matrix''' dialogue-box.
+
|| Cursor on '''Distance Matrix''' dialog-box.
||'''Distance Matrix''' dialogue-box opens.
+
||'''Distance Matrix''' dialog-box opens.
  
 
Please read the description about '''Distance matrix''' on the right-panel.
 
Please read the description about '''Distance matrix''' on the right-panel.
Line 210: Line 212:
  
 
Select '''NAME''' as '''Input unique ID field '''
 
Select '''NAME''' as '''Input unique ID field '''
 
  
 
||By default '''Parameters '''tab opens on the screen.
 
||By default '''Parameters '''tab opens on the screen.
Line 245: Line 246:
 
||Click on the 3 dots button next to '''Distance Matrix''' field.
 
||Click on the 3 dots button next to '''Distance Matrix''' field.
  
From the drop-down menu, select '''Save to file..''' option.
+
From the drop-down menu, select '''Save to file'''. option.
  
 
|-
 
|-
Line 255: Line 256:
 
||In the dialog-box, give an appropriate name and location.  
 
||In the dialog-box, give an appropriate name and location.  
  
Choose''' Files of type''', as''' csv '''.
+
Choose''' Files of type''', as''' CSV '''.
  
 
In the '''Encoding''' field choose '''System'''.  
 
In the '''Encoding''' field choose '''System'''.  
Line 266: Line 267:
 
Check the check-box for '''Open output file after running the algorithm'''.
 
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.
+
Click on the '''Run '''button at the bottom-right corner of the dialog box.
 
||In the '''Distance matrix''' dialog-box check the check-box for the following.
 
||In the '''Distance matrix''' dialog-box check the check-box for the following.
  
 
'''Open output file after running the algorithm'''.
 
'''Open output file after running the algorithm'''.
  
Click on the '''Run '''button at the bottom-right corner of the dialogue box.
+
Click on the '''Run '''button at the bottom-right corner of the dialog box.
  
 
The process will take few seconds.
 
The process will take few seconds.
Line 283: Line 284:
  
 
Click on the '''open attribute layer.'''
 
Click on the '''open attribute layer.'''
||Open the attribute table for '''Distance matrix''' layer.  
+
||Open the '''attribute table''' for '''Distance matrix''' layer.  
  
 
|-
 
|-
|| Cursor on the columns of attribute tables.
+
|| Cursor on the columns of '''attribute tables'''.
||In the attribute table there are three columns.
+
||In the '''attribute table''' there are three columns.
  
 
The last column is the distance between the volcano and nearest city.  
 
The last column is the distance between the volcano and nearest city.  
Line 296: Line 297:
  
 
|-
 
|-
|| Cursor on the attribute table.
+
|| Cursor on the '''attribute table'''.
 
||Depending on the '''CRS''', the distance can also be in '''layer units''' or in '''degrees'''.
 
||Depending on the '''CRS''', the distance can also be in '''layer units''' or in '''degrees'''.
  
Line 310: Line 311:
 
We will run a '''nearest neighbour analysis''' to analyze the distribution of features.
 
We will run a '''nearest neighbour analysis''' to analyze the distribution of features.
  
The results will establish the distribution as clustered, dispersed or random.
+
The results will establish, the distribution as clustered, dispersed or random.
 
+
|-
Close the attribute table.
+
|| Click on x icon at the top.
 +
||Close the '''attribute table'''.
  
 
|-
 
|-
Line 326: Line 328:
 
Scroll down and click on the '''Analysis Tools'''.
 
Scroll down and click on the '''Analysis Tools'''.
  
From the sub-menu, Select the '''Nearest Neighbour analysis'''.
+
From the sub-menu, select the '''Nearest Neighbour analysis'''.
  
 
|-
 
|-
Line 334: Line 336:
 
||'''Nearest Neighbour Analysis''' dialog-box opens.
 
||'''Nearest Neighbour Analysis''' dialog-box opens.
  
Read the information given about '''Nearest Neighbour analysis''' on the right-panel.
+
Read the information given about '''Nearest neighbour analysis''' on the right-panel.
  
 
Select '''Volcanoes''' layer in the '''Points''' drop-down.
 
Select '''Volcanoes''' layer in the '''Points''' drop-down.
Line 358: Line 360:
 
'''Number of point features''' and
 
'''Number of point features''' and
  
'''Z-score'''.
+
'''Z-Score'''.
 
|-
 
|-
 
|| '''Slide Number 8'''
 
|| '''Slide Number 8'''
Line 375: Line 377:
 
If the index is less than 1, the pattern exhibits clustering.
 
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 is greater than 1, the trend is towards dispersion or competition.
 
||If the index value is less than 1, the pattern exhibits clustering.
 
||If the index value is less than 1, the pattern exhibits clustering.
  
Line 384: Line 386:
 
||Here the '''Nearest Neighbor Index''' value of 0.2 indicates clustering.
 
||Here the '''Nearest Neighbor Index''' value of 0.2 indicates clustering.
  
Which means the volcanoes are located close to each other.
+
Which means, the volcanoes are located close to each other.
  
Similarly a negative Z-score also indicates clustering of point features.
+
Similarly a negative '''Z-Score''' also indicates clustering of point features.
  
 
|-
 
|-
Line 400: Line 402:
  
 
'''Summary'''
 
'''Summary'''
||Let us summarize. In this tutorial we have learnt about,
+
||Let us summarize.  
 +
 
 +
In this tutorial we have learnt about,
  
 
* '''Nearest Neighbour Analysis''' by '''Distance Matrix''' method.
 
* '''Nearest Neighbour Analysis''' by '''Distance Matrix''' method.
Line 413: Line 417:
  
 
Hint: Use '''Urban Areas''' as Input and '''K''' as 5.
 
Hint: Use '''Urban Areas''' as Input and '''K''' as 5.
 
  
 
|-
 
|-
Line 439: Line 442:
 
'''Spoken Tutorial Forum'''
 
'''Spoken Tutorial Forum'''
 
||Please post your timed queries in this forum.
 
||Please post your timed queries in this forum.
 
  
 
|-
 
|-

Latest revision as of 16:25, 28 October 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.

Right-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 dialog-box. Distance Matrix dialog-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 dialog 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 dialog 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.

Click on x icon at the top. 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 towards 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 team 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.

Thank you for joining.

Contributors and Content Editors

Karwanjehimanshi95, Madhurig, PoojaMoolya, Snehalathak