[R-sig-Geo] Selecting cells in a raster
Robert J. Hijmans
r.hijmans at gmail.com
Wed Oct 16 05:42:36 CEST 2013
Hugh,
You really should not use raster[] because that will fail with large
objects, and it is not necessary. Manuel's
forest <- cob_r == 1
is correct.
Robert
On Tue, Oct 15, 2013 at 1:29 PM, Hugh Sturrock <hughsturrock at hotmail.com> wrote:
> Hi Manuel,
> raster[] will give you a vector of the raster values so
>
> #create a new raster of the same red and extent as cob_r
> forest_raster<-cob_r
>
> # assuming forest pixels have a value of 1
> forest_raster[forest_raster[]!=1]<-0
> plot(forest_raster)
>
> Does that work?
>
> Date: Tue, 15 Oct 2013 10:49:50 -0600
> From: mspinola10 at gmail.com
> To: r-sig-geo at r-project.org
> Subject: [R-sig-Geo] Selecting cells in a raster
>
> Dear list members,
>
> I have a raster with land use data (with values from 1 to 9). I want to
> select the cells with value 1 wich belong to forest. How can I do that? I
> was trying:
>
> forest <- cob_r ==1
> plot(forest)
>
> but it didn´t work
>
>> cob_r
> class : RasterLayer
> dimensions : 314, 236, 74104 (nrow, ncol, ncell)
> resolution : 300, 300 (x, y)
> extent : 447181, 517981, 1121851, 1216051 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=tmerc +lat_0=0 +lon_0=-84 +k=0.9999 +x_0=500000 +y_0=0
> +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names : layer
> values : 1, 9 (min, max)
>
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre
> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspinola at una.ac.cr
> mspinola10 at gmail.com
> Teléfono: (506) 2277-3598
> Fax: (506) 2237-7036
> Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
> Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>
>
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list