I have a raster file (created in QGIS, from a vectorial file). I would like to know if it is possible, in R: 1) to change the values of the pixels? (I believe all the cells have the value "1" associated, or at least the blue pixels (check images below), and I don't know the values for the white pixels, but I would like to set it to "2", for instance, so it would be binary) 2) to "crop" the raster? Here are the characteristics of the input raster:
> catC1raster class : RasterLayer dimensions : 1384, 2359, 3264856 (nrow, ncol, ncell) resolution : 30, 30 (x, y) extent : 325352.8, 396122.8, 4613074, 4654594 (xmin, xmax, ymin, ymax) coord. ref. : +proj=utm +zone=31 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 names : CAT_C1_30m
And here is the plot:
asked Jun 28, 2018 at 22:33 391 1 1 gold badge 5 5 silver badges 15 15 bronze badgesYes. The raster package (cran.r-project.org/web/packages/raster/index.html) can modify the pixel values. Functions subs() and reclasify() are two ways to do it. The cunction crop() will crop your raster.
Commented Jun 28, 2018 at 23:04the crop function worked perfectly, thanks!! regarding the reclassify()/subs(), how can I find first the values each pixel has??
Commented Jun 28, 2018 at 23:22For each pixel my advise is to get them into a dataframe format with rasterToPoints(). Do note that depending on the size of your raster, the resulting dataframe might be very large.You could try values().