4

I have a TIFF file that has 17 bands (colors). Each color corresponds to different land use land cover characteristics.

enter image description here

Additionally, I have a shapefile of a district with blocks. I want to find the area covered under all 17 colors in all blocks. I can use zonal statistics or r.report. But both of them work for a single district shapefile not for district shapefile with blocks. What can I try?

enter image description here

  • I think you mean to say that the tiff file has 17 values, not bands, because a band is an entire colour channel (think the red, green and blue channels in a typical colour image). Are these "blocks" a different shapefile than the district shapefile? It is hard to give you advice unless we can see these shapefiles with the image. – wfgeo Oct 15 '19 at 8:35
  • Added the shape file of blocks or counties. – G.S. J Oct 15 '19 at 8:47
  • It would be great if you can add the information returned by gdalinfo to the raster file. – Gabriel De Luca Oct 15 '19 at 9:25
  • 1
    Make sure your coordinate system for the district shapefile with blocks is in the same coordinate system. Also that each polygon has its own unique ID. What exactly is the error that gets returned - can you post the log? – wfgeo Oct 15 '19 at 12:05
  • Each polygon has its own unique id. Both shape files are in the same coordinate system. I don't know how to solve this problem, that's why I can't post the log here. I know that "r.report" gives me the area under each value (17 values), but how can I do the same for multiple blocks (like the above image) at the same time. – G.S. J Oct 16 '19 at 3:43
0

I had a similar problem. My solution was to modify the image to a black and white image and then use zonal statistic. I did the following steps on a Windows 10 computer

1) Find out about the colours in the image. I did this using gdalinfo in the OSGeo4W shell (see this link for details)

gdalinfo -hist  MyMapOriginal.tif

In my case, it gave me the following result

....
  229145351 33906481 23372842 1766970 67856 30414 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  Color Table (RGB with 256 entries)
    0: 244,240,232,255
    1: 48,132,92,255
    2: 24,20,12,255
    3: 240,232,72,255
    4: 196,68,72,255
    5: 40,116,196,255
    6: 52,48,116,255
    7: 0,0,0,255
...

I then used a web colour identifier (for example this one) to find out that the third colour (240,232,72) is the one I want to have the statistics about (the colour was yellow).

2) Replace colours using the replace command from Imagemagick. I first made all non-yellow pixel balck

magick MyMapOriginal.tif              -fill black +opaque "rgb(240,232,72)"  MyMap_yellowBlack.tif

and then the yellow pixel white

magick MyMap_yellowBlack.tif  -fill white -opaque "rgb(240,232,72)"  MyMap_whiteBlack.tif

3) In QGIS I then did zonal statistics. The value in "sum" returns the number of pixel within each zone (districts in the question of Q.S.J), and "value" the sum of the values in each zone. In my case, white had the value 255 and black the value 0. Thus to calculate the share of white (originally yellow) pixel, I need to derive (value/255)/sum.

4) You can now repeat 2) and 3) for each colour you are interested in.

Some notes beyond the question by Q.S.J:

a)If you work with a scan (e.g. a jpeg of a map) rather than an original raster file, you probably want to reduce the number of colours before you do step 1). The reply by Steven Kay explaines how this can be done within QGIS. I had good results using the GIMP tool found in the menue Image - Mode - Indexed using the custome palette PointJet colours.

b) If your scan consists of several sheets, it is a good idea to merge them first (e.g., using the montage command from imagemagick), otherwise you end up with different colour codes for each sheet.

c) If you also need to georeference your map (which is much more difficult with a black/white map), you can do this in QGIS using the Georeferencer (menue "Raster-Georeferencer...") with your original map ("MyMapOriginal.tif") and save the GCP Points (in the menue "File" within the georeferencer window). Then open the modifed black/white map ("MyMap_whiteBlack.tif") in the georference window, laod the GCP points and use them for georeferencing.

| improve this answer | |

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.