17.3. Creare un Output

Fig. 17.56 shows an example print layout including all the types of layout items described in the previous section.

../../../_images/print_composer_complete.png

Fig. 17.56 Layout di stampa con visualizzazione della mappa, legenda, immagine, barra di scala, coordinate, testo e cornice HTML aggiunti

Dal menu Layout o dalla barra degli strumenti, puoi stampare il layout di stampa in diversi formati di file, ed è possibile modificare la risoluzione (qualità di stampa) e le dimensioni della carta:

  • The filePrint Print icon allows you to print the layout to a connected printer or a PostScript file, depending on the installed printer drivers.

  • The saveMapAsImage Export as image icon exports the print layout image formats such as PNG, BMP, TIF, JPG, and many others…

  • L’icona saveAsSVG Esporta come SVG… salva il layout di stampa come SVG (Scalable Vector Graphic).

  • The saveAsPDF Export as PDF icon saves the defined print layout directly as a PDF (Portable Document Format) file.

17.3.1. Impostazioni per l’esportazione

Whenever you export a print layout, there are a selection of export settings QGIS needs to check in order to produce the most appropriate output. These configurations are:

17.3.2. Esportare in formato Immagine

To export a layout as an image:

  1. Click the saveMapAsImage Export as image icon

  2. Select the image format, the folder and filename (e.g. myill.png) to use. If the layout contains more than one page, each page will be exported to a file with the given filename with the page number appended (e.g. myill_2.png).

  3. In the next (Image Export Options) dialog:

    • You can override the print layout Export resolution and the exported page dimensions (as set in Layout panel).

    • Image rendering can also be improved with the Enable antialiasing option.

    • If you want to export your layout as a georeferenced image (e.g., to share with other projects), check the unchecked Generate world file option, and an ESRI World File with the same name as the exported image, but a different extension (.tfw for TIFF, .pnw for PNG, jgw for JPEG, …) will be created when exporting. This option can also be checked by default in the layout panel.

      Nota

      For multi-page output, only the page that contains the reference map will get a world file (assuming that the Generate world file option is checked).

    • Selezionando l’opzione ||checkbox| Taglia al Contenuto, l’immagine prodotta dal layout includerà l’area minima che racchiude tutti gli elementi (mappa, legenda, barra di scala, forme, etichetta, immagine….) di ogni pagina della composizione:

      • Se la composizione include una singola pagina, allora l’output viene ridimensionato per includere TUTTO nella composizione. La pagina può quindi essere ridotta o estesa a tutti gli oggetti a seconda della loro posizione (sopra, sopra, sotto, a sinistra o a destra della pagina).

      • Nel caso di un layout a più pagine, ogni pagina sarà ridimensionata per includere gli oggetti nella sua area (lati destro e sinistro per tutte le pagine, più in alto per la prima pagina e in basso per l’ultima pagina). Ogni pagina ridimensionata viene esportata in un file separato.

      The Crop to content dialog also lets you add margins around the cropped bounds.

../../../_images/image_export_options.png

Fig. 17.57 Opzioni di esportazione delle immagini, l’output viene ridimensionato alla estensione degli oggetti

Suggerimento

Utilizza formati immagine che supportano la trasparenza quando gli oggetti si estendono oltre l’estensione della carta

Layout items may be placed outside the paper extent. When exporting with the Crop to content option, the resulting image may therefore extend beyond the paper extent. Since the background outside of the paper extent will be transparent, for image formats that do not support transparency (e.g. BMP and JPG) the transparent background will be rendered as full black, «corrupting» the image. Use transparency-compatible formats (e.g. TIFF and PNG) in such cases.

Nota

When supported by the format (e.g. PNG) and the underlying Qt library, the exported image may include project metadata (author, title, date, description…)

17.3.3. Esportare in formato SVG

