Hi,
I need to make it run the following code in arcGIS but this is not written to run in arcgis but in visual studio. I tried but it DOES NOT work. Can someone help me to write thin in python so that I can add as a script in ArcGIS.? I am planning to import this as a script after making this a working code.
Any help is highy appreciated.
Thanks.
------------------------------------------------------------------------
import arcpy
from arcpy import env
from arcpy.sa import *
#Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = "c:\temp\tmp"
env.workspace = "c:\DEMPreProcess"
LULC = Raster("C:\DEMPreProcess\VietnamLULC_Resample.tif")
Simard = Raster("C:\DEMPreProcess\MajoritySTOht.tif")
resultmap = Simard
for i in range(1,14):
if i == 1:
number = 0.4
elif i == 2:
number = 0.4
elif i == 3:
number = 0.4
elif i == 4:
number = 0.4
elif i == 5:
number = 0.4
elif i == 6:
number = 0.3
elif i == 7:
number = 0.3
elif i == 8:
number = 0.3
elif i == 9:
number = 0.3
elif i == 10:
number = 0.3
elif i == 11:
number = 0
elif i == 12:
number = 0.3
elif i == 13:
number = 0
elif i == 14:
number = 0.3
resultmap = Con(LULC == i,Simard*number,resultmap)
resultmap.save("C:\DEMPreProcess\MajoritySTOhtPer.tif")
Solved! Go to Solution.
Basically, you download the tool to a location on disk. Unzip the file. Open you existing model . Next navigate with the Catalog window to the location of the toolbox you just downloaded and unzipped. Drag the script on yout model window. It will appear with white colors and unconnected.
Now double click on the script tool "SRTM Correction Tree Offsets". In the dialog you will be able to select the intermediate results and inputs your are creating in your model:
Select the input rasters and specify the output result. When you click OK, you will see the result in the model:
Connect the output of the script tool to other processes in case necessary.
Please remember that in case the question has been answered, to mark the post that answered your question as "Correct Answer". In case you feel that other posts were Helpful you can mark them as such.
What is the error message? and what is it supposed to do?
Hi Dan,
I am new to python but what I want to write a script in python to take the integer values from i=1 to 14 in VietnamLULC_Resample.tif file and then multiplied by the interger values in the MajoritySTOht.tif file for each corresponding i.
I need to include this process as a pythin script to this model builder.
Thanks and help is appreciated.
It is hard to tell from your code formatting, but I think your last two lines should be indented so that they are within the for loop...currently, they are outside the loop by all appearances. You should use the Advanced Editor, then select >> and choose Syntax Highlighting and format your code in the original thread to Python syntax to make it easier to read and so indentation can be confirmed.
Dan,
The above code is run in Visual Studio but I want to convert it to pythin to include in the model bilder.
Where can I find the Advanced editor and syntax highlighting?
Thanks again for your reply.
In the upper right corner of the editor (when editing a post) you will see the link "Use advanced editor". The code you supplied is Python code. It is possible that Visual Studio has been used to run it, but the IDE has no influence on the code itself.
OK. But How can I include this code into my model buider environment? and to make it run?
Thanks and highly appreciate your help. I am very new to python and GIS model builder.
Create a new geoprocessing tool, set the source to your .py file, add the tool to your model.
Hi James,
Could you please illustrate how to do that? I am totally new to this.
Thanks again and appreciate it.