POST
|
Hi. I ended up here because i was having the same problem. The suggestions here make sense as well. The thing is i don't want to put an if arcpy.Exists() for every layer. I was having the same problem until i put my section of code between the try:
<code>
except:
<code> and it worked. Why that makes all the difference is beyond me but it might be worth trying because it worked for me.
... View more
10-19-2012
11:26 AM
|
0
|
0
|
1109
|
POST
|
Hello fmonsn, I was getting the same error message with the CalculateField tool and with the help of a co-worker I found a solution. This may or may not help because i'm not too sure if your fields are area or length based. It turns out it's best to use Describe on feature class properties in the GDB before trying to calculate with an expression to convert the value to a different unit of measure. Here is some code inside a function that helped my script stop throwing ERROR 000539. def CalcAreaHa(dataIn,haField):
if not arcpy.ListFields(dataIn, haField):
arcpy.AddField_management(dataIn, haField, "DOUBLE","","4")
desc = arcpy.Describe(dataIn)
ftype = desc.ShapeType
if ftype == 'Polygon':
areaItem = desc.areaFieldName
if areaItem == 'GEOMETRY_Area':
arcpy.CalculateField_management(dataIn,haField,"!geometry.area@HECTARES!", "PYTHON_9.3")
else:
arcpy.CalculateField_management(dataIn,haField,"!shape.area@HECTARES!", "PYTHON_9.3")
... View more
10-02-2012
11:28 AM
|
0
|
0
|
400
|
POST
|
Hello everyone, Very helpful thread. Thanks. One thing I changed in my for loop was to use "ADD_TO_SELECTION" rather than use the "NEW_SELECTION". In my case the for loop would overwrite each previous selection which of course is not the intended result. The "ADD_TO_SELECTION" parameter acts like "NEW_SELECTION" for the first iteration. Here is my code for future reference to anyone else having similar problems. I have three seperate lists because I use them elsewhere in my function and my table contains 48 records. Of the 48 records only 37 are matched in the table as per my criteria. The idea behind this chunk of code within my function is to create a temporary or one time lookup table based on an area of interest. My goal was to select attributes I needed and delete the rows I did not need to complete my table.
sList = ['BG','PP','IDFxh1','IDFxh1a','IDFxh2','IDFxh2a']
mLIST = ['IDFdk1','IDFdk1a','IDFdk2','IDFdk3','IDFunk','MS']
dList = ['ESSF','ICH','CWH']
mergeList = sList+mLIST+dList
# This is using python list comprehension to add the '%' wildcard to each item in my list
# because the attributes BG, PP, MS, ESSF, ICH, CWH contain up to 4 more characters
mergeList = [x[:1]=='%' and x or x+'%' for x in mergeList]
print "The merged lists look like this:\n " + str(mergeList)
arcpy.MakeTableView_management("becFreqTbl","tempBecTbl")
for list in mergeList:
print 'iterating through list item:', list
where_clause = "MAP_LABEL LIKE '"+list+"'"
arcpy.SelectLayerByAttribute_management("tempBecTbl","ADD_TO_SELECTION",where_clause)
newSel = int(arcpy.GetCount_management("tempBecTbl").getOutput(0))
print "The new selection yieled "+str(newSel)+" fields selected"
arcpy.SelectLayerByAttribute_management("tempBecTbl","SWITCH_SELECTION")
switchSel = int(arcpy.GetCount_management("tempBecTbl").getOutput(0))
print "The switch selection yielded "+str(switchSel)+" fields selected"
arcpy.DeleteRows_management("tempBecTbl")
print "Deleted "+str(switchSel)+" rows from table that did not match the list criteria" The output looks like this: The merged lists look like this: ['BG%', 'PP%', 'IDFxh1%', 'IDFxh1a%', 'IDFxh2%', 'IDFxh2a%', 'IDFdk1%', 'IDFdk1a%', 'IDFdk2%', 'IDFdk3%', 'IDFunk%', 'MS%', 'ESSF%', 'ICH%', 'CWH%'] iterating through list item: BG% iterating through list item: PP% iterating through list item: IDFxh1% iterating through list item: IDFxh1a% iterating through list item: IDFxh2% iterating through list item: IDFxh2a% iterating through list item: IDFdk1% iterating through list item: IDFdk1a% iterating through list item: IDFdk2% iterating through list item: IDFdk3% iterating through list item: IDFunk% iterating through list item: MS% iterating through list item: ESSF% iterating through list item: ICH% iterating through list item: CWH% The new selection yieled 37 fields selected The switch selection yielded 11 fields selected Deleted 11 rows from table that did not match the list criteria
... View more
09-14-2012
02:23 PM
|
0
|
0
|
750
|
POST
|
I found this the other day. http://joelmccune.com/2011/05/05/run-models-as-scheduled-tasks/
... View more
08-08-2012
10:27 AM
|
0
|
0
|
514
|
POST
|
I've never found info so fast. Thanks for the code samples. Exactly what i was looking for. Dana
... View more
04-30-2012
08:34 AM
|
0
|
0
|
1793
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|