0

I would like to know how I can extract a certain land cover type from a CORINE raster (GeoTiff) in R. I have the .tif file read in using raster function from raster package.

How can I binarize this raster so that land cover "Pasture" land cover type, which happened to have the value 231, is converted into 1 and all the others are turned into 0. Below is a piece of code you can use to explain your answer. I would like to save this new raster as a new raster.

raster("CLC2018_CLC2018_V2018_20.tif") -> corine   # Read in using raster function from raster package
plot(corine) # Gives the map below.

Thanks in advance!

enter image description here

1 Answer 1

3

Comparing your raster with a numeric value results in a 1 for TRUE and a 0 for FALSE. This should work, I can't test it without your data file.

corine <- raster("CLC2018_CLC2018_V2018_20.tif")  
pasture <- corine == 231

show it:

plot(pasture)

get a table of pasture/non-pasture cells:

table(pasture[])
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.