3

When creating a grid (e.g. dx=15,dy=20) in GQIS 3 the first cell begins from the upper left corner and continues to the bottom of the grid as shown in the picture below.

enter image description here

Is there any way to define the way that the id cells are located? Is there any plugin in QGIS? In fact, I want to begin from the lower left corner and continue to the east (as MapInfo does) as shown below.

enter image description here

4

You can create a new layer with the re-ordered ID

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 *, ROW_NUMBER() OVER(ORDER BY  ST_MinY(geometry) asc, ST_MinX(geometry) asc) as newID
FROM Grid

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 query gets all rows from the Grid layer, then order each polygon by Y and X and generate a new sequential row number.

enter image description here

  • I tried this in QGIS3 but it gives the following error: "Query execution error on CREATE TEMP VIEW _tview AS select * , ROW_NUMBER() OVER(ORDER BY ST_MinY(geometry) asc, ST_MinX(geometry) asc) as newID FROM Grid: 1 - near "(": syntax error". – nat Apr 3 at 11:44
  • 1
    @nat it works under 3.4.5 (LTR), which has spatialite 4.3 (help menu, about). The window function was introduced in spatialite 3.25 – JGH Apr 3 at 11:48
  • Thank you a lot! I installed 3.4.6(LTR) on a MAC OS and it worked. – nat Apr 3 at 13:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.