I have installed in QGIS Lat/Lon plugin which helps to calculate MGRS coordinates by default value in point layer form.

However, if I add a point in QFIELD in the same project, MGRS is not calculated by default and the field remains blank. I'm using this expression in QGIS default value field

mgsr($y, $x, 'ESPG:3857')

Is there possibility when I add a point in QFIELD, the MGRS coordinate is calculated immediately by default in field value, so that I can immediately display it on the point label.

1 Answer 1


Presumably the MGSR plugin uses python. Python scripts are not supported in QField.

But you could create your own grids (of square polygons). One for Grid Zone, one for 100km Grid Square. I do not know what size a Grid Zone is, but presumably you do not need to many of these.

To create your 100km Grid Square...

  1. Create a spatial bookmark for your area of interest. You want the extent of this bookmark to match the extent of the grid squares you are going to create, so the values should be multiples of 100,000 (otherwise the grid squares you generate below won't aling to multiples of 100,000)

  2. Go to Vector_Research Tools_Create Grid. Use Grid Type=Redctangle and set Horizontal and Vertical Spacing to 100,000m. Save Grid to a permanent layer and load on creation.

  3. Add attributes to your grid layer, and populate gribs with your Grid Square ID (I'm sure there are expressions that can automate this to a degree).

Similar for your Grid Zones.

On your point layer, create an attribute that is MGSR co-ordinate (or several attributes, e.g. "gridZone", "gridSquare", "gridCoordX", "gridCoordY". Assuming the latter (4 attributes) Set default of gridZone =

overlay_within(myGridZoneLayer, myGridZoneAttribute)[0]

(overlay_within returns an array. [0] returns the first value of that array, which should have only one member).

Set default of gridSquare =

overlay_within(myGridSquareLayer, myGridSquareAttribute)[0]

Set default of gridCoordX to:

$x % 100000

(The '%' symbol is a modulo operatot, and leaves the remained after dividing $x by 100,000).

Set default of gridCoordY to:

$y % 100000

You can then build your MGSR coordinate.

  • thanks for the good tip, I got the idea, but I want to get the coordinates with 1m accuracy and previous experience rendering overlay_intersects or overlay_within is resource intensive ... suddenly there are more ways
    – Rii Pii
    Commented Feb 12 at 18:04
  • Yes, get the last coordinates from your eastings or northings. Use a modulus function to strip down to the figures you need. Yes, overlay functions are resource intensive, but using it as a default value rather than calculated field means is runs on one feature at a time, on creation or update.
    – Oisin
    Commented Feb 12 at 22:43
  • What you mean "modulus function to strip down" ... can you give some good examples of expression?
    – Rii Pii
    Commented Feb 13 at 7:31
  • Hi Rii. See editied answer. '%' is a modulo operater. It returns the remainder or a division. So 5 % 2 = 1 and 600,453 % 100,000 = 453.
    – Oisin
    Commented Feb 13 at 11:36

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.