3

I have a QGIS (3.16) map layout (maps generated using Atlas) that I have created a map inset, which shows the full extent of the state. Within it, I have an "overview" frame that shows the actual location of the map on the overview. However, because the individual map is so small, the red overview square is nearly invisible at the statewide scale (in the overview).

How can I use a Geometry Generator to expand (maybe buffer?) the bounds of the map frame (red, map canvas) shown within the overview map? I don't want to change the actual map bounds (a rectangle), just the depiction of it within the overview map.

map overview(red)

Edit: After doing some experimenting, I've noticed that both Simple Fill and Centroid Fill are working, but Geometry Generator is not. So I've broken it down to the simplest possible object (the polygon centroid). Now I'm thinking I might just be having an issue with choosing the right "geometry variable" to use in the to Geometry Generator. I have tried $geometry, @atlas_geometry, and @map_extent, and even @map_extent_center, without success

Testing centroid Geometry Generator

2
  • 2
    Would you be open to using a centroid fill to approximately indicate the location of your overview? gis.stackexchange.com/questions/446399/…
    – she_weeds
    Commented Jan 28, 2023 at 10:45
  • @she_weeds This is a good suggestion, and I may just go this route if I can't figure out how to buffer the polygon map frame Commented Jan 30, 2023 at 18:20

3 Answers 3

2

You can achieve this using map themes. Define two themes, one for the main and the other for the inset map, the latter one showing the expanded (buffered) version of your feature's extent.

  1. In QGIS main window, create a buffer of your features large enough (maybe create a bounding box around the buffer to get a rectangle). You might simply duplicate the initial layer, but set it's style from Simple Fill to Geometry generator. Use the expression bounds(buffer ($geometry,10000)) and change the buffer distance.

  2. Then define two map themes (in the layer panel, click the eye icon > Add Theme and give it a name - see next screenshot):

    1. Showing only your features, without the buffer/bounding box. This is for the main map.

    2. Showing only the buffer/bounding box. This is for the overview/inset map.

    enter image description here

  3. Then go to the print composer and set the map theme defined before to the two map items. You can do this in the Item Properties > Layers section > check the box Follow Map Theme and select the appropriate theme.

    enter image description here

1
  • This is a really good idea and may end up going this route. I actually have 2 map themes, including one an "overview", like you described. I tested it and it will definitely work, although I'd really like to apply the geometry change within the print composer Commented Jan 30, 2023 at 18:23
2

You were almost there with @map_extent.

Using QGIS 3.28.1
scale(
    geometry:=map_get(item_variables('Map 1'), 'map_extent'),  -- change 'Map 1' according to the name of your linked map
    x_scale:=2,
    y_scale:=2
)

enter image description here

Where the blue rectangle is the original overview extent and the red is the expanded one.

Earlier versions of QGIS

For earlier versions of QGIS that lack the scale function, you can do something like the following to expand the extent:

with_variable('ext', map_get(item_variables('Map 1'), 'map_extent'),
    bounds(
        buffer(@ext, bounds_height(@ext)/2, 5)
    )
)

enter image description here

Or, for full control over the height and width:

with_variable('ext', map_get(item_variables('Map 1'), 'map_extent'),
    bounds(
        collect_geometries(
            project(centroid(@ext), bounds_width(@ext), radians(-90)),
            project(centroid(@ext), bounds_height(@ext), radians(0)),
            project(centroid(@ext), bounds_width(@ext), radians(90)),
            project(centroid(@ext), bounds_height(@ext), radians(180))
        )
    )
)

enter image description here

2

Thanks to the answer @Matt provided before, I was finally able to resolve the issue. Ultimately, my goal was to expand the size of the highlighted "Overview" frame within the Map Inset window, when the overview frame was going to be too difficult to see. I'm sure there are more sophisticated ways to get this working, but this gave me what I was after.

  1. I had to delete and recreate the "Overview" before the Geometry Generator actually started working. I'm guessing it had something to do a previous cache of the Map Canvas (speculation).
  2. I needed to use $geometry for my Overview feature shape, not @atlas_geometry.
  3. I needed to use single quotes (') instead of double-quotes (") throughout the code expression. Interestingly, QGIS kept inserting fields and variables with double-quotes.

Now for the code that worked:

with_variable( 
    'buf_factor',
    
    CASE
         WHEN to_int(attribute(@atlas_feature , 'mapscale')) = 15840 THEN 2.5
         WHEN to_int(attribute(@atlas_feature , 'mapscale')) = 31680 THEN 1.0
         WHEN to_int(attribute(@atlas_feature , 'mapscale')) = 47520 THEN 0.5
         WHEN to_int(attribute(@atlas_feature , 'mapscale')) = 63360 THEN 0.25
         ELSE 0.01
    END,
    
    bounds(
        buffer( $geometry, 
            bounds_width( $geometry ) * @buf_factor
        )
    )
)

Overview Properties Dialog

Result is a dynamically sized red box, based on the extent of the current feature in my Atlas output: Result overview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.