import arcpy
import xml.etree.cElementTree as ET
import os
import xlrd
from arcpy import env
import os.path
import shutil
import zipfile
import glob
#set paths to documents
myPath = os.getcwd() + "\\ScriptFiles"
excel_path = myPath + "\\Inputs.xls"
wb = xlrd.open_workbook(excel_path)
# Load XLRD Excel Reader
sheetname = wb.sheet_names() #Read for XCL Sheet names
sh1 = wb.sheet_by_index(0) #Login
#flag for first row
Skip = True
### Set Geoprocessing environments
arcpy.env.scratchWorkspace = myPath + "\\Scratch.gdb"
arcpy.env.workspace = myPath + "\\PROXCreate.gdb"
Coordinate_System = "GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" # provide a default value if unspecified
# Set overwrite option
arcpy.env.overwriteOutput = True
tmpRoads = "tmpRoads"
tmpBoundaries = "tmpBoundaries"
#Loop through Excel
for rownum in range(sh1.nrows):
rows = sh1.row_values(rownum)
#skip first row
if Skip == True:
Skip=False
else:
CountyName = rows[0]
StateName = rows[2]
InputRoadShpfl = rows[10]
InputBoundaryShpfl = rows[11]
ProjName = rows[9]
ProjCode = rows[12]
if arcpy.Exists(tmpRoads):
arcpy.Delete_management(tmpRoads)
if arcpy.Exists(tmpBoundaries):
arcpy.Delete_management(tmpBoundaries)
if (arcpy.Exists(myPath + "\\TigerFiles\\" + InputRoadShpfl)) and (myPath + "\\TigerFiles\\" + InputBoundaryShpfl):
print "Executing shapefiles:" + InputBoundaryShpfl + " & " + InputRoadShpfl + "(" + StateName + "\\" + CountyName + ")"
# Make a layer from the feature class
#arcpy.MakeFeatureLayer_management(myPath + "\\TigerFiles\\" + InputRoadShpfl, tmpRoads)
arcpy.CopyFeatures_management(myPath + "\\TigerFiles\\" + InputRoadShpfl, tmpRoads)
arcpy.MakeFeatureLayer_management(myPath + "\\TigerFiles\\" + InputBoundaryShpfl, tmpBoundaries)
# Process: Define Projection (3)
#sr = arcpy.SpatialReference(102629)
sr = arcpy.SpatialReference(ProjCode)
#sr = arcpy.SpatialReference(ProjName)
#sr.factoryCode = ProjCode
sr.create()
arcpy.DefineProjection_management(tmpRoads, sr)
ProjCode = rows[12] print type(ProjCode)
ProjCode = rows[12] ProjCode = int(ProjCode.strip())
Add a print statement to check type of ProjCode as follows:ProjCode = rows[12] print type(ProjCode)
Most probably the type is not an "int" - in that case convert it to an int:ProjCode = rows[12] ProjCode = int(ProjCode.strip())
#Loop through Excel for rownum in range(sh1.nrows): columns = sh1.row_values(rownum) print "row num = ", rownum #skip first row if Skip == True: Skip=False else: ProjCode = columns[0] print ProjCode print type(ProjCode) # check type for all rows ProjCode = int(ProjCode) sr = arcpy.SpatialReference(ProjCode) sr.create() print sr.name
if (arcpy.Exists(myPath + "\\TigerFiles\\" + InputRoadShpfl)) and (myPath + "\\TigerFiles\\" + InputBoundaryShpfl):
if (arcpy.Exists(myPath + "\\TigerFiles\\" + InputRoadShpfl)) and arcpy.Exists(myPath + "\\TigerFiles\\" + InputBoundaryShpfl):
print "Executing shapefiles:" + InputBoundaryShpfl + " & " + InputRoadShpfl + "(" + StateName + "\\" + CountyName + ")"
# Make a layer from the feature class
#arcpy.MakeFeatureLayer_management(myPath + "\\TigerFiles\\" + InputRoadShpfl, tmpRoads)
arcpy.CopyFeatures_management(myPath + "\\TigerFiles\\" + InputRoadShpfl, tmpRoads)
arcpy.MakeFeatureLayer_management(myPath + "\\TigerFiles\\" + InputBoundaryShpfl, tmpBoundaries)
# Process: Define Projection (3)
#sr = arcpy.SpatialReference(102629)
print ProjCode
sr = arcpy.SpatialReference(ProjCode)
#sr = arcpy.SpatialReference(ProjName)
#sr.factoryCode = ProjCode
sr.create()
print sr.name
arcpy.DefineProjection_management(tmpRoads, sr)
# Process: Add Field
arcpy.AddField_management(tmpRoads, "Length", "DOUBLE", "6", "3", "", "", "NULLABLE", "NON_REQUIRED", "")
# Process: Calculate Field
arcpy.CalculateField_management(tmpRoads, "Length", "!shape.length@miles!", "PYTHON", "")
# Process: Define Projection (2)
arcpy.DefineProjection_management(tmpRoads, "GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")