1

I'm trying to extract rows and columns from a raster to points, as the Value Tool plugin shows:

enter image description here

It's a pity that the raster to points tool only records the value of cells and not the raster cell coordinates. Even trying other tools from GRASS and SAGA, none of them is capable of extracting such information.

Searching for questions on this topic, I saw no immediate solution. Only this thread proposes a python script to do something similar, but it only extracts rows and columns from mouse clicks in specific positions. Furthermore, I'm not sure a script is batchable.

Since other threads I saw were with no answer or quite updated, is there a tool/plugin that can work for this operation to date?

NorthSon
  • 339
  • 1
  • 7
  • 1
    Export your raster to XYZ format, the result will be a text file with the X, Y and Z values where Z is the cell value. The X, Y values are in georeferenced coordinates which can be converted to row and column by loading the XYZ as a text file point feature class (add delimited text layer) then use the offset and cell size of the raster to calculate the row and column; you might need to save the points to a shapefile first, I can't remember if QGIS will let you add new fields on a delimited text layer. – Michael Stimson Feb 15 '23 at 03:39
  • @MichaelStimson thank you for the answer. This is a good start, however, as far as I know, the "add delimited text layer" is not batchable, this makes this solution quite time-consuming because I have hundreds of layers to process. – NorthSon Feb 15 '23 at 17:35
  • You could try it in modeler https://docs.qgis.org/2.8/en/docs/user_manual/processing/modeler.html if you don't know how to script in python. – Michael Stimson Feb 16 '23 at 00:17

1 Answers1

1

This is a trick, but it works.

  1. Make a copy of your image and remove the georeferencing from the copy with gdal_edit.

    gdal_edit -unsetgt source.tif

  2. Create a .tfw file (source.tfw for this example) that defines the pixel size into 1, and the location of the centre of the top-left pixel into (1,1). It is a text file with 6 rows:

1
0
0
1
1
1
  1. Convert TIFF into XYZ format

    gdal_translate -of xyz source.tif target.xyz

  2. Check the result. With my test image with size 1198, 645 and lots of zeroes in the data the beginnings of the two first rows are like here:

    1 1 0
    2 1 0
    3 1 0
    4 1 0
    5 1 0
    6 1 0
    ...
    1195 1 0
    1196 1 0
    1197 1 0
    1198 1 0
    1 2 0
    2 2 0
    3 2 0
    4 2 0
    5 2 0
    6 2 0
    ...

user30184
  • 65,331
  • 4
  • 65
  • 118