This article completes the series of articles on creating a geopackage database to manage ENC nautical charts in QGis and the symbology of the various data layers. Working with a small number of maps presents no particular problems, but as soon as the number increases there is a series of operations that become either complicated or time-consuming.
We have developed a series of Python scripts that simplify work on large geopackage databases.
1- Loading layers
The first problem is the large number of layers to be loaded into the QGis project. While one map may have around twenty layers, as soon as the number of maps increases you can quickly find yourself with over a hundred layers to load.
QGis allows you to load all the layers in a geopackage en bloc. So you don’t have to load the hundred or so layers one by one. But once they are loaded, there are two tasks to perform:
- remove irrelevant layers such as metadata layers
- order the display of layers to prevent certain layers from being completely invisible due to overlapping with other layers. Surface layers such as DEPARE and LNDARE (depths and terrain) must always be below marine and terrestrial objects, otherwise these objects are not visible.
What’s more, it’s always more pleasant to work with minimum display scales, so that only certain layers are shown when zooming in at very small scales, and detailed information is only displayed when zooming in at larger scales.
Selecting layers to load
We have provided a python script that solves all these problems on its own. You can download it from this link.
The script includes a list of 210 S57 layers, ordered for correct display:
Surface layers represented by solid polygons, then surface layers represented by empty polygons (only the perimeters are displayed), then linear type layers and finally point type layers. Within each category, the order has been designed to avoid masking information.
Each layer is accompanied by a minimum display scale value, the default being 100000000.
Here’s an example:
#Liste des couches dans l’ordre de chargement
couches_a_charger = [
(‘pl_DEPARE’, 100000000),
(‘pl_UNSARE’, 100000000),
(‘pl_TIDEWY’, 100000000),
(‘pl_DAMCON’, 100000000),
(‘pl_CAUSWY’, 100000000),
(‘pl_HULKES’, 100000000),
(‘pl_LOKBSN’, 100000000),
(‘pl_OBSTRN’, 100000000),
(‘pl_PONTON’, 100000000),
(‘pl_PYLONS’, 100000000),
If you don’t want the script to load layers you’re not interested in, you can simply comment out the corresponding line by adding a ‘#’ at the beginning of the line:
#Liste des couches dans l’ordre de chargement
couches_a_charger = [
(‘pl_DEPARE’, 100000000),
(‘pl_UNSARE’, 100000000),
#(‘pl_TIDEWY’, 100000000),
#(‘pl_DAMCON’, 100000000),
In this example, the TIDEWY and DAMCON layers will not be loaded.
In addition, if you wish to define a minimum display scale for a layer, simply modify the corresponding value:
‘pl_DEPARE’, 100000000),
(‘pl_UNSARE’, 100000000),
(‘pl_TIDEWY’, 100000),
#(‘pl_DAMCON’, 100000000),
#(‘pl_CAUSWY’, 100000000),
(‘pl_HULKES’, 100000000),
(‘pl_LOKBSN’, 100000000),
(‘pl_OBSTRN’, 50000),
In this example, the TIDEWY layer will only be displayed when the map window zoom value is below 100000, and the OBSTRN layer when the value is below 50000.
To use the script:
- download the .py file,
- save it in a directory of your choice
- Open the QGis Python console (Extensions ->Python console)
- Open the Editor window (1)
- Click on the Browse icon (2) and point to the downloaded .py file
- Change the geopackage path to the path and name of your geopackage (3)
- Run the script (4)
Before running the script, you can make modifications to prevent layers from being loaded or to assign them a different minimum scale. Don’t forget to save these modifications before closing your project.
The script code is as follows:
Display scale management
The previous script is used to define a minimum scale when layers are first loaded into the project. When you save your project, the value in the layer’s Min_scale field is saved. When the project is opened, the display parameters at the time the project is closed are taken into account. You will therefore only use the previous script at the start of work on a project. However, the scales defined in the load_layers script may not be suitable for your work area. You may therefore need to modify the min scale values for certain layers.
We provide you with a Python script that allows you to define the minimum display scale for all layers selected in the Layers panel. Once your project has been saved, these settings will be used each time the project is opened.
To use it, first load it into the QGis Python console, select (highlight) the layers you wish to modify in the Layers panel, and, most importantly, modify the line
#Define minimum scale (for example, 1:50000)
min_scale = 250000
with the desired value for the minimum display scale.
The Python script for setting the minimum display scale for selected layers is as follows:
A Python script to filter layers by “purpose
The tables in your geopackage include an attribute called “purpose”, a value between 1 and 6 that corresponds to the map’s main objective:
- 1 : Overview
- 2 : General
- 3 : Coastal
- 4 : Approach
- 5 : Port
- 6: Docking
If you have maps with different purposes covering the same area, for example a General map and an Approach map, you will have duplicate information. If the entities on two maps are not of the same type (a surface entity on an Approach map will correspond to a point entity on the General map, for example), rendering can quickly become very messy. The proposed solution is simple
You can download the script here.
Load the script in the python console, modify the line:
#Define the value of the “purpose” attribute to be filtered
purpose_value = 5
with the desired purpose value, then run the script. All layers present in the project’s Layers panel will be filtered.
If you wish to remove all active filters from all layers in the project, the following script allows you to do so: