1

I have various point and polygon layers (shapefiles) which I use regularly in QGIS (3.6.3), and often need to work out their location as an 8 figure grid reference (British co-ordinates, EPSG-code 27700, same code used by each project). For polygons this means working out the central point of the shape (centroid?) first and then converting this to a grid ref.

At the moment I am using the FSC plugin tools, 'OSGR Tool' and 'Add GRs to Layers Tool' to do this, but this means I have to go through the process every time I have a new/edited feature which I need the info for.

I would prefer to be able to automatically generate the grid ref every time a point/polygon is added/edited, within the grid ref field of the existing layer (see below). Is this possible?

Attributes Table

I presume it could be done using the 'default value' option for the existing field, but I cannot work out what expression I would need to do this.

  • Is there a separate grid layer, or is the centroid a part of the polygons attributes? – Erik Jan 8 at 13:08
  • I'm probably getting my terminology muddled here - by centroid I mean the central point inherent in any polygon - there is currently no separate grid layer – JimS-W Jan 8 at 14:09
  • And what do you mean by "grid reference"? The coordinates of said centroid? – Erik Jan 8 at 14:19
  • 2
    Well, problem: geom_to_wkt(centroid($geometry)) gives you the coordinates of the centroid - but only as numeric values. I have no idea how to convert these to the characteristic grid letters, sorry. – Erik Jan 8 at 16:08
  • 1
    This post has some code for converting grid reference to eastings and northings, as well as links to some other references. One of the links might help figure out how to do it. Or the other solution would be to download the British grid as a layer, and use an expression that references that layer. – csk Jan 8 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.