0

I'm trying to assign a state plane zone based on if a point intersects it. I make a feature layer from a feature class. It gets through the loop once and calculates everything correctly, but when it loops again it says that the dataset already exists. Can I put the MakeFeatureLayer command at the top and have it loop through underneath that?

This is the line that it gets stuck on after it calculates the first group of points:
arcpy.MakeFeatureLayer_management(fc,"fcTemp")

 for fc in SMON:
 print fc + " Started Processing"
 arcpy.AddField_management(fc, 'LATDMS','text')
 arcpy.AddField_management(fc, 'LONGDMS','text')
 arcpy.AddField_management(fc, 'DESC_','text')
 arcpy.AddField_management(fc, 'StatePlane','text')
 arcpy.AddField_management(fc, 'State','text')
 arcpy.AddField_management(fc, 'Unique_ID','text')
 arcpy.AddField_management(fc, 'DateImport','text')
 print "Fields added"
 arcpy.CalculateField_management(fc, "LATDMS", "decdeg2dms ( !GlobalLati! )", "PYTHON", "def decdeg2dms(dd):\\n negative = dd < 0\\n dd = abs(dd)\\n minutes,seconds = divmod(dd*3600,60)\\n degrees,minutes = divmod(minutes,60)\\n if negative:\\n if degrees > 0:\\n degrees = -degrees\\n elif minutes > 0:\\n minutes = -minutes\\n else:\\n seconds = -seconds\\n seconds = round(seconds, 5) #my attempt to define it\\n \\n dms = '{0:.0f} {1:.0f} {2:.5f}'.format(degrees, minutes, seconds)\\n \\n return (dms)")
 arcpy.CalculateField_management(fc, "LONGDMS", "decdeg2dms ( !GlobalLong! )", "PYTHON", "def decdeg2dms(dd):\\n negative = dd < 0\\n dd = abs(dd)\\n minutes,seconds = divmod(dd*3600,60)\\n degrees,minutes = divmod(minutes,60)\\n if negative:\\n if degrees > 0:\\n degrees = -degrees\\n elif minutes > 0:\\n minutes = -minutes\\n else:\\n seconds = -seconds\\n seconds = round(seconds, 5) #my attempt to define it\\n \\n dms = '{0:.0f} {1:.0f} {2:.5f}'.format(degrees, minutes, seconds)\\n \\n return (dms)")
 #Assigning State Plane and Unique ID for SMON
 #fcTemp = "fcTemp"
 arcpy.MakeFeatureLayer_management(fc,"fcTemp")
 arcpy.SelectLayerByLocation_management("fcTemp", "INTERSECT", CON, "", "NEW_SELECTION")
 urows = arcpy.UpdateCursor("fcTemp")
 for urow in urows:
 urow.StatePlane = 'Colorado NorthTEST'
 urow.State = 'Colorado'
 urow.Unique_ID = str(urow.PointID) + str(Con)
 urows.updateRow(urow)
 arcpy.SelectLayerByLocation_management("fcTemp", "INTERSECT", NDN, "", "NEW_SELECTION")
 urows = arcpy.UpdateCursor("fcTemp")
 for urow in urows:
 urow.StatePlane = 'North Dakota North'
 urow.State = 'North Dakota'
 urow.Unique_ID = str(urow.PointID) + str(Con)
 urows.updateRow(urow)
asked Mar 12, 2014 at 15:32

1 Answer 1

2

Try adding this before before the loop:

arcpy.env.overwriteOutput = True

This tells your script to overwrite the output of any command. When the loop reaches the "fcTemp" it will know it's okay to overwrite the existing file.

Look here for more information.

answered Mar 12, 2014 at 15:40
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.