I would like to know how can I create a GRID layer with customized labels as you can see in the image below:

enter image description here

I have searched this topic here:

  1. Creating indexed vector grid in QGIS?
  2. QGIS Python Plugins Repository
  3. Create a grid with all polygons labelled - Index style

I did not found a clear idea, first of all I activate the Experimental plugins to install "Create Indexed Vector Grid" plugins but it does not appears.

I went to the repository to understand it but when I add the repository it gives this error:

enter image description here

A part from this I used 2 different ways off creating:

  1. Vector > Research Tools > Create GRID...

    enter image description here

  2. MMQGIS > Create > Create GRID Layer...

    enter image description here

As you can see the result it the same.

How can I do this?

I´m using QGIS 3.6


1 Answer 1


You can generate these IDs using a virtual layer

Run the grid tool as you currently do.

Go the the menu layer / add layer / add-edit virtual layer and enter the following query.

select *, char(r+64) || ROW_NUMBER() OVER(PARTITION BY r) as newID 
from (
  SELECT *,DENSE_RANK() OVER (ORDER BY round( ST_minY(geometry)/0.02) desc) as r 
  FROM Grid
  ORDER BY round(ST_minY(geometry)/0.02)  DESC,
           round( ST_minX(geometry)/0.02)  ASC

you can replace the layer name (Grid) with the true name. If you don't want to have the old id field and the new newID field, replace * by the list of field name from Grid you want.

The idea would be to order the row by Y, then to compute the dense_rank according to this 1st sort (i.e. all rows having the same value gets the same rank) to get the row number, then to generate a new cell number for each row and at last to convert the row number to a letter.

Let's note that it is highly probable that the X and Y coordinates should not be used directly, but rather with a small tolerance (that is, 2 points that are a micro-meter away from each other should be considered the same). Even if the points where created by a script, the storage model (floating point) could add noise to the coordinates.

In the query above, I have used a tolerance of 0.02 degrees. You will have to adjust this value for your data.

enter image description here

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.