25

I want to extract certain values of a raster image in order to create a new raster which then should only contain the extracted/chosen values.

How to do this in QGIS?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Peter QGis
  • 251
  • 1
  • 3
  • 3
  • 1
    I think how you would do this will depend on what exactly you wish to do. If say you had a one-band raster with pixel values between 0 and 1000 you might want to select pixels with values between (say) 495 and 600 or pixels with values between 300 and 450, or both. Or you might wish to select all of the pixels above a certain value or select all of the pixels below a certain value, or both. Can you provide a bit more detail? N. – nhopton Feb 02 '13 at 09:11
  • 1
    I'm having a self created raster image containing pixel of 11 differnt values. What I want to do is to extract for example all pixel with value 3 to a new raster image. The new raster image then should have only the value 3 pixel. – Peter QGis Feb 05 '13 at 16:42
  • 1
    See my answer, below. N. – nhopton Feb 05 '13 at 19:42

6 Answers6

21

Load the raster and start the raster calculator. Set an output filename then in the "Raster calculator expression" text box type:

filename@1 = 3

Where "filename" is the name shown under "Raster bands". Then press OK. That's it!

See also: http://spatialgalaxy.net/2012/01/25/using-the-qgis-raster-calculator/

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
nhopton
  • 6,983
  • 1
  • 19
  • 36
5

QGIS has a Raster Calculator that can calculate specific raster bands using mathematical expressions and save that to specific GDAL enabled formats, such as GeoTIFF, Erdas Imagine, etc.
There are a number of additional QGIS plugins as well.
see http://plugins.qgis.org/plugins/tags/raster/ QGIS can be built with GRASS which has raster functionality http://grass.osgeo.org/programming6/gisrasterlib.html

You didn't ask about this, but you might want to consider other remote sensing software such as Optics [FOSS]-- opticks.org

And these industry standard Products of course: Erdas Imagine geospatial.intergraph.com and the exceptional ESRI Raster capabilities. www.Esri.com

user12711
  • 1,620
  • 3
  • 16
  • 26
4

Gdal calc would be another option use

gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A==3)" --NoDataValue=0

see http://www.gdal.org/gdal_calc.html

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
2

Expanding on @can-sucuoglu 's answer If you want to extract the value 14 from a multi-value raster, which represents wetlands in the Canadian Land Cover Classification. (https://open.canada.ca/data/en/dataset/ee1580ab-a23d-4f86-a09b-79763677eb47)

  1. Select the Raster Calculator Tool from the Processing Tools
  2. Enter the formula in the Expression box that includes the value want to extract from the layer. Here, Ontario is the layer and 14is the value to extract as its own raster file : ("Ontario@1")/("Ontario@1"=14)
  3. Choose the layer you are using in the Reference layer box
  4. Run

enter image description here

user3386170
  • 1,957
  • 1
  • 28
  • 53
1

If you want to extract the values without having 0's, you need to use a different formula in the Raster Calculator.

"img1@1"/("img1@1">0)

0 values will be returned as no values.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
  • When I attempt your formula, the resulting output is identical to the input raster. – Stu Smith May 05 '21 at 14:53
  • This code specifically would work to extract values greater than 0. Depending your data this might happen. The important point is that when you put the mask statement as the divider when it is 0 the algoritm return Null or No Data Values. – Can Sucuoglu May 06 '21 at 15:10
1

Identify Polygons on raster image

This was a similar question. I was looking to take certain parts of the raster out (in my case buildings) and create polygons...but you create a raster first. or create the polygons and then convert to raster.

Ger
  • 2,575
  • 8
  • 35
  • 45