|
POST
|
Only use setValue() if the field name is a variable. if your field IS NOT a variable: rows = arcpy.UpdateCursor("Parcels", "FID = 1")
for row in rows:
row.GENERATED = "GENERATED"
rows.updateRow(row) if your field IS a variable: myField = "GENERATED"
rows = arcpy.UpdateCursor("Parcels", "FID = 1")
for row in rows:
row.setValue(myField,"GENERATED")
rows.updateRow(row)
... View more
08-23-2012
02:01 PM
|
0
|
0
|
1747
|
|
POST
|
setvalue vs setValue Python is case sensitive... Meaning there is a difference between upper case (V) and lower case (v).
... View more
08-23-2012
01:43 PM
|
0
|
0
|
1747
|
|
POST
|
but can i start an edit session automatically with arcpy script Actually, in v10.1, yes you can: http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000005000000 Although I feel that extra complexity might not be what you actually want to do in this case...
... View more
08-23-2012
01:10 PM
|
0
|
0
|
1747
|
|
POST
|
Not sure why it's not working. Can you do a test and harcode your remap_cur variable such as: remap_cur = arcpy.sa.RemapValue([7, 777][8,888],[9,999],...) ? You are able to use variable in the remap tables, so I don't think that's the issue... More likely you are not retreiving the variables you want to use in the correct way. Are the row's field values you are retreving indeed integers - or as the error suggests, a tuple object? For example something weird and unexpected like (None, 3). What does: print row.BIOME_7 evaluate to? Also, where in your code do you define the "row" object (as in row.BIOME_7)... shouldn't it be something like "cursor.BIOME_7"?
... View more
08-23-2012
10:36 AM
|
0
|
0
|
1666
|
|
POST
|
For SAG's (American slang), here's the v10.1 equivalent using the new "data access" update cursor syntax: fieldList = ["GENERATED"] #list of the field names you want the cursor to return... order is important
rows = arcpy.da.UpdateCursor("Parcels", fieldList, "OBJECTID = 1")
for row in rows:
row[0] = 'GENERATED' #fields are now refered to in terms of their index in the fieldList
rows.updateRow(row)
... View more
08-23-2012
09:30 AM
|
0
|
0
|
2529
|
|
POST
|
I might add that your original sytax of .setvalue should in fact be .setValue (case now matters in v10.0 +!!!). also, I think your SQL in the cursor statement was incorrect. Note you ONLY need to use the .setValue() method if your field name is a variable. This should work: rows = arcpy.UpdateCursor("Parcels", "OBJECTID = 1")
for row in rows:
row.GENERATED = 'GENERATED'
rows.updateRow(row)
del row, rows Alternately, this should also work, and demonstates the proper use of the .setValue() method: generatedFieldName = "GENERATED"
rows = arcpy.UpdateCursor("Parcels", "OBJECTID = 1")
for row in rows:
row.setValue(generatedFieldName) = 'GENERATED'
rows.updateRow(row)
del row, rows
... View more
08-23-2012
09:22 AM
|
0
|
0
|
2529
|
|
POST
|
I think the sytax for using the remap table is: arcpy.sa.RemapValue() as in... temp3Grd = arcpy.sa.Reclassify(temp2Grd, "Value", arcpy.sa.RemapValue([[1,1],[0,"NODATA"]]), "DATA") I think you are getting an error because you are not specifying the arcpy.sa... part of the Remap command.
... View more
08-22-2012
02:05 PM
|
0
|
0
|
1666
|
|
POST
|
ArcView only allows two FCs to be unioned at a time. Here is some ***untested*** Python code that could serve as a work-around:
#Be carefull to delete any "tmp_*" or "final_union" FCs before you run the code... otherwise those'll get unioned too
import arcpy
arcpy.env.workspace = r"C:\temp\python\test.gdb"
fcList = arcpy.ListFeatureClasses("*", "POLYGON")
i = 0
for fc in fcList:
i = i + 1
if i == 1:
unionFcList = [fcList[i-1],fcList]
else:
inputTmpFC = "tmp_" + str(i-1)
unionFcList = [fcList,inputTmpFC]
outTmpFC = "tmp_" + str(i)
arcpy.Union_analysis(unionFcList, outTmpFC)
arcpy.Delete_managment(inputTmpFC)
arcpy.Rename_managment(outTmpFC, "final_union")
... View more
08-22-2012
01:00 PM
|
0
|
0
|
1511
|
|
POST
|
These 3 lines of Python code, if you aren't using them already, should help to speed things up a bit as well: arcpy.SetLogHistory(False)
arcpy.env.pyramid = "None"
arcpy.env.rasterStatistics = "None"
... View more
08-22-2012
09:15 AM
|
0
|
0
|
2008
|
|
POST
|
I logged a new bug for this issue, NIM083765. Appreciate that. Thanks Chris.
... View more
08-13-2012
04:30 PM
|
0
|
0
|
2681
|
|
POST
|
Thanks Jason... Working sytax: http://forums.arcgis.com/threads/64580-SQL-sort-parameter-syntax-for-da.cursors?p=223774&viewfull=1#post223774
... View more
08-13-2012
02:07 PM
|
0
|
0
|
4306
|
|
POST
|
Okay - I get the 'named parameter' thing... .It's working now... Thanks Chris and Jason! Correct sytax for a multiple field sort: arcpy.da.UpdateCursor(oesfHydroDislvFC, fieldList, sql_clause=(None, 'ORDER BY SL_WTRTY_CD, RIP_COMBO_UID DESC')) Note that the Help system indicates "ORDER_BY" but it is really "ORDER BY" (with no underscore). VERIFIED: arcpy.da.UpdateCursor(oesfHydroDislvFC, fieldList, None, None, False, (None,'ORDER BY SL_WTRTY_CD, RIP_COMBO_UID DESC')) results in an error.... Not sure why...
... View more
08-13-2012
02:04 PM
|
0
|
0
|
2681
|
|
POST
|
A related thread: http://forums.arcgis.com/threads/49897-arcpy.da.Searchcursor-sql_clause
... View more
08-13-2012
01:39 PM
|
0
|
0
|
2681
|
|
POST
|
Hi Marc (Hoogerwerf) - Did you ever get the SQL sort function to work? I'm having the same difficulty... Trying to make this old code: arcpy.UpdateCursor(oesfHydroDislvFC, "", "", "", "SL_WTRTY_CD A;RIP_COMBO_UID D") Fly in v10.1... Trying all sorts of derivations of: fieldList = ["SL_WTRTY_CD","RIP_COMBO_UID","CHAN_WIDTH"]
updateRows = arcpy.da.UpdateCursor(oesfHydroDislvFC, fieldList, None, None, False, (None, 'ORDER BY SL_WTRTY_CD, RIP_COMBO_UID DESC')) but no luck so far... Common error is: Traceback (most recent call last): File "<interactive input>", line 1, in <module> TypeError: expected callable function - logger(obj) Any suggestions?
... View more
08-13-2012
01:37 PM
|
0
|
0
|
4306
|
|
POST
|
Thanks Chris I'm thinking the "fancy" SQL parameter is the 6th one down the line, so it probably should be something like this: arcpy.da.UpdateCursor(oesfHydroDislvFC, fieldList, None, None, False, (None, 'ORDER_BY SL_WTRTY_CD, RIP_COMBO_UID DESC')) But that is thowing an error: Traceback (most recent call last): File "<interactive input>", line 1, in <module> TypeError: expected callable function - logger(obj) Been trying a lot of things for a while - with nothing working out...
... View more
08-13-2012
01:29 PM
|
0
|
0
|
2681
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-25-2014 12:57 PM | |
| 1 | 08-29-2024 08:23 AM | |
| 1 | 08-29-2024 08:21 AM | |
| 1 | 02-13-2012 09:06 AM | |
| 2 | 10-05-2010 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|