Chapter 2: Data Management, Symbols, and Styles in QGIS

Part II C: Reusing Layer Styles

After we have customized our layer’s symbology and labels, there are a few ways in which we can reuse this styling. Reusing styles is useful for a couple of reasons. First, when we add a shapefile to QGIS, it will not show any symbology; we have to spend time designing its symbology. So, reusing our symbology allows us to quickly symbolize a newly added layer without having to spend time in the layer’s Properties menu. Second, a key point of cartography is honesty in presentation of map data. Cartographers strive to present their map data as honestly and accurately as possible. By reusing styles across a series of maps, a cartographer can provide the necessary consistency for telling an honest story with his or her maps.

For example, let’s say that we not only had a shapefile containing forestry data for PEI for 1935 but also shapefiles containing forestry data for PEI in 1955, 1975, and 1995. Provided that the shapefiles were all polygons and all had exactly the same headers in their attribute tables, we could apply the same Graduated symbology style we created for the 1935 layer to the others. All of the layers would thus have the same class breaks and colour scheme, making for easy and accurate comparisons across each of the time points. As a bonus, we could also copy our labels to the other layers.

Copying a Style

Since we do not have the hypothetical forestry layers mentioned above, let’s say that you would like to copy the styling that we created for the 1935 inventory region layer in this chapter’s project file to the same layer in Chapter 1’s project file. To quickly do so:

  • Make sure that both projects are open. That is, make sure that you have two different windows of QGIS open, one with Chapter 1’s project file and one with Chapter 2’s project file.
    • On Windows, one good way to open two instances of QGIS is to have one QGIS window open, right-click the QGIS button in the Taskbar, and then click QGIS Desktop. A second instance of QGIS will open, and you can click Project and then Open to open another project, such as Project1.
    • On a Mac, it is more difficult to have two projects open at once. However, you can still copy a layer and then open a different project (note that this will close your other project) and paste that layer into the Layers panel.
Figure 2.109. QGIS Desktop options.
Figure 2.109
  • In the QGIS window containing the project that features the layer whose style you would like to copy, right-click this layer and click Styles, and then Copy Styles, and then All Style Categories.
Figure 2.110. QGIS window containing the project that features the layer whose style you would like to copy, right-click this layer and click Styles, and then Copy Styles, and then All Style Categories.
Figure 2.110
  • In the QGIS window containing the project that features the layer onto which you would like to copy the style, right-click this layer and click Styles, and then Paste Style, and then All Style Categories.
Figure 2.111. This image shows the QGIS window with the 1935 inventory layer selected, with a pop-up where the second last option (Styles) is highlighted. From this first pop-up stems a second pop-up where the second option (Paste Style) is highlighted. The final pop-up that stems from the second has the first option (All Style Categories) selected.
Figure 2.111

Here is the result of the paste:

Figure 2.112. Updated map with the pasted layer results.
Figure 2.112
Note: when you copy and paste styles between layers in QGIS, it does not copy your filter settings.

 

Note: you can only copy and paste styles between layers in QGIS. It will not work between QGIS and another GIS application, such as ArcGIS Pro.

 

Note: if you copy a style, please note that you must apply the style to the same layer (perhaps in a different project file) or to a layer that has the same structure. A different layer of the same structure would be one that is of the same geometry type (i.e., points, lines, or polygons) and that has the same attribute that was originally used for symbolization.

Saving a Style

The process outlined above for copying a style is effective for times when you only need to copy a style once and quickly paste it onto another layer. However, if you wish to save your style permanently, you have a few options.

Saving a QGIS Style File (.qml)

A QGIS Style File (.qml) offers much of the same functionality as the process of copying and pasting symbology, but it allows you to permanently save this symbology instead of temporarily storing it on your clipboard. It also allows you to have a layer’s symbology load automatically when the layer is added to a project.

To save a QGIS Style File:

  • In the table of contents, right-click the layer whose style you would like to save.
  • Click Properties…
  • Click Information.
  • At the bottom of the Information window, click Style and then Save Style…
Figure 2.113. At the bottom of the Information window, Style is selected and a pop-up appears in which Save Style is selected.
Figure 2.113
  • Click Browse
