I have a QGIS print layout with an atlas layer for which I would like the map extents to show the current atlas feature and a nearby point. The layer provider is postgis.
It seems the only way to do this is provide separately the xmin,xmax,ymin,ymax via expression to qgis. I've also discovered it behaves oddly if the aspect ratio of the bounding box is different than the map item so I need to account for that too.
What I've tried so far:
Get a bounding box from PostGIS scaled by 10% height
SELECT t.territory,
st_expand(t.bbox, ((st_ymax((t.bbox)) - st_ymin((t.bbox))) * (0.1))) AS geom
FROM
(SELECT
parcellayer.id,
st_envelope(st_union(parcellayer.geom,
(SELECT pointlayer.geom FROM pointlayer LIMIT 1))
) AS bbox
FROM parcellayer) t;
this gets me a box but I need to make sure it's the same aspect ratio (2:1) I can do a bunch of complicated case statements, but is there an easier way to go about this?