QGIS Tutorials

Semi-Automated Mapping with QGIS Atlas Panel

Credit: Youtube Channel “Statistics Canada”


analysisWe need to output an entire post about self mapping using QGIS Atlas Panel, wrote special as GIS specialist. We need to use HTML tags. Must remove title at beginning (no header). Remove all comments. So no
  • Maintain consistency in scale, projection, and labeling.
  • Embed dynamic elements such as legends, scale bars, and directional symbols.
  • Combine with Python or GIS automation tools for even more power.
  • Prerequisites

    Before you begin, make sure you have:

    • QGIS 3.x (the steps apply to the latest stable release)
    • A vector layer that defines map extents (Polygon or MultiPolygon)
    • A background raster or tiled map service if desired
    • At least one variable to be displayed or styled per feature (e.g., a land‑use code)

    Step‑by‑Step Setup

    1. Prepare Your Data

    1. Open QGIS and load the reference layer you want to drive the atlas. Ensure the layer has an ID field or any unique attribute you’ll reference later.
    2. If you need to split the layer into smaller polygons, use Vector → Geometry Tools → Dissolve and dissolve by your chosen attribute.

    2. Create a New Print Layout

    All atlas settings are configured in a Print Layout:

    1. Go to Project → New Print Layout and name the layout.
    2. Add a map item: Layout → Add Map, then drag a rectangle onto the canvas.
    3. Configure the map extent to the area you wish each atlas page to display. Typically, you set a fixed extent covering the maximum bounds, or leave it unfiltered and let Atlas handle it.
    4. Adjust scale, resolution (DPI), and frame drawings as needed.
    5. Insert other elements: title (Layout → Add Label), legend (Layout → Add Legend), scale bar, north arrow, etc.

    3. Enable Atlas

    1. Open the Atlas panel: View → Panels → Atlas.
    2. In the Atlas panel, select the reference layer as the source.
    3. Choose the Coverage layer—this is the layer whose features drive the atlas.
    4. Activate Enable Atlas. Atlas will now iterate over each feature.
    5. Optional: Set Read from layer to Visible features if you only want to process those currently displayed.

    4. Configure Map Item to Follow Atlas Extents

    To make the map item automatically adjust to each feature:

    1. Select the map item in the layout.
    2. In the Item Properties tab, under “Extent”, check Use Atlas coverage layer extent.
    3. Optional: define Map Scale or leave it dynamic. For consistent scale across atlases, set e.g. 1:5000.
    4. You can also add a buffer around each feature extent by adding a buffer expression in the extent setting.

    5. Add Dynamic Labels and Variables

    Atlas supports variables that can be inserted into labels, titles, and other layout elements:

    1. In the label you previously added for the title, click the Insert Variable button (small database icon).
    2. Select the field from the coverage layer, e.g., name or id. The label will now read dynamically for each map.
    3. Similarly, dynamic data can be placed in the legend or anywhere else using the Insert Variable feature.

    6. Auto‑Generate Legend Entries (Advanced)

    If you want each atlas map to show only the layers relevant to the current extent:

    1. In the legend item, right‑click and choose Rename layers to edit the labels if desired.
    2. Open Legend Item Settings and enable Only show visible layers.
    3. Under Legend Formatting, you can set Sort by and Filter conditions using expressions like array_contains($currentFeature, $map_layer_name).

    7. Test with Preview

    Once all components are in place, use the Preview Atlas button in the Atlas panel. This renders all pages in the layout, letting you verify:

    • Map extents"
    • Dynamic titles"
    • Legend content"
    • Overlays (e.g., shapefiles or vector markers)

    8. Export Atlas

    When you’re satisfied:

    1. Go to Layout → Export → Export Atlas as PDF.
    2. Set output folder, filename pattern (e.g., map_{atlas_id}.pdf).
    3. Choose Export style: Composite PDF (single file), Separate PDFs (individual files), or Image for each map.
    4. Click Export. QGIS will spool through each feature and create the corresponding map file.

    Enhancing Atlas with Python (PyQGIS)

    For users comfortable with scripting, PyQGIS can generate custom content before the Atlas runs or adjust map properties on the fly.

    Example Script: Auto‑Add Boundary Highlights

    This snippet highlights the Atlas feature boundary on each generated map.

    layer = QgsProject.instance().mapLayersByName('CoverageLayer')[0]
    canvas = iface.mapCanvas()
    crs = layer.crs()
    
    # Prepare an in-memory layer to hold the highlight geometry
    mem_layer = QgsVectorLayer("Polygon?crs={}".format(crs.authid()), "Highlight", "memory")
    pr = mem_layer.dataProvider()
    pr.addAttributes([QgsField("Name", QVariant.String)])
    mem_layer.updateFields()
    
    # Function to run per feature
    def add_boundary_to_map(context):
        feature = context.feature()
        geom = feature.geometry()
        attrs = [feature['name']]
        mem_layer.addFeature(QgsFeature(mem_layer.fields(), attrs, geom))
    
    # Connect to atlas rendering
    iface.mapCanvas().setStyle(QgsMapSettings.Style.Opaque)
    context = QgsPrintLayoutExporter.layoutContext()
    add_boundary_to_map(context)
    

    Insert the above code into Project → Properties → Python Console → Advanced → Execute Script to run before exporting.

    Tips & Tricks

    • Clip Maps to Polygon: Use the Clip Using option in the Map Item properties to trim the map outline to the feature shape.
    • Dynamic Legends: Switch the legend’s Group by field to isolate categories per map.
    • Quick Export: Use Project → Save as… → Web Map Service (WMS) to push the atlas pages to a remote map server automatically.
    • Integration with GitHub Actions: Commit your QGIS project and run qgisserver in a CI workflow to produce atlases on demand.

    FAQ

    QuestionAnswer
    Can Atlas work with raster layers?Atlas itself drives the layout, but you may need another vector layer to define extents. Raster layers can be added as background in the map item; their visibility is controlled via the map item’s Item Properties panel.
    How do I set a different scale for each map?Use an Atlas Variable to calculate the desired scale in the map item’s Scale field, e.g., if($area < 10000, 1:5000, 1:10000).
    Is it possible to preview the atlas in the main QGIS window?No. Atlas only renders within the Print Layout. Use the Preview button in the Atlas panel.
    How can I export a PDF that contains an index page linking to each map?Create a separate layout for the index, then include bookmarks using Atlas variables (e.g., {atlas_id}) to link each PDF page.
    Can I use Atlas to create maps for a GIS mobile application?Yes. Export the atlas as GeoPackage or MPK files, then load them into QGIS for Android or create a Mapbox style for mobile use.

    With the basics covered, you can now tailor the atlas for more specialized scenarios—temporal overview maps, choropleth distributions, or even thematic tours. Experiment, iterate, and let QGIS Atlas turn your data into cartographic storytelling with minimal manual effort.

    Similar Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *