2

How do I merge multiple binary rasters that each have different values and still retain the values in the output file?

Background Information:

I am working on improving unsupervised classification by applying 4 slope classes to it for a grad school project.For example unsupervised classification clustered playa together, but there are some playa pixels on the top of 4,000 foot high mountains. By applying the slope classes to it using raster calculator, I can isolate those pixels and change them to the granitic mountain class.

EDIT: I did it like this: ("unsupervised"==3) & ("slope">=30) - this output would become mountains ("unupervised"==3) & ("slope"<30) & ("slope">=5) - this would become alluvial slope. There are 9 unsupervised classes and 4 slope classes. 9x4=36 outputs.

This process produced 36 rasters using raster calculator. These all have a value of 0 and 1. I tried all the same things listed below to merge them, but all outputs just ended up with 0 and 1 in the value field except for the "combine tool". That makes sense to me.

So then I multiplied each one by a unique class number. Now I have 36 rasters that are reclassified, each one contains values of 0 and a corresponding class 1-8. So there are several files that are class 2. Several that are class 8 , and so on. They do not overlap that I know of. I want to get them all into one file with 8 rows, (or 9 rows with the 0 value).If I could even get 36 rows with their reclassed value retained and then use the "lookup tool" to dissolve them that would be ok too. I been googling for hours and have tried everything as follows.

Mosaic to new raster - results in 0 and 1.

Add to raster dataset and calculate statistics - did not work , don't recall why

combine - Can't do all at once, reassigns a new value. Yeah, I could make this work sort of, but no one who opens the file will know what is going on or how to symbolize it.

Raster Calculator - add them together "raster1" + "raster2" etc. Always have an error like something that was not in the input values for example, a row with a value of 16 when no input is over 8.

Raster Calculator - Merge([raster1],[raster2],[raster3]) Error says output raster empty or similar.

Append - The table looks better but the image is a disaster something is totally wrong.Seems to be too many 0 pixels, holes in the image all over.

I have VERY basic python skills and also have ERDAS, if those options offer a solution.

Here it is before I reclassed all the files that were only 0 and 1. This is how I want the final image to look, just in 1 file with 8 classes.

Classified Landcover Image

  • 1
    This seems like an overly complicated approach. I'm also confused by your second paragraph when you say "That makes sense to me", it doesn't make sense to me why you have 36 rasters OR why they would be all 0 or 1. – jbchurchill Oct 21 '16 at 14:13
  • @jbchurchill There are 36 rasters because the unclassified image had 9 class. The intersection of 4 slope classes for each class is 9 x 4. It makes since to me that all the raster tools that combine them create an output of 0 and 1 because they work from the value field and they are not going to create a value that does not exist in the input. – GeographyNerd Oct 21 '16 at 14:18
  • Please clean up this question so that future users can help you. The following will help guide your edits: gis.stackexchange.com/help/how-to-ask – Aaron Oct 22 '16 at 23:57
  • @Aaron The problem is answered and that is why I added the EDIT at the top of the original question. Everyone was very helpful, and they seemed to understand the problem just fine. I see no reason to put it on hold. – GeographyNerd Oct 23 '16 at 0:45
  • 1
    @Aaron Ok I am still learning the very stringent rules of this forum. Clearly the question was why am I unable to merge multiple binary rasters with different values and retain those values in the output. I cannot move the answer until you remove the hold. I made edit with clear question. – GeographyNerd Oct 23 '16 at 1:15
1

I was able to use mosaic to new raster. Problem was I needed to set it to "sum" instead of first. Finally, I got classes 1-8. The first time I still had some pixels as 0 and some now as 16.I guessed that some pixels in class 8 overlapped and their sum was 16. I carefully looked back through all the reclassified files. I found that I had used the same input with a value of 8 for two classes. I fixed this, and it solved both the 16 where pixels overlapped and the 0 pixels. In retrospect, using raster calculator "raste1" + "raster2" did work, but I had the same 16 and 0 pixels. If I have time this semester I will revisit con statements to try and make this workflow easier. I looked at it in help, but do not fully understand the syntax.

0

