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?
have a look at Combine
Do your rasters have the same extent and cell size?
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
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
Yes. Same resolution and same extension.
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
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 Steve,
But combine does not solve my problem.
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.
way too much overkill for a preceeding zero
far easier to edit the legend
This is a tricky but genius answer and it solves the problem in a handy way. To be honest, I coded the process in python and it works for as many combination as you'd like. Thanks Curtis.
Ashraf
Hi Ashraf,
I have a similar issue with concatenating Fields of rasters in ArcMap. I combined 2 rasters to get a raster with both Fields from the 2. Then I concatenated the text Fields as per the suggestions above. The result is fine. But the problem with this raster is that when I apply Raster Calculator, it does not work on the joint fields, and it only works on the Value and Count fields. I was thinking you might have encountered the same issue and could give me some advice.
Cheers.
You can access raster fields using the Lookup tool. Not so sure you can apply Raster Calculator on text values however.
Thanks Curtis.
That's actually really helpful. I did not know about this tool at all. But I am wondering wouldn't the "join from a table" do the same thing?
But I am wondering wouldn't the "join from a table" do the same thing?
Lookup is the way to access fields in raster attribute tables that are not value. In 9.x the syntax for this was 'raster.field' (eg 'raster.COUNT') this is now in map algebra expressed as Lookup(raster, "COUNT") If you have a active join from the raster table to another table, you can use that in the Lookup expression with the fully qualified field name in the joined table: Lookup(raster, "othertable.field")
Again in map algebra expressions must resolve to a numeric value -- you can't use map algebra to combine raster table text fields. The best you can do to combine text fields from multiple raster inputs is do a Combine, add a new text field to the Combine output raster table, add a join back to the inputs using Add Join and run Calculate Field to populate the new field from calculations using the fully-qualified related field names.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.