|
POST
|
Soemthing like this would work: import string
fieldValue = "ML-26588"
for character in fieldValue:
if character in string.ascii_letters or character in string.punctuation:
fieldValue = fieldValue.replace(character, "")
print fieldValue I think it would be better to use something like this in an update cursor though... Somthing like:
#Removes all letters and special characters from a string - hopefully leaving only numbers.
import string, arcpy
updateRows = arcpy.UpdateCursor(myFC)
for updateRow in updateRows:
fieldValue = updateRow.MY_FIELD
for character in fieldValue:
if character in string.ascii_letters or character in string.punctuation:
fieldValue = fieldValue.replace(character, "")
updateRows.updateRow(updateRow)
del updateRow, updateRows
... View more
11-15-2012
03:30 PM
|
0
|
0
|
9062
|
|
POST
|
...and to exclude any Nulls in the lookup table I think could look like this: lookupIds = [r.MY_ID for r in arcpy.SearchCursor(lookupTbl) if r.MY_ID != None]
arcpy.MakeFeatureLayer_managment(parentFC, "lyr", "MY_ID in (" + str(lookupIds)[1:-1] + ")")
... View more
11-14-2012
03:27 PM
|
0
|
0
|
2928
|
|
POST
|
You are on the right track Nathan. You code would be much more efficient if it was structured something like this: #Returns a feature layer composed of the features in 'parentFC' that
#share the same "MY_ID" values as those in 'lookupTbl'
lookupIds = [r.MY_ID for r in arcpy.SearchCursor(lookupTbl)]
arcpy.MakeFeatureLayer_managment(parentFC, "lyr", "MY_ID in (" + str(lookupIds)[1:-1] + ")")
... View more
11-14-2012
03:19 PM
|
0
|
0
|
2928
|
|
POST
|
BTW: I have heard that the .da cursors are similar to the way the ArcObjects cursors behave (with an index).
... View more
11-13-2012
09:39 AM
|
0
|
0
|
547
|
|
POST
|
Yep - I had the same complaint when I started messing around with the da cursors: What happened to .getValue and .setValue? How are you supposed to reference the field names? updateRow[updateRows.fields.index("FIELD_NAME")]) was the best replacement I could come up with... Maybe a bit longer code wise, but that's okay. Maybe it'd be better to have a little function fetch the index, but... Why a tuple? I don't know, but I have found it to be quite nice for a lot of things, such as direct table to dictionary conversion and data conversion. It's nice to have the row values be a an iterable data type. Took me a while to appreciate it (just like the v10.0 MapAlgebra syntax), but now that I get it, I like it way better.
... View more
11-13-2012
08:37 AM
|
0
|
0
|
2459
|
|
POST
|
Use the .fields property (a property of the .da cursor). It gives you a tuple of the field names returned by the cursor... Then use the .index property of the .fields tuple. For example: updateRows = arcpy.da.UpdateCursor(myTable,["*"])
for updateRow in updateRows:
updateRow[updateRows.fields.index("BASIN_NAME")] = "Basin "+ str(updateRow[updateRows.fields.index("BASIN_ID")]) I found that using the .fields property like this is no slower (well maybe a teeny bit) than just using the index to set/retreive the field value... even for millions of records. Like less than a second differance... In my opinion, the .da cursors are the best thing since slided bread.
... View more
11-08-2012
06:47 PM
|
0
|
0
|
2459
|
|
POST
|
BTW: in v10.1 there are no more .prj files, and you need to track down the projection codes (the prj code for WGS84 is 4326). So that would be the Spatial reference code you could use in the cursor provided you wanted to return WGS84 coordinates. You can also use the SR name, but good luck tracking down which SR "name" is the correct one (is it "WGS 84" or "GCS_WGS_1984"). Also, unless I am mistaken, the cursor SR parameter doesn't allow for datum transformations, so things could be off by quite a bit. Safe method: 1. Project your centroid points (using the appropriate datum transformation) 2. Read the coordinates in a search cursor
... View more
10-31-2012
01:03 PM
|
0
|
0
|
9809
|
|
POST
|
I don't think you can get a hook into the realtime tool messages. However... Maybe the feature it appears to be hanging on is just a large feature that requires extra time to process? If you look at this feature (probably has the same OBJECTID field value as the message indicates), is there something unusual about it? How many verticies does it have? The TaskManger can be a useful tool in diagnosing things like this. While the tool appears to hang, what is going in parent process (ArcMap.exe if you are calling the tool from that application). Is the processor or RAM usage fluctuating? Do you see the read and/or write bytes increasing? How long will the tool run if you don't cancel it? Also, if the tool is indeed hanging, would your script do something else (like try an alternate tool, or use a modified tool parameter)? While it may be more complex than you are wanting to do, you could accomlish a sort of "time out" process by using the "subprocess" module.
... View more
10-22-2012
08:21 AM
|
0
|
0
|
1667
|
|
POST
|
I don't think there is a way to return the messages in "real time"... but you could do something like: print "Attempting to Clip..."
arcpy.Clip_analysis(...)
print "Clip completed..." or try:
arcpy.Clip_analysis(...)
except:
print "Clip failed!" What leads you to believe the tool is hanging vs. just taking a long time?
... View more
10-19-2012
01:09 PM
|
0
|
0
|
1667
|
|
POST
|
I use arcpy.GetMessages() #returns all messages (messages, errors, warnings, etc) Take a look at the documentation: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000000p000000.htm
... View more
10-19-2012
08:24 AM
|
0
|
0
|
1667
|
|
POST
|
Another possibly related virus scan issue: http://forums.arcgis.com/threads/25406-Zonal-Statistics-Crashes-Randomly?p=240540&viewfull=1#post240540
... View more
10-13-2012
09:48 AM
|
0
|
0
|
2877
|
|
POST
|
after turning Microsoft Security Essentials "Real Time Protection" off I am starting to see a reoccuring problem here! http://forums.arcgis.com/threads/66584-repeated-AddField-operations-fails-in-10.1-works-in-10.0 Hope this issue is on ESRI's radar... And BTW it's not just Microsoft virus scan software... I've experienced this 1st on McAfee and now (after switching to Symantec since that initially fixed the problem), Symantec as well... Symptom: ArcGIS tools randomly failing when run in a loop or in rapid repeated calls
... View more
10-13-2012
09:43 AM
|
0
|
0
|
1398
|
|
POST
|
Here is an actual example, and also some notes: 1. This method is WAY faster if you can use the data access cursors (new in v10.1)... Like about 20x faster! 2. As Duncan said, you may indeed run out of 32-bit memory with 7.5 million rows. I've experienced this... Remember that ints take up less RAM than floats way way less than strings.... especially long strings. 3. Unlike the example below, it would be way more compact to make just one dictionary and for each look up table, append to the attribute tuple/list that each key is pointing to... No need to have duplicate keys if only one key is required. #Process: Build dictionaries of the basin size stats that we can then use in an update cursor - faster than join/calc
message = "Populating BASIN_SIZE_DICT..."; showPyMessage()
basinSizeDict = dict([(r.VALUE, (r.MIN, r.MAX, int(r.MEAN + .5))) for r in arcpy.SearchCursor(flowAccZoneStatTbl)]) #Int
message = "Populating SLOPE_DICT..."; showPyMessage()
slopeDict = dict([(r.VALUE, (r.MIN, r.MAX, int(r.MEAN + .5))) for r in arcpy.SearchCursor(slopePctZoneStatTbl)]) #Int
message = "Populating CURVE_PLAN3_DICT..."; showPyMessage()
curvePlan3Dict = dict([(r.VALUE, (r.MEAN)) for r in arcpy.SearchCursor(curvePlan3ZoneStatTbl)]) #Float
message = "Populating ELEV_DICT..."; showPyMessage()
elevationDict = dict([(r.VALUE, (r.MIN, r.MAX, int(r.MEAN + .5))) for r in arcpy.SearchCursor(elevationZoneStatTbl)]) #Int
#Process: Blah blah
##...State Secrets...
#Process: Update the streamFC table
message = "Updating stream table..."; showPyMessage()
updateRows = arcpy.UpdateCursor(streamFC)
for updateRow in updateRows:
streamIdValue = updateRow.STREAM_ID
if streamIdValue in outFlowStreamLinkList:
updateRow.OUT_FLG = 1
else:
updateRow.OUT_FLG = -1
updateRow.TILE_NO = int(areaId)
updateRow.SUB_NET = streamNetworkIdDict[streamIdValue]
updateRow.ACRE_MIN = basinSizeDict[streamIdValue][0] * cellSize ** 2 / 43560 #SQ FEET TO ACRES
updateRow.ACRE_MAX = basinSizeDict[streamIdValue][1] * cellSize ** 2 / 43560 #SQ FEET TO ACRES
updateRow.ACRE_MEAN = basinSizeDict[streamIdValue][2] * cellSize ** 2 / 43560 #SQ FEET TO ACRES
del basinSizeDict[streamIdValue]
updateRow.ELEV_MIN = elevationDict[streamIdValue][0]
updateRow.ELEV_MAX = elevationDict[streamIdValue][1]
updateRow.ELEV_MEAN = elevationDict[streamIdValue][2]
del elevationDict[streamIdValue]
updateRow.SLOPE_MIN = slopeDict[streamIdValue][0]
updateRow.SLOPE_MAX = slopeDict[streamIdValue][1]
updateRow.SLOPE_MEAN = slopeDict[streamIdValue][2]
del slopeDict[streamIdValue]
updateRow.PCRV3_MEAN = curvePlan3Dict[streamIdValue]
del curvePlan3Dict[streamIdValue]
updateRows.updateRow(updateRow)
del updateRow, updateRows
message = "Done updating stream table!"; showPyMessage()
... View more
10-10-2012
04:57 PM
|
0
|
0
|
5418
|
|
POST
|
My work around was to use .da cursors on the Grid vat directly, but load the records into a list, and then sort the list. Even though I have to load the entire table into the list with the .da cursor and then sort it in list format (since the .da cursor sort paramter won't work with a Grid vat table), it is still 4x as fast as using the traditional arcpy cursors. Okay I'm happy - even if the .da cuirsors won't (by themselves) sort a Grid vat. #make sure the fields are specified in the proper list sort order - luickily I want to sort everything ascending sortRows = [r for r in arcpy.da.SearchCursor(comboGrd, ["PDRND","HAB", "COUNT"])] sortRows.sort() for sortRow in sortRows: blah... blah...
... View more
10-10-2012
10:35 AM
|
0
|
0
|
634
|
|
POST
|
Features are only dissolved (into a single feature) if their unique value combinations of the fields you specify are the same. Review the Dissolve tool documentation: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000005n000000
... View more
10-10-2012
09:03 AM
|
0
|
0
|
13655
|
| 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
|