I'm trying to reclassify only a certain part of a raster...not the entire raster. Here's the problem. I have a LULC raster of the entire US. There are some issues with the raster that I want to fix, namely some cells that should be water are classified as wetlands. These are mainly off the coast, not inland. However, some cells that are classified as wetlands should really be wetlands (mainly inland) and I don't want these to change. I plan on using a ZIP Code boundary file to determine which cells are considered "off the coast" and which ones are not. I have access to ArcGIS 10.1 and R with the appropriate raster packages I need so a solution in either software would be fine. Can anyone help me figure this out?


If I understand well, you have one class that needs to be changed only if it is located off the coast

So what you need to do is convert your ZIP code boundaries to raster (feature to raster): this will produce a raster that is Null (NoData) where you are not on inland.

Then apply a conditional statement in order to change your wetland values. In the raster calculator, this would look like this :

Con( IsNull("MyZIPraster") AND ("LULCraster"==wetland_value) , water_value , "LULCraster" )

where wetland_value and water_value are integer values of your class

  • 1
    Thanks so much. I used this formula in Raster Calculator and it worked. There was one slight error in the formula though. I had to replace the 'AND' with an ampersand (&), then it worked like a charm! – user27355 Feb 26 '14 at 14:35

Here is R solution: I used this post and edited it a little

library (raster)

# use state bounds from gadm website:
# us = shapefile("USA_adm1.shp")
us <- getData("GADM", country="USA", level=1)
# extract states (need to uppercase everything)
nestates <- c("Maine", "Vermont", "Massachusetts", "New Hampshire" ,"Connecticut",
              "Rhode Island","New York","Pennsylvania", "New Jersey",
              "Maryland", "Delaware", "Virginia", "West Virginia")

ne = us[match(toupper(nestates),toupper(us$NAME_1)),]

# create a random raster over the space:        
r = raster(xmn=-85,xmx=-65,ymn=36,ymx=48,nrow=100,ncol=100)

# plot it with the boundaries we want to clip against:

# now use the mask function
rr <- mask(r, ne)

# classification of masked cells
rr[] <- ifelse(rr[]>0.5,1,0)

# add classification to the original file
r@data@values[!is.na(rr@data@values)] <- rr@data@values[!is.na(rr@data@values)]

# plot, and overlay:
  • Thanks for the help. I ended up using ArcGIS for this but I will keep this solution handy for future R work. – user27355 Feb 26 '14 at 14:36
  • 1
    This thread answered exactly the issue I was having with my code - also working with Land Use maps. But the last command wouldn´t work for me, so I changed it to (the equivalent of) r[!is.na(rr)] <- rr[!is.na(rr)] I am not a pro and I don´t know why this works better, but it did work =). – user67597 Feb 19 '16 at 18:00
  • I had the same problem with code... thanks @Rafaela, wour solution works great !! also, I can't download the dataset – maycca May 8 '16 at 0:04

This sort of operation is often accomplished using a mask in the environment settings accompanied by a Spatial Analyst tool that honors the mask environment. The Con or Reclassify tools could be used to perform the analysis you describe.

enter image description here

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.