2

I have a raster that has 50 land cover classes. I am trying to combine multiple attributes from the attribute table into a single attribute. For example, I would like "Evergreen", "Semi-Evergreen" as - EVERGREEN.

I used the Editor Toolbar in ArcGIS and selected these features, but the Merge button on the Editor toolbar is greyed out. I read another solution that asked me to "delete the Shared Features tool on the Topology toolbar", but I was unable to do so. Apparently, deleting the "Shared Features" tool will activate the merge tool?

Either way, I would like to combine the attributes into a single attribute in R.

What I have tried in R so far (just loading and viewing the attributes)

> lulc_2015 <- raster("E:\\MasterThesis\\Absence Approach\\Data\\LandCover_Data\\2015_lulc")
> lulc_2015
class       : RasterLayer 
dimensions  : 26782, 11768, 315170576  (nrow, ncol, ncell)
resolution  : 60, 60  (x, y)
extent      : 163125, 869205, 855611, 2462531  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=43 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
data source : E:\2015_lulc 
names       : X2015_lulc 
values      : 1, 134  (min, max)
attributes  :
    ID     COUNT CLASS_NAME
from:   1 118944856           
to  : 134   3589862 Settlement

> lulc_2015@data@attributes
[[1]]
ID     COUNT                       CLASS_NAME
1    1 118944856                                 
2    2   2397462                        Evergreen
3    6     39397         Sub-tropical broadleaved
4   11   2457007                   Semi-evergreen
5   12   8798892                  Moist deciduous
6   13       184        Sal mixed moist deciduous
7   14   1076081       Teak mixed moist deciduous
8   15   6675337                    Dry deciduous
9   17   1790087         Teak mixed dry deciduous
10  18    476694                     Thorn forest
11  19    247793                     Bamboo mixed
12  20        16             Temperate coniferous
13  22      1109                              Sal
14  23    708833                             Teak
15  25    138858                           Bamboo
16  26         4                             Pine
17  30     85417                       Hardwickia
18  33      2179                        Boswellia
19  35       210               Anogeissus pendula
20  41    107796                         Mangrove

How do I combine these classes?


For those providing a possible solution, please note I am currently using Reclassify tool from the Spatial Analyst extension in ArcGIS to achieve the same, but if there is an alternative, please provide the same below.

4
  • The tools that you referred are all used for vector manipulation and irrelevant for raster processing. Reclassify or cascaded conditionals via raster calculator are the only options in ArcGIS that I think of.
    – fatih_dur
    Jun 5, 2017 at 16:03
  • Interesting. Reclassify is taking far TOO LONG. I have to manually classify almost 50-60 classes which is taking me atleast 20 minutes for each of the rasters I have. Jun 5, 2017 at 16:06
  • 1
    Have you tried building a model that will iterate through your datasets and perform the reclassify automatically? Jun 5, 2017 at 17:18
  • If the r tag is not an error, you could try using functionreclass of the raster package. Its use is quite straightforward: artax.karlin.mff.cuni.cz/r-help/library/raster/html/…
    – lbusett
    Jun 5, 2017 at 21:07

2 Answers 2

2

if you have, for example, 50 classes, and only classes 14,15,17 and 21 need to be aggregated all into 14, you can use raster:reclassify

require(raster)

r1 <- raster(xmn=0,xmx=10,ymn=0,ymx=10)
r1[] <- sample(1:50,100,rep=T)

# reclassification map must be a matrix
rc <- as.matrix(data.frame(from=c(14,15,17,21),to=c(14,14,14,14)))

r.rc <- reclassify(r1, rc)

#check 
freq(r1)
freq(r.rc)

i've found this to be the quickest way. If your raster is huge, reclassify can be done in parallel very quickly

Obviously you can make a large classification map with the matrix.

2

As an alternative to the raster::reclassify function suggested above, you could simply reclassify manually. Assuming you'd like to keep the attribute table:

# sample raster
library(raster)
#> Loading required package: sp
r <- raster(ncol = 10, nrow = 10)
r[] <- sample(1:10, 100, replace = TRUE)
r <- raster::ratify(r)

# build RAT table for sample raster
rat <- levels(r)[[1]]
rat$landcover <- letters[1:10]
levels(r) <- rat

# reclassify
r[r %in% c(1, 8)] <- 1
r[r %in% c(2:7, 10)] <- 2
r[r == 9] <- 3

# set new RAT for reclassfied raster
r <- raster::ratify(r)
rat <- data.frame(
  ID = 1:3,
  landcover = c("x", "y", "z") # new classes
)
levels(r) <- rat

r
#> class       : RasterLayer 
#> dimensions  : 10, 10, 100  (nrow, ncol, ncell)
#> resolution  : 36, 18  (x, y)
#> extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
#> data source : in memory
#> names       : layer 
#> values      : 1, 3  (min, max)
#> attributes  :
#>  ID landcover
#>   1         x
#>   2         y
#>   3         z

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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