Saturday, 18 April 2015

arcgis desktop - Replacing Raster Values in Ras1 with Ras2


I have two rasters Ras1 and Ras2.


I want to change the Ras1.


In Ras1, there are few areas, lines, points I am interested having nodata cells and wrong data cells.(limited to interested areas only not talking about the entire Ras1 image)


For those interested areas of Ras1 having nodata cells and wrong data cells, I want to replace cell values with Ras2.


I have seen few tools replace values, but those are value specific ( ie. Replacing all "10" value cells with "56" in entire image) and conditon tools in arcgis, deals with null/no data values.


Is there any way, I can do Replacing Raster Values in Ras1 with Ras2 of my chosen area in the image?? Is there any way I can use arcgis / envi / erdas for this? Please guide me.



Answer




Do you have access to spatial analyst? If so, the Con function will do exactly what you want. Create a "condition" raster that is 1 where you want the values changed to Ras2 and 0 everywhere else. Execute the statements:


Ras1 = Con(Raster("condition"), Raster("Ras2"), Raster("Ras1"))
Ras1.save("Ras1")

This will replace Ras1 with your new raster. If you just want to create a new raster, change the string in the save function. If you do not have access to spatial analyst, I will see if there is a way around using the Con function.


ArcGIS 9.3.1 Raster Calculator method:


Again, assuming you have a condition raster as above.


outraster = con(condition > 0, Ras2, Ras1)

In the raster calculator, you just use the direct references rather than using the Raster function as I did for arcpy. You would then need to save your outraster and replace Ras1 with it.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...