QGIS Atlas – How to Use Two Dynamic Maps with QGIS Atlas

atlasqgis

I have some different routes with different POIs, and I want to show these POIs in a detailed map and also the position of the POIs in the route, showing all the routes.

enter image description here

I have two layers, one layer with the routes (LineString), with attribute Id_Route, and another layer with POIs (Points) with attributes Id_Route, Id_POI and POI_Description.

I create a Map controlled by Atlas, and Atlas is controlled by Id_POI, that shows a detailed map of POI. I also create a map that shows all the route, and a star where the POI is in the route. This map is not controlled by Atlas because if I control by Atlas, the extent change when the POI change, and I always want the same zoom. If I fixed then all works fine because the complete route is showed. My problem is when I generate an atlas with all points, when the POI is from another route, the zoom/view does not change to the new route.

How I Control/Configure Map of POI

How I Control/Configure Map of Route

Any ideas?

Result with @Babel solution:

Result with @Babel solution

Result with control with atlas:

enter image description here

Result with buffered points:

Result with buffered points

Best Answer

I find a solution: control extent of map position (Route) by Expression String Builder.

enter image description here

For example for determining x_min extent I use this code:

x_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route'))))))

First I get value of Id_Route of current POI that is showing in atlas.

Id_Route = attribute(@atlas_feature,'Id_Route')

After that I search a feature (Route) in Routes that have this Id_Route.

Feature = get_feature( 'Routes','Id_Route',Id_Route)

After, I get geometry of this feature (Route).

Geometry = geometry(Feature)

Finally I get de x_min of the Geometry (Route).

x_min(Geometry)

For x_max,y_min and y_max, I do the same, but from Geometry(Route) I extract x_max,y_min and y_max

Whith this code I have a map just with route extension, but I want some pad arround the route (15%).

I find this page where is very well explained how to do:

https://techoverflow.net/2021/04/26/how-to-make-bounding-box-larger-by-a-percentage-in-python/

xmin -= 0.15 * (xmax - xmin)
xmax += 0.15 * (xmax - xmin)
ymin -= 0.15 * (ymax - ymin)
ymax += 0.15 * (ymax - ymin)

For all the position the code is for 15% of margin:

x_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route'))))-( 0.15 * (x_max(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) - x_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route'))))))

y_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) - (0.15 * (y_max(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) - y_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route'))))))

x_max(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) + (0.15 * (x_max(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) - x_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route'))))))

y_max(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) + (0.15 * (y_max(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route')))) - y_min(geometry( get_feature( 'Routes','Id_Route',attribute(@atlas_feature,'Id_Route'))))))
Related Question