Create a binary raster

I am working with ecological niche models, I have a raster which represents the current scenario (img). I have a raster which represents the future scenario. To work on R, analyzing the lost areas and the areas gained in the future I need to reclassify the rasters. I need to traform the raster to binary, assigning a value of 0 to unsuitable areas, a value of 1 to suitable areas. How can I do?

• What do you mean polyline raster? Can you post a screenshot of the data you have/
– GBG
Commented Apr 27, 2021 at 18:13
• yes, I post a screenshot Commented Apr 27, 2021 at 18:41
• Your question is not clear and risks to be closed. To avoid this unpleasant experience, explain more in detail what you have, what you tried and where you 're stuck. To me it is unclear what a "polyline raster" is and based on what information a binary value could be created. What does your raster represent? Please edit the question. Commented Apr 27, 2021 at 19:04
• It looks like you just need to reclassify your existing raster. See Reclassify by table here: docs.qgis.org/3.4/en/docs/user_manual/processing_algs/qgis/…
– GBG
Commented Apr 27, 2021 at 19:10
• You only need to define the threshold value for discriminating suitable areas from unsuitable areas in both scenarios. Afterward, you can use QGIS Raster Calculator for obtaining both binary raster. Commented Apr 28, 2021 at 3:38

If you are going to take your data to R, you can reclassify them there.

Example data:

``````library(raster)
r <- raster()
values(r) <- runif(ncell(r))
``````

Solution

``````threshold <- 0.5
x <- r > threshold
x
#class      : RasterLayer
#dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#resolution : 1, 1  (x, y)
#extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#crs        : +proj=longlat +datum=WGS84 +no_defs
#source     : memory
#names      : layer
#values     : 0, 1  (min, max)
``````
• Thanks, I succeeded! Can I export the raster in TIF format? Commented Apr 28, 2021 at 12:39
• You can use `writeRaster` Commented Apr 28, 2021 at 16:24