I generated a rectangular grid using the vector tools available and added a attribute in this grade (sum of lentghs of a line). Now I want to convert this rectangular grid to a matrix (if possible in a text, because I would put it in my thesis, so I wouldn't need to type cell by cell), in which the values of the cells would be that attribute. I couldn't find a tool in QGIS to do that. I'm using QGIS 3.8.3 Zanzibar. This is the grid that I have generated, I did set the style according to a attribute value.

This is the attribute table. I want to extract the values of the last column in a matrix form, in which the value of each cell would be the value of the attribute in that cell.

As suggested by Gabriel De Luca, I exported the vector in a CSV format and opened it in LibreOffice Calc. Now I'm closer to what I need. I have the column with 2500 rowns, but need to convert it to a 50x50 matrix.

  • What kind of file format do u expect to integrate these data in your thesis ?
    – Snaileater
    Oct 23, 2019 at 16:33
  • Any kind of text file that could be imported to Excel or Libreoffice Calc would be welcome. So I could apply some math on them to calculate variations between matrices.
    – CaD
    Oct 23, 2019 at 18:30
  • 2
    From what I understand, you only want the values of the last field of the table, but arranged in columns according to their longitude and in rows according to their latitude? Oct 24, 2019 at 3:51
  • 2
    You can Export the vector layer, Save As with CSV format, and load the .csv file in LibreOffice Calc, but the ordering I think you'll have to do there. Oct 24, 2019 at 4:00
  • 1
    Thats it Gabriel de Luca, I exported as a CSV and loaded it in Calc, now I wondering how I could handle this data to transform the column in a matrix
    – CaD
    Oct 24, 2019 at 22:05

1 Answer 1


As you can see, you can Export the attribute table as a CSV file in a simple way in QGIS. But the problem turns to sort the values in LibreOffice. That task slightly exceeds our reach.

But I kept thinking that there really must be a way to export the data exactly as you wish, which is in the form of an array. And what has an array shape is a raster, so it seems to me that the first thing we should do is rasterize those polygons.


Here I had some polygons created from another test I was doing. You will notice that they are the result of a polygonization, but it is not a problem, let's rasterize them again.

My polygons have a field called DM that contains the values that I want to burn in the pixels of a raster.

We do not want to go crazy with the coordinates and the resolution, so all we know is how many pixels the image should be wide by how many high (5x5 in my case), and we will ask the raster to assume the extent of the polygon layer (by pressing the three dots button in the Output Extent section, and choosing the Use Layer Extent option).


The result is a raster that we can export to GeoTIFF format. Rendering is not a problem, the important thing is to notice that the values of the DN field are burned in each pixel.


We can now use the gdal_translate command (https://gdal.org/programs/gdal_translate.html) to convert the GeoTIFF file to a format that is almost exactly what we are looking for, an ASCII grid (https://gdal.org/drivers/raster/aaigrid.html).

My way of doing this is to run the OSGeo4W console, navigate to the folder that has the rasterized file, and run the following command:

gdal_translate -of AAIGrid Rasterized.tiff Rasterized.csv

Now, it only remains to import it into LibreOffice Calc, separating cells delimited by space, and remove the rows from the header to have the values grid.


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.