Displaying generated lines out of map extent using QGIS?

Found the following work-around: Use a additional virtual layer instead of a geometry generator to display the lines.

Definition of the virtual layer:

select m.FID, make_line(.....) as geometry from my_layer m

(original geometry can be referenced using m.geometry)

To assure the virtual layer refreshes when my_layer is edited, go to layer properties | dependencies and make sure my_layer is checked (which is greyed out by default).


The problem here is that there's no actual data saying "there's a line here". Your expression is part of the Layer Styling, and is only encountered in the rendering process when two applicable points are also being rendered.

Try using the Distance to nearest hub tool, found in the processing toolbox under Vector analysis tools. I note that you're selecting particular polygons for your spokes, and styling the lines according to other attributes. This is possible, but you'll need to do a few things to prep for it. Thankfully, the tool automatically uses centroids when polygon inputs are chosen.

  1. Vector selections tools > Extract by attribute
    • Input layer: 'LAYER_1'
    • Selection attribute: 'ATTRIBUTE_1'
    • Operator: =
    • Value: 'value referring to hub polygon'
    • Extracted (attribute): 'HUB'

  2. Vector selections tools > Extract by attribute
    • Input layer: 'LAYER_1'
    • Selection attribute: 'ATTRIBUTE_2'
    • Operator: chosen as needed
    • Value: 'value(s) referring to spoke polygons'
    • Extracted (attribute): 'SPOKES'

  3. Vector analysis tools > Distance to nearest hub
    • Source points layer: 'SPOKES'
    • Destination hubs layer: 'HUB'
    • Hub layer name attribute: creates a "Hub Name" field in the output based on the attribute chosen, in case multiple hubs are specified in input layer
    • Output shape type: Line to hub
    • Measurement unit: Meters
    • Hub distance: 'OUTPUT_LAYER_NAME'

The resulting output retains all attributes of the 'SPOKES' layer input, so attributes needed for line styling will still be present. As its own vector layer, the lines will remain visible at all zoom levels, regardless of the visibility of either endpoint.

If you're comfortable with the Graphical Modeler, you might even build these steps into a single process so as not to clutter your workspace with unnecessary layers.