To export a layout as SVG:

  1. Click the saveAsSVG Export as SVG icon

  2. Fill in the path and filename (used as a base name for all the files in case of multi-page composition, as for image export)

  3. In the next SVG Export Options dialog, you can override the layout default export settings or configure new ones:

    • unchecked Export map layers as SVG groups: exported items are grouped within layers whose name matches the layer names from QGIS, making it much easier to understand the contents of the document.

    • unchecked Always export as vectors: some rendering options require items to be rasterized for a better rendering. Check this option to keep the objects as vectors with the risk that the appearance of the output file may not match the print layout preview (for more details, see Impostazioni per l’esportazione).

    • checkbox Esporta RDF metadata del documento come il titolo, l’autore, la data, la descrizione…

    • checkbox Simplify geometries to reduce output file size: this avoids exporting ALL geometry vertices, which can result in a ridiculously complex and large export file size that could fail to load in other applications. Geometries will be simplified while exporting the layout in order to remove any redundant vertices which are not discernably different at the export resolution (e.g. if the export resolution is 300 dpi, vertices that are less than 1/600 inch apart will be removed).

    • Set the Text export: controls whether text labels are exported as proper text objects (Always export texts as text objects) or as paths only (Always export texts as paths). If they are exported as text objects, they can be edited in external applications (e.g. Inkscape) as normal text. BUT the side effect is that the rendering quality is reduced, AND there are issues with rendering when certain text settings like buffers are in place. That’s why exporting as paths is recommended.

    • Apply checkbox Crop to content option

    • unchecked Disable tiled raster layer exports: When exporting files, QGIS uses a built-in raster layer tiled rendering that saves memory. Sometimes, this can cause visible «seams» in the rasters for generated files. Checking this option would fix that, at the cost of a higher memory usage during exports.

../../../_images/svg_export_options.png

Fig. 17.58 Opzioni esportazione SVG

Nota

Attualmente l’output SVG è molto scarno. Questo non è un problema QGIS, ma un problema con la libreria Qt sottostante. Questo sarà probabilmente risolto nelle versioni future.

17.3.4. Esportare in formato PDF

To export a layout as PDF:

  1. Click the saveAsPDF Export as PDF icon

  2. Fill in the path and filename: unlike for image and SVG export, all the pages in the layout are exported to a single PDF file.

  3. In the next PDF Export Options dialog, you can override the layout default export settings or configure new ones:

    • unchecked Always export as vectors: some rendering options require items to be rasterized for a better rendering. Check this option to keep the objects as vectors with the risk that the appearance of the output file may not match the print layout preview (for more details, see Impostazioni per l’esportazione).

    • checkbox Append georeference information

    • checkbox Esporta RDF metadata del documento come il titolo, l’autore, la data, la descrizione…

    • Imposta l” Esportazione testo: controlla se le etichette di testo vengono esportate come oggetti di testo propriamente detti (Esporta Sempre Testo come Oggetti Testo) o solo come percorsi (Esporta Sempre Testo come Percorso). Se vengono esportati come oggetti di testo, allora possono essere modificati in applicazioni esterne (p.e. Inkscape) come testo normale. MA l’effetto collaterale è che la qualità della restituzione risulta inferiore. E ci sono problemi con la restituzione quando certe impostazioni di testo come i buffer sono al loro posto. Questo è il motivo per cui si raccomanda di esportare come percorsi.

    • unchecked Create Geospatial PDF (GeoPDF): Generate a georeferenced PDF file (requires GDAL version 3 or later).

    • unchecked Disable tiled raster layer exports: When exporting files, QGIS uses tiled based rendering that saves memory. Sometimes, this can cause visible «seams» in the rasters for generated files. Checking this option would fix that, at the cost of a higher memory usage during exports.

    • checkbox Simplify geometries to reduce output file size: Geometries will be simplified while exporting the layout by removing vertices that are not discernably different at the export resolution (e.g. if the export resolution is 300 dpi, vertices that are less than 1/600 inch apart will be removed). This can reduce the size and complexity of the export file (very large files can fail to load in other applications).

../../../_images/pdf_export_options.png

Fig. 17.59 Opzioni esportazione PDF

Nota

Since QGIS 3.10, with GDAL 3, GeoPDF export is supported, and a number of GeoPDF specific options are available:

  • Format (GeoPDF format - there are some GeoPDF variations),

  • Include multiple map themes (specify map themes to include),

  • Include vector feature information (choose the layers and group them into logical PDF groups).

Nota

Exporting a print layout to formats that supports georeferencing (e.g. PDF and TIFF) creates a georeferenced output by default.

17.3.5. Generazione Atlante

Atlas functions allow you to create map books in an automated way. Atlas uses the features of a table or vector layer (Coverage layer) to create an output for each feature (atlas feature) in the table / layer. The most common usage is to zoom a map item to the current atlas feature. Further use cases include:

  • a map item showing, for another layer, only features that share the same attribute as the atlas feature or are within its geometry.

  • a label or HTML item whose text is replaced as features are iterated over

  • un oggetto tabella che mostra gli attributi degli oggetti associati parent or children all’oggetto corrente dell’atlante….

For each feature, the output is processed for all pages and items according to their exports settings.

