Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a raster that I think was "combined" using an arcmap function. I am wondering if there is a way to extract just one raster layer from the combined dataset in order to use it separately, either in R or Arcmap.

If you want to see the data it is available here

It takes this form in R:

class       : RasterLayer 

dimensions  : 10995, 10349, 113787255  (nrow, ncol, ncell)

resolution  : 100, 100  (x, y)

extent      : -446880, 588020, -612570, 486930  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +datum=NAD27 +units=m +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat 

data source : G:\Faculty\Mann\Share\Fire\FRAP_FireThreat\FireThreat.tif 

names       : FireThreat 

values      : 0, 255  (min, max)

attributes
     fields : ID Rowid   COUNT FUEL_RANK FROTCLASS URBAN THREAT THREAT2PEOPLE
        min :  1     0       1        -1         0     0     -1            -1
        max : 97    96 5360409         3         3     1      4           424
share|improve this question
add comment

2 Answers

The data slot in sp DataFrame objects can be accessed by simply using @ and a standard column index $ or [,"ColName"]. You do not need to define names in the reclass matrix, it just needs to be three columns (from value, to value, new value) Your code can be consolidated to:

reclass <- matrix(c(fire_threat@data$ID, fire_threat@data$ID, 
                    fire_threat@data$THREAT), ncol=3)
THREAT <- reclassify(fire_threat, reclass)

If you do not need to be memory safe (i.e., plenty of RAM to hold the raster in memory) it would be more efficent to read your raster directly to a sp SpatialGridDataFrame object using readGDAL in the rgdal package. Using the raster package is introducing coercion, which is adding unnecessary overhead. Then, you would not need to reclassify the raster. You could just use writeGDAL and specify the "THREAT" column as the value attribute that is assigned to the output.

share|improve this answer
add comment
up vote 0 down vote accepted

I figured it out in R. Used attribute data as a lookup table where ID was the current cell value (and unique lookup for THREAT class)

    >fire_threat = raster('G:\\Fire\\FRAP_FireThreat\\FireThreat.tif')

    > fire_threat

class       : RasterLayer 
dimensions  : 10995, 10349, 113787255  (nrow, ncol, ncell)
resolution  : 100, 100  (x, y)
extent      : -446880, 588020, -612570, 486930  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +datum=NAD27 +units=m +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat 
data source : G:\Faculty\Mann\Share\Fire\FRAP_FireThreat\FireThreat.tif 
names       : FireThreat 
values      : 0, 255  (min, max)
attributes
     fields : ID Rowid   COUNT FUEL_RANK FROTCLASS URBAN THREAT THREAT2PEOPLE
        min :  1     0       1        -1         0     0     -1            -1
        max : 97    96 5360409         3         3     1      4           424


    > lookup = data.frame(slot(fire_threat, "data")@attributes)  # ID is raster value, look up corresponding THREAT
    > head(lookup)

  ID Rowid   COUNT FUEL_RANK FROTCLASS URBAN THREAT THREAT2PEOPLE
1  1     0  740186         1         0     0      1           324
2  2     1  993424        -1         0     0     -1           324
3  3     2 3371876         1         1     0      1           324
4  4     3 2641845         3         1     0      3           324
5  5     4 1060206         3         2     0      3           324
6  6     5  406150         2         0     0      2           324

    > rclass = lookup[,c('ID','THREAT')]
    > head(rclass)

  ID THREAT
1  1      1
2  2     -1
3  3      1
4  4      3
5  5      3
6  6      2

    > names(rclass)=c('is','becomes')
    > head(rclass)



     is becomes
    1  1       1
    2  2      -1
    3  3       1
    4  4       3
    5  5       3
    6  6       2

    >    THREAT = reclassify(fire_threat,rclass)
    > THREAT

class       : RasterLayer 
dimensions  : 10995, 10349, 113787255  (nrow, ncol, ncell)
resolution  : 100, 100  (x, y)
extent      : -446880, 588020, -612570, 486930  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +datum=NAD27 +units=m +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat 
data source : G:\Faculty\Mann\Share\Fire\FRAP_FireThreat\THREAT.tif 
names       : THREAT 
values      : -1, 4  (min, max)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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