1

I created grids (A1, A2....,B1,B2,...etc.) in print layout (main properties-grids). I also use atlas. I display many points and I need to calculate location of every point within a page of atlas and a grid. It is simple to calculate location of a point within a page atlas, because atlas is driven by a grid layer. I don´t know how to simply calculate location of a point within a grid. On a picture below black line is atlas grid frame (overlapping), red line are grids created at print layout

How can be it done? enter image description here

8
  • 2
    I suggest you add some images which show, what you are looking for, and tell us, where the calculation location should "go".
    – Erik
    Commented May 28, 2021 at 13:15
  • What exactly do you mean by "location of every point within a page of atlas and a grid"? Like A1, B3 etc.? Please also show how/where you create the black and red grid. And finally, as @Erik mentioned: where should the result be displayed or saved?
    – Babel
    Commented May 28, 2021 at 15:54
  • 1
    What do you want to do with the coordinates?
    – Erik
    Commented May 28, 2021 at 16:14
  • I created black grid as a vector grid (vector - research tools - vector grid). Red grid is created at print layout (map-main properties-grids). I mean to find out location of every point in A1, B2 etc. The result should be displayed at attribute table of a vector grid layer used for atlas. If a result is displayed elsewhere, I don´t mind.
    – pazelvak
    Commented May 31, 2021 at 7:09
  • I think you can not access to your gird created on your map in the layout to analyse with points. The only option you have is to create a real layer like you black one which would serve as location layer for your point. Is it fine for your use case ? Commented Jun 18, 2021 at 12:01

1 Answer 1

1

There is a solution but this need that your gird have always the same number of division of your final layout (always 5 division horizontal and 4 vertical). If you want to change it you only have to adapt the expression.

Principle

The goal is to calculate the position of the point in your layout based on the coordinate of your point and the map extent. For example : you have a point that have Y coordinate = 105. If your map max Y is 110 and min Y is 100 then your point will be in the center. If it is in the center then you should attribute the letter in the middle, if you go form A to E it should be C.

I assume you have 4 divisions in X with number from 1 to 4 and 5 division in Y with letter from A to E.

Expression

  1. Make sure the layer for your points is in the same CRS as you are using for your layout. In your layout name your map item Carte 1 or change the name in the expression.
  2. Add an attribute table with your point layer and set it to get only visible features.
  3. Add a column with the heading X and with the attribute based on the following expression :
with_variable( 'extent',
               map_get( item_variables( 'Carte 1' ), 'map_extent' ), 
               ceil(($x -x_min(@extent)) / bounds_width(@extent)*4)
)
  1. Add a column with the heading Y and with the attribute based on the following expression :
with_variable( 'extent',
               map_get( item_variables( 'Carte 1' ), 'map_extent' ), 
               char(64+ceil(($y -y_min(@extent)) / bounds_height(@extent)*5))
)

Result

enter image description here

Notes

The function with variable() define a temporary variable named extent to be used easier in the calculation.

The function ceil() permit to get 1 when we are between 0 and 1, 2 between 1 and 2.

The function char() is used to get letter based on asci code. If you do char(65) you get A, char (66) you get B. Combine with ceil it permit to get the letter you want based on number.

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.