Suggerimento

Usare le variabili per una maggiore flessibilità

QGIS provides a large panel of functions and variables, including atlas related ones, that you can use to manipulate the layout items, but also the symbology of the layers, according to atlas status. Combining these features gives you a lot of flexibility and helps you easily produce advanced maps.

To enable the generation of an atlas and access atlas parameters, refer to the Atlas panel. This panel contains the following (see figure_layout_atlas):

../../../_images/atlas_properties.png

Fig. 17.60 Pannello Atlante

  • checkbox Generate an atlas enables or disables atlas generation.

  • Configuration

    • A Coverage layer selectString combo box that allows you to choose the table or vector layer containing the features to iterate over.

    • An optional checkbox Hidden coverage layer that, if checked, will hide the coverage layer (but not the other layers) during the generation.

    • An optional Page name combo box to specify the name for the feature page(s). You can select a field of the coverage layer or set an expression. If this option is empty, QGIS will use an internal ID, according to the filter and/or the sort order applied to the layer.

    • An optional checkbox Filter with text area that allows you to specify an expression for filtering features from the coverage layer. If the expression is not empty, only features that evaluate to True will be processed.

    • An optional checkbox Sort by that allows you to sort features of the coverage layer (and the output), using a field of the coverage layer or an expression. The sort order (either ascending or descending) is set by the two-state Sort direction button that displays an up or a down arrow.

  • Output - this is where the output of the atlas can be configured:

    • An Output filename expression textbox that is used to generate a filename for each atlas feature. It is based on expressions. is meaningful only for rendering to multiple files.

    • A checkbox Single file export when possible that allows you to force the generation of a single file if this is possible with the chosen output format (PDF, for instance). If this field is checked, the value of the Output filename expression field is meaningless.

    • Un elenco a discesa Esporta Atlante per selezionare il formato di output quando si usa il tasto saveMapAsImage Esporta atlante come immagini…..

17.3.5.1. Mappa di controllo per atlante

The most common usage of atlas is with the map item, zooming to the current atlas feature, as iteration goes over the coverage layer. This behavior is set in the Controlled by atlas group properties of the map item. See Controllato da Atlante for different settings you can apply on the map item.

17.3.5.2. Personalizzare le etichette con un’espressione

In order to adapt labels to the feature the atlas iterates over, you can include expressions. Make sure that you place the expression part (including functions, fields or variables) between [% and %] (see L’Oggetto Etichetta for more details).

For example, for a city layer with fields CITY_NAME and ZIPCODE, you could insert this:

The area of [% concat( upper(CITY_NAME), ',', ZIPCODE, ' is ',
format_number($area/1000000, 2) ) %] km2

o, un’altra espressione:

The area of [% upper(CITY_NAME)%],[%ZIPCODE%] is
[%format_number($area/1000000,2) %] km2

The information [% concat( upper(CITY_NAME), ',', ZIPCODE, ' is ',  format_number($area/1000000, 2) ) %] is an expression used inside the label. Both expressions would result in the following type of label in the generated atlas:

The area of PARIS,75001 is 1.94 km2

17.3.5.3. Esplorare Sovrascrittura definita dai dati con atlante

There are several places where you can use a dataDefined Data defined override button to override the selected setting. This is particularly useful with atlas generation. See Impostazione Sovrascrittura definita dai dati for more details on this widget.

For the following examples the Regions layer of the QGIS sample dataset is used and selected as Coverage layer for the atlas generation. We assume that it is a single page layout containing a map item and a label item.

When the height (north-south) of a region extent is greater than its width (east-west), you should use Portrait instead of Landscape orientation to optimize the use of paper. With a dataDefined Data Defined Override button you can dynamically set the paper orientation.

Right-click on the page and select Page Properties to open the panel. We want to set the orientation dynamically, using an expression depending on the region geometry, so press the dataDefined button of field Orientation, select Edit… to open the Expression string builder dialog and enter the following expression:

CASE WHEN bounds_width(@atlas_geometry) > bounds_height(@atlas_geometry)
THEN 'Landscape' ELSE 'Portrait' END

Now if you preview the atlas, the paper orients itself automatically, but item placements may not be ideal. For each Region you need to reposition the location of the layout items as well. For the map item you can use the dataDefined button of its Width property to set it dynamic using the following expression:

@layout_pagewidth - 20

Likewise, use the dataDefined button of the Height property to provide the following expression to constrain map item size:

@layout_pageheight - 20

