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

Modifying labels with QGIS 3

4/3/2019

0 Comments

 
If you have used previous versions of QGIS you may have noticed that most of the icons on the abc labelling feature were greyed out. In these earlier versions a number of steps had to be taken to enable a layer to access abc labelling features such as move, rotate and hide. For instance, fields had to be added to the layer’s attribute table for x and y coordinates for the move feature to work. Similarly a rotate field was needed for the rotation functionality. To hide labels required yet another field. Again these fields also had to be in the correct format. . Having created these fields correctly there were several more steps required to make the labelling function work. Each field had to be connected to the labels property function and then finally, if editing was enabled, the various features of the abc labelling application would become activated. Because of the amount of work involved, in getting these features to work for each individual layer, this functionality was mainly used by geographers who needed to place, move, rotate and hide layers where the standard features were insufficient. If you have previously used software such as MapInfo Pro you would have been surprised that manipulating labels required so many additional options. In MapInfo you can click on a label and move or rotate it without any of the previous steps mentioned. Once a label is moved in this way in MapInfo it is referred to as being personalised.    
With the advent of QGIS 3 the labelling functionality, which was previously only within proprietary software, is now available to open source geographers.   
Here, I have opened a project in QGIS 3 containing layers from the Alaska data set which is available for download with the latest versions of QGIS. As you can see I have moved the Label Toolbar to the map section on this occasion for clarity purposes. Normally it would be positioned on the top menu.
Picture
In this screen shot of the Label Toolbar only one of the icons is currently enabled. In earlier versions of QGIS, as previously discussed, most of these icons would stay greyed out without a lot of extra work being involved. However, if we now click on the regions layer in the Layers panel all of the icons will be enabled as shown in the next screen shot.
Picture
Clicking on the abc icon brings up the Layer Styling dialogue panel. As we have selected a layer with labelling enabled we have a number of options available.   
Picture
If we switch to another layer such as airports we no longer have any features enabled as shown in the next screen shot. You can do this either by selecting airports from the drop down section of Layer Styling dialogue panel or by switching from the regions to the airports layer in the Layers panel.
Picture
To create labels on a layer first you need to select the Show labels for this layer option from the drop down list as shown in the next screen shot. Then select an attribute from the layer’s attribute table to label the map with.
Picture
 On the Label Toolbar there are six buttons for modifying labels. Starting from the left is the Highlight Pinned Labels function which will show those labels which have been modified in some way. The cursor appears as a cross on the map when the Label Toolbar is activated.
Picture
Similarly the Pin/Unpin Labels function will enable labels to be modified as well as reverted to their previous state.
Picture
If you want to hide a label first click on the Show/Hide Labels function as shown in the next screen shot.  
Picture
 Placing the cursor over a label as in the next screen shot. The cursor is represented by a cross.
Picture
 Pressing the Shift key together with a mouse click will hide the label as shown in the next screen shot.
Picture
To hide several layers follow the above process but create a rectangle around the labels you wish to hide. Similarly, to show labels either click or create a rectangle around the area where the labels are hidden.

The Move Label and Diagram icon enables labels to be moved as necessary. In the next screen shot I have clicked on the Northwest Arctic label and moved it to the left.  
Picture
 Once in the desired position letting go of the mouse button will place the label in the new position.
Picture
Enabling the Rotate Label and clicking and holding down the mouse whilst rotating as desired will reposition the label.
Picture
​ Here we have clicked on label and rotated it 24 degrees.
Picture
 Once the mouse is released the label will stay in its new position as shown in the next screen shot.
Picture
The Change label option allows you to modify the look of individual labels. Click on a label and the Label Properties dialogue box for the label will appear as shown in the next screen shot.
Picture
 As you can see there are numerous options for personalising specific labels with this dialogue box. This option enables a label to have a variety of changes simultaneously rather than using the individual options to move, rotate or hide.

As mentioned earlier the improvements to the labelling functions in QGIS 3 makes modifying labels a much easier task than with earlier versions of QGIS.
0 Comments

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

    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