Is there a tool in QGIS that will extract the row and column numbers of a raster at a set of points? All I have been able to find is the following:

  • Raster Analysis > Sample raster values
  • (Plugin) Point Sampling Tool
  • GRASS > Vector > v.sample

None of these return the row & column number of the point, as far as I have been able to tell.

I also found this question, but it is rather in-depth and I was hoping to find a tool which could do it automatically if possible.

  • The column number is going to be the X coordinate of the point minus the X coordinate of the left of the raster divided by the cell size, rounded to an integer. You can get the extent and hence the min X of a raster in the expression editor via layer_properties(layername, 'extent') but I can't yet see how to get the cell size or the number of columns... – Spacedman Jun 22 '19 at 10:49
  • 1
    Maybe this answer to a similar question can help you: gis.stackexchange.com/questions/261504/… – pan Jun 22 '19 at 15:43

One way to do this is with the gdallocationinfo utility:

micha@TP480:GTOPO30$ gdallocationinfo -geoloc gt30e020n40.tif 31 29
  Location: (1320P,1320L)
  Band 1:
    Value: 15

You enter the X-Y the -geoloc parameter, and X-Y coords at the end, and it returns the Pixel and Line numbers (together with the value at that pixel)

| improve this answer | |
  • Seems to work but I am kind of surprised that QGIS does not do this automatically, I would think it would be quite useful to have it as a built-in feature, perhaps as a derived output from the identify tool, or as an optional output in the "Sample raster values" tool. – wfgeo Jun 23 '19 at 11:36
  • Since QGIS is a GIS application, and everything is done in the georeferenced space, the row and column numbers are not usually important. So I'm not surprised. The lower level tools, such as GDAL, that deal directly with the image do access the row and column numbers. – Micha Jun 23 '19 at 12:32

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.