Per assicurarti che l’elemento della mappa sia centrato nella pagina, imposta il suo Punto di riferimento al pulsante di opzione in alto a sinistra e inserisci 10 per le sue posizioni X e Y.

Let’s add a title above the map in the center of the page. Select the label item and set the horizontal alignment to radioButtonOn Center. Next move the label to the right position, choose the middle button for the Reference point, and provide the following expression for field X:

@layout_pagewidth / 2

For all other layout items you can set the position in a similar way so they are correctly positioned both for portrait and landscape. You can also do more tweaks such as customizing the title with feature attributes (see Personalizzare le etichette con un’espressione example), changing images, resizing the number of legend columns number according to page orientation, …

The information provided here is an update of the excellent blog (in English and Portuguese) on the Data Defined Override options Multiple_format_map_series_using_QGIS_2.6 .

Questo è solo un esempio di come è possibile utilizzare alcune impostazioni avanzate con atlante.

17.3.5.4. Anteprima e generazione dell’atlante

../../../_images/atlas_preview.png

Fig. 17.61 Barra degli strumenti anteprima Atlante

Once the atlas settings have been configured, and layout items (map, table, image…) linked to it, you can create a preview of all the pages by choosing Atlas ▶ Preview Atlas or clicking the atlas Preview Atlas icon. You can then use the arrows to navigate through all the features:

  • atlasFirst Prima geometria

  • atlasPrev Geometria precedente

  • atlasNext Geometria successiva

  • atlasLast Ultima geometria

You can also use the combo box to select and preview a specific feature. The combo box shows atlas feature names according to the expression set in the atlas Page name option.

As for simple compositions, an atlas can be generated in different ways (see Creare un Output for more information - just use tools from the Atlas menu or toolbar instead of the Layout menu.

Ciò significa che puoi stampare direttamente le tue composizioni con Atlante ▶ Stampa Atlante. Puoi inoltre creare un PDF utilizzando Atlante ▶ Esporta Atlante come PDF.: ti verrà richiesta una directory per salvare tutti i file PDF generati, a meno che non sia stata selezionata la casella di controllo checkbox Esportazione file singolo se possibile. In questo caso, ti verrà richiesto di dare un nome al file.

With Atlas ▶ Export Atlas as Images… or Atlas ▶ Export Atlas as SVG… tool, you’re also prompted to select a folder. Each page of each atlas feature composition is exported to the image file format set in Atlas panel or to SVG.

Nota

With multi-page output, an atlas behaves like a layout in that only the page that contains the Impostazioni generali will get a world file (for each feature output).

Suggerimento

Stampare una specifica geometria dell’Atlante

Se vuoi stampare o esportare la composizione di una solo oggetto dell’atlante, è sufficiente avviare l’anteprima, selezionare l’oggetto desiderato nell’elenco a discesa e fare clic su Layout ▶ Stampa (oppure Esporta… in qualsiasi formato di file supportato).

17.3.5.5. Usare le relazioni definite nel progetto per la creazione dell’atlante

For users with HTML and Javascript knowledge it is possible to operate on GeoJSON objects and use project defined relations from the QGIS project. The difference between this approach and using expressions directly inserted into the HTML is that it gives you a full, unstructured GeoJSON feature to work with. This means that you can use existing Javascript libraries and functions that operate on GeoJSON feature representations.

Il codice seguente include tutte le feature figlie correlate dalla relazione definita. Utilizzando la funzione JavaScript setFeature ti permette di creare un HTML flessibile che rappresenta le relazioni in qualsiasi formato tu vuoi (liste, tabelle, ecc.). Nell’esempio di codice, creiamo un elenco dinamico delle feature figlio correlate.

// Declare the two HTML div elements we will use for the parent feature id
// and information about the children
<div id="parent"></div>
<div id="my_children"></div>

<script type="text/javascript">
   function setFeature(feature)
   {
     // Show the parent feature's identifier (using its "ID" field)
     document.getElementById('parent').innerHTML = feature.properties.ID;
     //clear the existing relation contents
     document.getElementById('my_children').innerHTML = '';
     feature.properties.my_relation.forEach(function(child_feature) {
     // for each related child feature, create a list element
     // with the feature's name (using its "NAME" field)
       var node = document.createElement("li");
       node.appendChild(document.createTextNode(child_feature.NAME));
       document.getElementById('my_children').appendChild(node);
     });
   }
</script>

During atlas creation there will be an iteration over the coverage layer containing the parent features. On each page, you will see a bullet list of the related child features following the parent’s identifier.