10

I try to show a small resolution raster file in the QGIS Print Manager tool. I would like to show a small label with each cell value (position - circa middle of each cell).

How I can do it? Is there any plugin which can help me to accomplish this task?

My idea is to use gdal2xyz, load such file using CSV plugin and then save it as a vector file. Unfortunately it is much work, because I have many raster files.

Another idea is to use gdal2xyz.py, then ogr2ogr to save it as vector file.

Is there any way to batch this process? Is there any open-source program where I can do it much more easily?

7

There doesn't seem to be a plugin for or functionality in QGIS to label cells.

Using a converted vector file to label the centres of the cells is probably your best bet. The open-source statistics package R has a lot of excellent spatial tools and can batch or quickly process raster files to create shapefiles (vector/points).

library(maptools)
library(raster)

# Load the raster from a file
r <- raster("/workspace/TEMP/raster.asc")

# Convert to spatial points
p <- as(r, "SpatialPointsDataFrame")

# Save as a shapefile
writeSpatialShape(p, "/workspace/TEMP/raster_points")

The shapefile will have column with the raster values for each point. The points can then be loaded into QGIS, given a size of 0 and labelled appropriately; they appear in the centre of cells.

To go through, for example, all the TIF files in a directory:

for (file in dir("/workspace/TEMP/", pattern="*.tif")) { # list all .tif files
  r <- raster(file)
  p <- as(r, "SpatialPointsDataFrame")
  writeSpatialShape(p, substr(file, start = 1, stop = nchar(file) -4)) # substr() removes extension.
}
4

In case R is not available (or, want to do it within QGIS environment), there is now SAGA tool in the processing toolbox, Raster values to points to extract cell values.

We can label the output Shapes layer and overlay it with the original raster.

enter image description here

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.