Set up an extraction using QGIS Server (atlas print layout)
Info
This tutorial uses the extraction plugin Impression Atlas QGIS Server which allows you to print out a QGIS project (e.g. in PDF) using a standard layout size (e.g. A4). Since the plugin uses a GetPrint request, the QGIS project must be hosted on a QGIS Server instance.
The QGIS Atlas tool allows you to use a fixed scale and a fixed layout size by using an additional vector layer containing a grid that will be used to divide your project in multiple files. Hence, when a client request your data, the plugin will intersect the desired perimeter with your grid and print out as many files as needed to cover the request's perimeter. Each file with the fixed layout size and scale.
To follow along with this tutorial, you can download the sample script and data available here. Either by cloning the repo :
git clone https://github.com/asit-asso/extraction-samples.git
Or downloading a ZIP archive with the following link : https://github.com/asit-asso/extraction-samples/archive/refs/heads/main.zip
Warning
This tutorial uses Docker and Docker compose to quickly get a running QGIS Server. Of course, you can use your own server.
Set up the QGIS Project :
-
In the downloaded folder, navigate to
qgis-atlas-server>qgis-server>dataand open up the QGIS projectsample.qgz. This project will be hosted on a QGIS Server and be used by the plugin.The project contains only 2 layers, the building footprints from swissTLMRegio and the
Divisionlayer. The latter is our grid layer used by the Atlas tool to divide our project in multiple outputted files. -
First, we need to create a print layout. In this example, there is already a print layout available (the
atlasLayoutthat you can open by going toProject>Layouts>atlasLayout). But you can create your own by going toProject>New Print Layout, give it a name and clickOk. -
In the print compose, you can add a map, legend, scale bar, some labels etc. You can also set up the map scale and layout size and resolution for export. In our
atlasLayoutexample, we set the map scale to 1:100'000 and the export resolution to 300 DPI and the layout size to A4 in landscape orientation. We've added a title and other labels and a scale bar. -
Once you have your layout ready, we need to generate an Atlas. Still in the print compose, go to the Altas tab and check
Generate an Atlas.Select the
Divisionlayer as theCoverage layer, it will set up this layer as the grid layer to export fixed page of our project.Make sur to check the option
Hidden coverage layer, it will hide thedivisionlayer in the outputted result.You can set up a name for each generated page under
Page name. In our example, we set it up toto_string( "left") + ' - ' + to_string( "bottom" ). It uses attributes from theDivisionlayer to give the bottom left corner coordinates as page name.Finally, we sort the
Divisionlayer by itsidattribute.
-
Once the Atlas configuration is set, we need to configure the map to use it. In the print compose, select your map item and go to the
Item Propertiestab and check the optionControlled by Atlas.
-
Now, we can test it out inside the print composer. Go to the
Atlas menuand click onPreview Atlas. You can now click on the left and right arrow to preview the different pages generated by the Atlas.
-
Go back to your QGIS project and make sure that the properties allow to generate more then 1 feature for Atlas print request. Go to
Project>Properties>QGIS Server>WMStab and underMap and Legend Options, adapt the number next toMaximum features for Atlas print request(e.g. 10).
-
Now that our print layout using the Altas tool is ready, we can publish our QGIS project in QGIS Server. If you have docker installed and running, you can simply do a
Docker compose upbeing at the root of theqgis-atlas-serverfolder.When all containers are running, we can test an export by calling the following URL in a browser :
http://127.0.0.1:8888/qgis-server?SERVICE=WMS&REQUEST=GetPrint&CRS=EPSG:2056&TEMPLATE=atlasLayout&FORMAT=pdf&ATLAS_PK=122,123,124,125This will export 4 PDF pages corresponding to the id
122,123,124and125of theDivisionlayer.
Connect the workspace to Extract
-
In Extract, create a new or use an existing process (see processes).
-
Drag and drop the task plugin
Impression Atlas QGIS Serverinto the process task list. -
In the field
Url de base QGIS Server, type the URL of your QGIS Server instance. In our example using Docker, you can typehttp://127.0.0.1:8888/qgis-server. In the fieldTemplate à utiliser pour le layout, you need to give the print layout name using the Atlas tool. In our example, this is thealtasLayout.
-
To test the extraction, you can link this process to viageo (see Connect Extract to viageo.ch). With our example, the linked resource can be orderable over the entire Switzerland. The format does not really matter and won't be read by Extract or QGIS. But the plugin will always export files in PDF. So, for clarity for the clients, the format must be set to PDF in viageo.ch.
-
Finally, you can order the linked product on viageo, Extract will retrieve the request and call the GetPrint request of your QGIS Server.