If you know you'll have 36 possible classes and you are generating all of these binary rasters for each class, could you not just establish a code for each landform and generate "0, landform class code" rasters? I.e. Class 1=mountains,class 2=alluvial. Then do a "mosaic to new raster" function to combine? Or am I missing something.

  • I did that by reclassifying all the binary rasters to a new value as stated above. The output from mosaic to new raster combines them back to 0 and 1,even though the inputs are binary rasters that are 0 and 5 or 0 and 7 etc. I really thought this would work too. no idea why it does not. – GeographyNerd Oct 22 '16 at 4:22
  • And you're sure that you have chosen the proper pixel type (8 bit or above) and mosaic method for the tool? – Jae Oct 22 '16 at 9:04
  • I figured it out. I did have the wrong mosaic method. See the edit to the original post. – GeographyNerd Oct 22 '16 at 19:49
0

I think you can make this easier by keeping your original classification intact rather than splitting it out into several binary rasters (1 or 0) but you could potentially use those since you already have them. If you already have a "granitic mountain class", you can assign that (as you indicated) to those areas of a given slope category. I'm showing the dialog for using CON within the Raster Calculator (for steps 1 and 2).
I'm referring to "Spatial Analyst Tools"-> "Map Algebra" -> "Raster Calculator"

Step 1. I would start by just outlining the slopes of interest as a binary raster e.g. slopes > X%.

Con(SLOPE > 90%, 1, 0)

First Con Statement

Step 2. I thought that You could use that single binary raster and leave your original classifications alone by doing something like this (where ORIGINAL is the name of your classified image and 45 is the code for "granitic mountain" and OUTPUT2 is the result of Step 1 above)...

Con(OUTPUT2 == 1, 45, ORIGINAL)

Second CON statement

As long as the extents of both are the same and "NoData" is NOT involved, you shouldn't have any problem. I would also be sure the cell sizes match and that you are snapping output to a common raster so that all cells align perfectly (done in "Environment Settings").

As Jeffrey points out you can nest both statements and that should be perfectly valid however, looking at this again, the formatting he suggested is not exactly correct...

Con(Con(SLOPE > 90), 45, ORIGINAL)

will not work ... instead something like this might.

Con(Slope > 90, 45, ORIGINAL)

EDIT: With many categories, you may want to nest multiple times. If you have already created a series of binary rasters for different slope categories. Lets say you have named them CAT1, CAT2 for different categories of slope, you could nest these like this ...

Con(CAT1 == 1, 45, Con(CAT2 == 1, 46, Con(CAT3 == 1, 47, ORIGINAL)))

You just need to remember that the basic flow of CON is +/- "If true (comma) do this (comma), if not do something else and that second argument (the false) can be another Con statement.

You may also need to change your logical expression to include an "And" like ...

Con(Slope > 90 And ORIGINAL == 22, 45, Con(Slope > 90 And ORIGINAL == 23, 46, ORIGINAL))

but It may be easer to get it right inside the CAT1, CAT2 Categories first (best not to overcomplicate).

I suppose I'm used to doing things like this one step at a time to be sure it all works. It's just easier to figure out what happened if things do go wrong. I thought it would get you close to figuring this out.

  • Why the multi-step process, you can just apply the condition of slope directly to the raster that you want to modify. The use of nested con statements allows considerable flexibility, particularly for multiple conditions or applying a condition across rasters, in this case simply: Con(Con(SLOPE > 90), 45, ORIGINAL) – Jeffrey Evans Oct 21 '16 at 18:49
  • Good point. duly noted! – jbchurchill Oct 21 '16 at 19:26
  • @jbchurchill Thanks for the advice. I have little experience with rasters and dont even know what con is. I was just told to figure it out and this is what i came up with. I will look into con and try it when i get home. – GeographyNerd Oct 21 '16 at 22:23
  • @JeffreyEvans I think i understand how the CON example you have given will work. The thing is, everything over 30% slope in the unsupervised does not go to the same class. It goes to granite mountains or volcanic mountains. This is straight forward for some classes which were already clearly basalt, but other classes contain both areas of basalt and granite. When slope is applied to these poor classifications they must be visually evaluated to determine if they now better fit granite mountains or volcanic. All the classes are like this, volcanic plain or granitic plain and so on. – GeographyNerd Oct 22 '16 at 7:21

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.