AnsweredAssumed Answered

Arcmap python script - System Compatibility

Question asked by Mudassaralii_2k5 on Sep 11, 2020
Latest reply on Sep 12, 2020 by danretired

I have written a script for automating a task on .img file. The script is running perfect on windows 7 but giving error (snapshot attached) on windows 10. Both the systems have the same version of arcmap. 

 

# -*- #################
# ---------------------------------------------------------------------------
#
#
#
#
# ---------------------------------------------------------------------------
# Set the necessary product code
import arcinfo
# Import arcpy module
import arcpy,os,string,glob,sys
# Script arguments
DEM = arcpy.GetParameterAsText(0)
#river splitted shapefiles directory path
rootFolder = arcpy.GetParameterAsText(1)
#output directory
outputDir = arcpy.GetParameterAsText(2)
# Local variables:
home=os.path.expanduser('~')
constant_raster_ = home+"\\Documents\\ArcGIS\\Default2.gdb\\CreateConsta1"
point_feature = home+"\\Documents\\ArcGIS\\Default2.gdb\\c20_FeatureVerticesToPoints"
point_feature_with_elevation = point_feature
min_elevation = home+"\\Documents\\ArcGIS\\Default2.gdb\\c20_FeatureVerticesToPoints_"
Value = min_elevation
rastercalc = home+"\\Documents\\ArcGIS\\Default2.gdb\\rastercalc"
WaterMask = home+"\\Documents\\ArcGIS\\Default2.gdb\\Extract_rast3" # provide a Default2 value if unspecified
#loop for iterations through all shapefiles
for root,dirs,files in os.walk(rootFolder): 
    for name in files:                 
        if name.endswith(".shp"):
            #try:
                shpName = name #os.path.splitext(name)[0] 
                # absolute file path of shapefile river splits
                absFile = os.path.abspath(os.path.join(rootFolder,shpName))               
                water_body_feature_class = absFile
                # Process: Create Constant Raster
                arcpy.gp.CreateConstantRaster_sa(constant_raster_, "1", "FLOAT", DEM, water_body_feature_class)
                # Process: Feature Vertices To Points
                arcpy.FeatureVerticesToPoints_management(water_body_feature_class, point_feature, "ALL")
                # Process: Extract Multi Values to Points
                arcpy.gp.ExtractMultiValuesToPoints_sa(point_feature, DEM + ' ' +'elevation', 'NONE')
                # Process: Summary Statistics
                arcpy.Statistics_analysis(point_feature_with_elevation, min_elevation, "elevation MIN", "")
                # Process: Get Field Value
                #arcpy.GetFieldValue_mb(min_elevation, "MIN_elevation", "Double", "0")
                SC = arcpy.SearchCursor(min_elevation)
                field_name = 'MIN_elevation'
                for row in SC:                       
                    value=row.getValue(field_name)
                # Process: Raster Calculator
                #arcpy.gp.RasterCalculator_sa("\"%constant_raster_ %\" * float(%value%)", rastercalc)
                #arcpy.gp.RasterCalculator_sa(constant_raster_ * float(value), rastercalc)
                rastercalc=arcpy.sa.Raster(constant_raster_)*float(value)               
                # Process: Extract by Mask (2)           
                WaterMask=arcpy.gp.ExtractByMask_sa(rastercalc, water_body_feature_class)
                arcpy.CopyRaster_management(WaterMask,outputDir+"\\"+name.replace(".shp",'')+".img")
            #except Exception:
                # e=sys.exc_info()[1]
                # print(e.arg[0])
                #arcpy.AddError("Error in Shapefile "+shpName)

Attachments

Outcomes