AnsweredAssumed Answered

Run a python code in ArcGIS

Question asked by dljayasekera on Jan 13, 2015
Latest reply on Feb 3, 2015 by dljayasekera

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")

Outcomes