[R-sig-Geo] reclassify question

Agustin Lobo alobolistas at gmail.com
Mon Jan 13 09:07:30 CET 2014


Ashton,

We had had this problem with categorical values in the past, and
precisely this is why
Robert introduced specific support. From the help page of reclassify:
"You can also provide a two column matrix ("is", "becomes") which can
be useful for integer values. In that case, the right argument is
automatically set to NA"

If you use a range, note also the information of the help page on
which bounds are included in the range (arguments right and
include.lowest)

Agus


On Sat, Jan 11, 2014 at 8:44 PM, Ashton Drew <cadrew at ncsu.edu> wrote:
> I have just started switching from Arc to R for some of my spatial analyses
> and am stuck on a reclassification problem.  I am trying to use reclassify
> from the package raster.  I have been able to run the examples, but cannot
> run my own data.  I have tried to provide an example of my code using a
> small subset of my data.  The reclassify does work for some values (about
> 9/10 of the grid cells), but not all.  In the example below, values 71,
> 145, and 231 are not reclassified.
>
> The primary difference that I can find between my data and the worked
> examples is that all examples seem to assume that a range of values from
> continuous data are being reclassified, while my data are categorical
> (numerical codes for land cover classes).  Instead of a range to single
> value reclassification, I just want to reclassify each value to a single
> different value (in some cases, some of the original data can be treated as
> if they are a range, as shown in the example reclass matrix, but in reality
> this is not the case).  I thought maybe I could just put the same value in
> both the min and max columns, but that did not seem to work (value 71 in
> the example).  But that is not the only problem, because 145 and 231 are
> both values that I treated as if they were part of a range.  I do not get
> any error
> messages, just some values do not reclassify.
>
> So I am out of ideas.  If I cannot use reclassify, is there another way to
> classify ordinal or categorical raster data when I am not reclassifying a
> range to single value? Thank you for any help!
>
>> testarea
>
> class       : RasterLayer
> dimensions  : 34, 33, 1122  (nrow, ncol, ncell)
> resolution  : 30, 30  (x, y)
> extent      : 1200009, 1200999, 999992.1, 1001012  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0
> +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
> data source : in memory
> names       : segap_scope
> values      : 1, 231  (min, max)
> attributes  :
>         ID   COUNT
> CLASS_NAMES       RED     GREEN      BLUE OPACITY
>  from:   1 7128758                                  Open Water (Fresh)
> 0.3568627 0.4588235 0.6392157       1
>  to  : 253  427139 Southern and Central Appalachian Oak Forest - Xeric
> 0.5372549 0.6666667 0.3294118       1
>
>>
>> #Open reclass table.  Three columns From/To Values for input range, new
> value for output
>> recls = read.csv(file="
> SecondReclassTable_Rinput.csv", head=FALSE,
> sep=",")
>> recls = as.matrix(recls)
>> recls
>
>        V1  V2 V3
>  [1,]   1   7  0
>  [2,]  10  12  1
>  [3,]  16  26  0
>  [4,]  30  33  6
>  [5,]  35  37  0
>  [6,]  38  60  6
>  [7,]  61  64  4
>  [8,]  66  68  6
>  [9,]  71  71  4
> [10,]  72  74  3
> [11,]  76  77  4
> [12,]  79  79  3
> [13,]  82  82  6
> [14,]  85  85  4
> [15,]  86  86  6
> [16,]  90  96  4
> [17,]  98  99  6
> [18,] 100 100  4
> [19,] 102 109  6
> [20,] 118 118  0
> [21,] 119 119  6
> [22,] 124 127  0
> [23,] 141 143  1
> [24,] 145 149  0
> [25,] 151 182  2
> [26,] 183 188  4
> [27,] 192 206  2
> [28,] 207 207  0
> [29,] 213 216  5
> [30,] 217 217  1
> [31,] 218 228  5
> [32,] 231 233  4
> [33,] 238 238  2
> [34,] 245 250  5
> [35,] 253 253  6
>
>
>>
>> ecos = reclassify(testarea, recls)
>>
>> ecos
> class       : RasterLayer
> dimensions  : 34, 33, 1122  (nrow, ncol, ncell)
> resolution  : 30, 30  (x, y)
> extent      : 1200009, 1200999, 999992.1, 1001012  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0
> +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
> data source : in memory
> names       : layer
> values      : 0, 231  (min, max)
>
>
> --
> --
> C. Ashton Drew, PhD
> NC Fish and Wildlife Coop. Research Unit
> Dept. of Applied Ecology
> North Carolina State University
> cell: 919-886-2811
> email: cadrew at ncsu.edu
>
>         [[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