Figure 2.114. This shows the Save Layer Style page. Under the save file information is the option to browse.
Figure 2.114
  • Navigate to the folder in which the layer from which we are saving the style (i.e., the original layer) is stored. In this case, navigate to the folder called Project1\Data\forest_35.SHP.
    • If you need a reminder as to its location, check the “Path” field in the Information window.
  • Next to File name, type in the name of the shapefile associated with this style file. We want the original shapefile and the QGIS Style File to have the same name.
    • Although the two files will have the same name, their extensions will differ. The shapefile will be called 1935 inventory_region.shp while its corresponding QGIS Style File will have the name 1935 inventory_region.qml.
  • Click Save

If you open a new project and add the 1935 inventory_region shapefile from the forest_35.SHP folder, it will be automatically symbolized according to the settings stored in the QGIS Style File that we just saved. This is done automatically because the shapefile and QGIS Style Files were stored in the same folder and were given the same name.

Here, we added the shapefile from the forest_35.SHP folder, and QGIS automatically loaded the corresponding QGIS Style File.

Figure 2.115. This is an updated map with the shapefile from the forest_35.SHP folder.
Figure 2.115
Note: your filter settings will not be stored in a QGIS Layer Style File.

 

If you do not save a shapefile and its corresponding QGIS Style File in the same location, QGIS will not automatically symbolize the shapefile. However, you can manually apply the QGIS Style File to the shapefile.

  • In the table of contents, right-click the layer to which you would like to apply the symbology.
  • Click Properties
  • Click Information
  • At the bottom of the window, click Load Style…
  • Click Browse
  • Navigate to the location where you saved your QGIS Style File and double-click it.
  • Click Load Style
Note: If you save a QGIS Layer Style File, please note that you must apply the style to the same layer (perhaps in a different project file) or to a layer that has the same structure. A different layer of the same structure would be one that is of the same geometry type (i.e., points, lines, or polygons) and that has the same attribute that was originally used for symbolization.

 

Saving a QGIS Layer Definition File (.qlr)

If you would like to create a new file that includes the shapefile and its symbolization, you can export the styled shapefile as a QGIS Layer Definition File (.qlr). When you add this file to a project, its style settings will automatically appear.

The key difference between a QGIS Layer Definition File and a QGIS Style File is that you can only use a Style File in conjunction with its corresponding shapefile. On the other hand, a Layer Definition File contains both the shapefile and its symbolization settings. QGIS treats it as a map layer unto itself.

To save a QGIS Layer Definition File,

  • In the table of contents, right-click the layer whose style you would like to save into a new QGIS Layer Definition File.
  • Click Export
  • Click Save as Layer Definition File…
Figure 2.116. This shows the 1935 inventory region file selected, in the pop-up from the file export is highlighted and from that another pop-up, in which Save as a Layer Definition File is highlighted.
Figure 2.116
  • Save the file in an appropriate location, perhaps in a folder alongside any other data you are using for a project.

To load a QGIS Layer Definition File,

  • Using the Browser pane, navigate to the location where you saved your QGIS Layer Definition File.
  • Double-click the QGIS Layer Definition File to load it into your project.

Here, we saved the 1935 inventory region shapefile that we symbolized earlier in the chapter as a QGIS Layer Definition File and then loaded it into a new, blank project. Note that the symbolization settings and our filter have been retained without having to replicate them manually.

Figure 2.117. This shows an updated map where only the 1935 inventory region shapefile is present.
Figure 2.117

Note also that the QGIS Layer Definition File has the same attributes as the original shapefile from which it was created. You can verify this by opening the QGIS Layer Definition File’s attribute table.

Note: a QGIS Layer Definition File can only be created and reused in QGIS. It cannot be added to another GIS application, such as ArcGIS Pro.

 

Watch for a future chapter on Creating and Sharing a GeoPackage for information on how to save styles within a GeoPackage.

 

 

 

License

The Geospatial Humanities Copyright © by Joshua MacFadyen; Benjamin Hoy; and Jim Clifford. All Rights Reserved.

Share This Book