POST
|
However, for truly embedded cursor routines that have to look up records against each other or walk through a sorted pair of cursors (using multi-field keys especially), the primary hit is from maintaining the secondary query synchronization on unsorted records or records that are only sorted in memory. This is a great description of the case where the dictionary structure is so fast/usefull!
... View more
08-04-2010
02:39 PM
|
0
|
0
|
889
|
POST
|
Jinx posting. Look at my post right above yours concerning dictionaries. This is all great stuff - I'm a hack self-taught programmer, so it's great to get someone else's suggestions, tips, tricks, etc.
... View more
08-04-2010
01:48 PM
|
0
|
0
|
889
|
POST
|
Wow that's good info! So I do know of a way to get the field's index via Python, but it's slow and hokey, and you have to use a featurelayer or tableview as input. For example: gp.makefeaturelayer(fc,"fl") print gp.describe("fl").fieldinfo.findfieldbyname("TER_ID") 6 #that is to say TER_ID is the 7th field, 0 being the 1st. However, I don't think there is a way to retrieve a field value in a cursor using it's index value. Maybe I'm wrong though... Seems that would be a major performance enhancement like you said. I have mostly shied away from embedded cursors (current script being an exception) since they tend to be slow. One thing I have used a lot (and that could be useful here if the table wasn't too huge and you didn't care to transfer the geometry) is using a Python Dictionary object to emulate a table structure in memory. Once you have loaded a table into a dictionary (using a searchcursor) it is EXTREEMLY fast to access the field values. This is especially useful to when you have a need to constantly look up lots and lots of unordered values. For example, I wrote a script that performs traces of a stream network (created using the hydrology tools). The idea is that every arc is flowing downhill, so has a startnode that is upstream of the endnode. The basic approach I took was to load the OIDs and their start/end nodes into a dictionary. Then (if tracing downstream) I basically traverse the items in the dictionary, looking up the arcs end node, searching for an arc that has its startnode == the last end node and so on. See: http://forums.esri.com/thread.asp?t=275202&f=1729&c=93#948148 for the code. A simple dictionary example: lookupDict = {}
searchRows = gp.searchcursor(lookupTbl)
searchRow = searchRows.next()
while searchRow:
lookupDict[searchRow.LOOKUPITEM] = [searchRow.FIELDVALUE1,searchRow.FIELDVALUE2]
searchRow = searchRows.next()
del searchRow
del searchRows
updateRows = gp.updatecursor(tableToUpdateTbl)
updateRow = updateRows.next()
while updateRow:
updateRow.MEAN = (lookupDict[updateRow.LOOKUPITEM][0] + lookupDict[updateRow.LOOKUPITEM][1]) / 2
updateRows.UpdateRow(updateRow)
updateRow = updateRows.next()
del updateRow
del updateRows
del lookupDict
... View more
08-04-2010
01:41 PM
|
0
|
0
|
889
|
POST
|
Rich, You are totally correct! Great observation... I thought it seemed like when I was testing this stuff yesterday it was running a bit slow when I used the ORIG_OID option... Another idea to structure it would be to append the ORIG_OID field (if the user provides it) to the inputLayerFieldList, and then have a condition in the loop that says if inputLayerField == originalOidFieldName, then attempt to write it.
... View more
08-04-2010
01:05 PM
|
0
|
0
|
889
|
POST
|
Jim, That test looks fine to me (no random spaces). Seems like the issue is when users paste text into the message body. My assertion that it was the code tag was wrong. Must be a dyslexic day toady...
... View more
08-04-2010
12:40 PM
|
0
|
0
|
534
|
POST
|
Sounds like the classic gp memory leak issue... Unless ESRI fixes it, only workaround is to break up the process into pieces using os.spwanv, subprocess, etc.
... View more
08-04-2010
09:25 AM
|
0
|
0
|
749
|
POST
|
Woops, I guess it's not the tagged code at all, just the raw text that is affected. Anyway, it's weird that there are spaces! Maybe something to do with the line wrapping?
... View more
08-04-2010
08:53 AM
|
0
|
0
|
534
|
POST
|
I have been noticing that when you apply a code tag in the forums, sometimes random spaces are introduced in the taged code. I don't think this is user error, since I have seen it more than a few times. For example the post here: http://forums.arcgis.com/threads/9559-Python-if-...-then-Statement conatains: Contours = "\\\\Atlas\\data\\geodata\\state\\contour\\arc " Crossings = "\\\\Atlas\\data\\geodata\\state\\crossings\\a rc" Contour = "Contour.shp" Crossing = "Crossing.shp" P_L = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\La mberts_Projection\\Pts_Lines" Clip_Feature = "C:\\Daves_Stuff\\ArcPad_Data\\Standard_Layers\\Clip_Feature\\Clip_Feature.shp" I have noticed this weird placement of random spaces in the code tags of several other posts as well, for example: http://forums.arcgis.com/threads/9512-Rectangle-for-Clip_management-tool-in-arcpy Code with random spaces introduced to it is lame... P.S. Funny thing I noticed is that when composing this message, the last line of the Python code above contained no spaces, but when I preview it, there is a space in "Cl ip". This space wasn't there when I composed the message - see the attached screen shot image for proof. Seems like it's not just tagged code that is affected? Perhaps this is another sympom of using IE8?
... View more
08-04-2010
08:48 AM
|
0
|
3
|
4035
|
POST
|
Great - thanks for the error checking part - I will add that to my version. The part where the OIDs get populated: The deal is that you can't populate some fields in a fc/table like OID, Length, Area, etc. That is what the "try" is for: Loop through the fieldList, and for each field, try to populate that field (but we can't for OID, Shape, etc). However, we can popualte the ORIG_OID field (whataver its called) and other fields since they are writable. I have some other logic in there for dealing with the 10 character limitation for .dbf/.shp files, and there probably is a better way to organize that, but... Also some logic for dealing with the ORIG_OID field if the user provided a field name, otherwise don't populate it (since we never added it in the 1st place). Hope that helps...
... View more
08-04-2010
08:03 AM
|
0
|
0
|
807
|
POST
|
Rich, I will post an update to acrscripts in the next few days. So as I understand, the requirements are: 1. The user can select up to four fields to sort. 2. The user can specify a new field name that will contain the original OID prior to sorting. Sound Good?
... View more
08-03-2010
02:33 PM
|
0
|
0
|
807
|
POST
|
Looks like I will be rewriting a lot of v9.3 code to make it arcpy compatible...
... View more
08-03-2010
10:05 AM
|
0
|
0
|
1174
|
POST
|
Not sure what's wrong... Take look at the sample code: http://forums.arcgis.com/threads/9512-Rectangle-for-Clip_management-tool-in-arcpy (my post Aug 2nd @10:25). Are you sure that your raster and shapefile are using the same projection?
... View more
08-03-2010
09:18 AM
|
0
|
0
|
193
|
POST
|
Preserving the original OID is a good idea! And the .oidfieldname property is the right one to use... The output names are given the default toll name suffix by the Toolbox GUI seemingly automatically now in v9.3+ (the default naming is not handled in a controlled fashion by the script of tool parameter settings). It wasn't this way pre-v9.2, and depending on how you look at it, it can be a good or bad thing. Personally I don't like it, since it seems to override the "default" parameter values that you assign in the tool setup dialog.
... View more
08-03-2010
09:02 AM
|
0
|
0
|
807
|
POST
|
You can build a drop down box (aka picklist) via the Toolbox GUI quite easily: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Understanding_script_tool_parameters/001500000007000000/ Although I have never done it, you can also build elaborate Python GUIs via: wxPython: http://www.wxpython.org/ TkInter: http://wiki.python.org/moin/TkInter
... View more
08-02-2010
01:20 PM
|
0
|
0
|
276
|
Title | Kudos | Posted |
---|---|---|
1 | 02-13-2012 09:06 AM | |
2 | 10-05-2010 07:50 PM | |
1 | 02-08-2012 03:09 PM | |
1 | 10-31-2013 02:18 PM | |
1 | 06-20-2011 07:53 AM |
Online Status |
Offline
|
Date Last Visited |
a week ago
|