TransWikia.com

Link QGIS CSV / Excel with raster layers

Geographic Information Systems Asked on December 20, 2021

I have the following problem. I want to link a value from an Excel file to a raster layer. Uploading the Excel file and linking to other vector layers via properties -> linking is no problem.

However, the ID values ​​from the Excel file should be linked to the same ID values ​​from the grid layer in order to have a region number in the grid, depending on the ID values. Is there a simple tool for this or is it only possible via detours?

2 Answers

Linking an attribute table (such as an Excel file) to a raster is possible, but only if the raster is in integer form.

With integer rasters, the values for each cell are limited to, well, integers. This is in contrast to floating-point rasters, wherein cell values are represented with decimal numbers.

Since integer raster values are constrained to just integers, it becomes possible for such rasters to be designed with an internal attribute table (known as a raster VAT or a RAT, Raster Attribute Table). Such tables look and act just like the attribute tables found in vector data, including the presence of unique ID values. This means that external tables, such as your Excel file, can be linked to the raster. No need to polygonize your raster!

Unfortunately, QGIS does not yet support integer rasters*. However, there is a crowdfunding effort underway at Kartoza to implement integer raster support for QGIS. Send 'em a pledge!

See this link for more info on the difference between integer and floating-point rasters.

*To be specific, QGIS will load and display integers rasters, but the the raster's internal VAT will not be exposed.

Answered by Stu Smith on December 20, 2021

If I'm understanding the translation right, you have a raster layer whose values represent different categories. You want to link to additional attributes for each category in an Excel layer.

If this is it, one process is as follows:

  1. Save the Excel attribute table as a CSV file.

  2. Load the CSV file as a layer with no geometry using Add layer / Add delimited text layer

  3. Polygonize (under Raster / Conversion) your raster layer into a vector polygon layer. The raster values will be put into an attribute of this vector polygon layer, by default called DN but this can be changed.

  4. Open the layer properties of the vector polygon layer, and make a join to the CSV layer from step 2, linking DN from 3 to the category attribute in the CSV.

  5. You can now access the additional attributes originally from the Excel file for each polygon.

Note different settings on 4- vs 8- connectedness, and whether or not you dissolve, will effect exactly how the regions sharing the same raster value are grouped. You can also post-process the vector layer to split or join attributes, or measure their area, etc.

Answered by Houska on December 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP