How to concatenate raster images in one representing value?

3545
17
Jump to solution
08-11-2017 08:24 AM
AshrafAfana
New Contributor II

Hi all, 

I'm trying to concatenate the values of two raster images in order to have a value that includes both of them (e.g. 02 + 07 = 0207). I'm trying to use the following in Raster Calculator "image1" & "" & "image2" but with no success. 

any suggestions?

0 Kudos
1 Solution

Accepted Solutions
SteveLynch
Esri Regular Contributor
17 Replies
IanMurray
Frequent Contributor

Do your rasters have the same extent and cell size?

0 Kudos
AshrafAfana
New Contributor II

Yes. Same resolution and same extension.

0 Kudos
ChrisDonohue__GISP
MVP Alum

Not sure if this will take you where you want to go, but I will throw it out there:

If 0207 is the desired output of rasters with values of 02 + 07, try multiplying the first raster by 100 before adding the raster values together.

Essentially:  (02*100) + 07

Chris Donohue, GISP

AshrafAfana
New Contributor II

Thanks Chris for the reply and for the simple idea. This should work with me. I thought ArcGIS can do it by converting the numbers to string character and concatenate them.

Thanks 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Rasters are represented by numbers ... 02 would suggest text... you can concatenate text, but not numbers. You won't get a preceeding 0 in 0207, the closest you will get is 207 as suggested by Chris.  Your end goal is therefore confusing

AshrafAfana
New Contributor II

Thanks Dan, 

Absolutely agree, but I was using R where I can convert numeric to string character and concatenate them and I thought if there was away to do it directly in ArcGIS. Anyway, Chris suggestion was a valid solution. 

Thanks

0 Kudos
SteveLynch
Esri Regular Contributor

have a look at Combine

AshrafAfana
New Contributor II

Thanks Steve, 

But combine does not solve my problem. 

0 Kudos
curtvprice
MVP Esteemed Contributor

Raster datasets in ArcGIS do not contain strings for each cell, natively, the values in the raster are numbers. When there is a string value for a cell it is stored in a raster attribute table related to each value. (Only integer rasters can have such a  table.)

I disagree, I believe Steve Lynch is right on (as usual, Hi Steve) in suggesting Combine(): this is a more general solution as you could then a build a Calculate Field expression to populate a string field in the raster table with something that you want like "0207". One could do other encodings (to strings or numbers) by using a different Calculate Field expression.

1. Combine("ras1", "ras2")

The output will raster table will have two fields, RAS1 and RAS2, with a row for every unique combination (not every cell) and a COUNT of how many had that combination.

2. Add Field, "RCODE", "TEXT"

3. Calculate Field Python expression: "{:02}{:02}".format(!RAS1!, !RAS2!)

The RCODE field will be set to "0207" if RAS1=2 and RAS2=7 for that row.