jps services
  • Home Page
  • GIS Training Courses
    • QGIS Training Courses
    • ArcGIS Training Courses
    • MapInfo Pro Training Courses >
      • MapBasic Training Course
  • About
  • Blog

Using virtual layers in QGIS for spatial analysis

2/3/2019

0 Comments

 
If you need to analyse map data in order to find areas which intersect or points of interest within a boundary for example, then you have a need for spatial analysis.

QGIS uses the geographical elements within your layers to enable you to make more sense of your data. This principle is based on the fact that two vector layers can have some sort of relationship between their respective geometries: some points are within a polygon, a polygon has some lines crossing or two polygons overlap partially or totally.

Several functions such as buffers and SQL selections allow you to use the geographic elements of your layers in your analysis.

The SQL selection function within QGIS can be used to extract data from a layer which corresponds to certain criteria.
Geographic joins

Intersects: this geographic function compares data within two tables.

A point, line or polygon intersects another point, line or polygon when they have at least a node in common: a network crosses another network for example a road or a railway line.

The intersection means a geographical geometry touches or goes through another.

Contains and its reciprocal Within means geographical geometries are within another geometry.

A geometry A contains a geometry B when it contains the centroid of B.

When B is within A: for example a catchment area contains clients represented by point geometries.

Entirely within and its reciprocal Contains entire.

A geometry A is entirely within a geometry B when the group of nodes of A are within B.

According to the type of the compared geometry, according to needs, depends on which of these operators are chosen.

Generally, use the Intersects function to compare polygons or from polygons to lines. ​
​
Use Contains/Within to compare points within polygons.

Spatial analysis example

After having created some areas of interest, let’s analyse the impact of these areas. As a starting point look at those areas which intersect with the buffers PA1 to PA7.
Picture
Here we have opened a project containing three layers. The population information is stored in a layer called Ilots_Saumur within a field called PSDC99. We can use the virtual layers function to find those areas which intersect with the buffer zones.. We can also find the sum of the populations for the areas which intersect the buffers. Additionally, we can create a geographic join by using the Intersects option. Prior to the introduction of the virtual layers function the individual layers in this project would have had to have been converted into a relational database format such as PostGIS or Oracle Spatial in order to access the SQL functionality needed.
​
To access the virtual layers function open the DB Manager from the top menu.

Picture
Click on the > icon next to the Virtual Layers option.
Picture
Next click on the icon > next to the Project layers option
Picture


The dialogue box in the Info section states that Project layers: Not connected.

In the Providers section double click on the Project layers option.

The various layers are now displayed

Click on the Ilots_Saumur option and view the Info, Table and Preview tabs​

Picture
From the top menu click on Database and choose the SQL window option
Picture
When the dialogue box appears click on the SQL query builder icon which is just below the Info tab
Picture
​In the Tables drop down list choose the Ilots_Saumur and Buffer_Stop_Points tables
Picture
Click in the Columns section and from the Columns drop down list choose

Ilots_Saumur.PSDC99

Buffer_Stop_Points.ID_PA

Ilots_Saumur.geometry​

Buffer_Stop_Points.geometry
Picture
Click within the Where section and select ST_Intersects from the Functions drop down list
Picture
Choose Ilots_Saumur.geometry from the Columns section ​
Picture
Put a comma after this entry

Then choose Buffer_Stop_Points.geometry and add a closing bracket​

Click in the Group by section and choose Buffer_Stop_Points.ID_PA from the Columns drop down list as in the following screen shot
Picture
Click on the OK button​

Click on the Execute button or Ctrl + R
Picture
Select Load as new layer by ticking in the box

The Co-ordinate Reference System dialogue box appears. Click OK to accept the default co-ordinate system​

Picture
Name the layer as “Population data where buffer intersects” in the Layer Name section​

The layer is loaded into QGIS
Picture
If you wanted the find the population data for the areas which intersect the seven buffers we could modify the SQL as follows
Picture
This will create a new layer similar to the previous one but with a different attribute table as shown below.
Picture
With virtual layers you can create more complex SQL statements than is possible with the QGIS field calculator.  Now it is possible to use ESRI shape and MapInfo mif files to create SQL statements previously only feasible with  PostGIS, MySQL and Oracle Spatial formats.
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    Joe Short BSc has been involved with various mapping solutions for over twenty years.  If you are considering implementing a GIS  or have ArcGIS Pro, MapInfo Pro or QGIS training requirements, jps services would be happy to be of assistance to your organisation. 

    Archives

    April 2020
    March 2020
    October 2019
    September 2019
    August 2019
    July 2019
    March 2019
    November 2018
    October 2018
    August 2018
    July 2018
    November 2017
    October 2017
    September 2017
    July 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    May 2016
    February 2016
    September 2015
    August 2015
    April 2015
    February 2015
    November 2014
    October 2014
    July 2014
    June 2014
    May 2014
    March 2014
    February 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    June 2013
    May 2013
    April 2013
    February 2013
    December 2012
    October 2012
    September 2012
    August 2012
    July 2012

    Categories

    All
    Arc Gis
    Arcview
    Autodesk
    Cad
    Gis Training
    Local Government
    Mapbasic
    Mapinfo
    Quantum Gis
    Relational Databases
    Saga Gis

    RSS Feed