1

I want to draw a point in the lower left corner of the QGIS map window (canvas). I tried the geometry genarator in the layer attributes:

point_n(@map_extent, 1)

This works, but I want the point really to be in the corner and not just the symbol. I need this, because I want to be able to klick on the point to select it.

I tried to write the map extend coordinates in an virtual attribut field (x and y) to catch them with a Virtual Layer and this query:

Select id, make_point(x, y, 31256) as geometry FROM Koordinaten

Unfortunately this doesn't work. Has anyone an idea on how to solve this?

0

1 Answer 1

2

You can create a point geometry at the bottom left of the current map canvas that dynamically changes by first creating a virtual field with the coordinates of this point in any of your vector layers. Then you can access these coordinates a virtual layer query to create the point.

  1. Inside field calculator (to create coordinates), the variable @map_extent from QGIS expressions is not available. So you have to create a custom function for the task to create the map canvas extent, see here how: https://gis.stackexchange.com/a/411313/88814 (thanks @katagena for the hint in the comment to this post).

    Then create two fields canvx for the x-coordinate with x_min(currentExtent()) and do the same for canvy with y_min(currentExtent()).

  2. New create a virtual layer with this query and replace my_layer with the name of the layer that contains the attributes canvx and canvy:

     SELECT MakePoint (p.x , p.y) FROM color as p where p.id=1;
    

    The where p.id=1 part is optional, but is to avoid creating one and the same point at the bottom left separately for each feature in your layer. Change the id=1 part so that it fits your data.

4
  • I need the point to be changed dynamically when the map extend changes.
    – MarinT
    Commented Aug 28, 2022 at 6:09
  • Thank you Babel!
    – MarinT
    Commented Aug 28, 2022 at 18:54
  • You can skip extracting the coordinates, and directly create a virtual layer with the expression SELECT MakePoint (xmin(currentExtent()) , ymin(currentExtent()))
    – JGH
    Commented Aug 29, 2022 at 14:15
  • Thanks for the hint. I had in mind that QGIS expressions can be use in Virtual Layer queries, but was not sure if all or just some expressions.
    – Babel
    Commented Aug 29, 2022 at 14:32

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.