|
POST
|
Okay your right... a better way: selectedCount = len([int(fid) for fid in arcpy.Describe(layerName).fidset.split(";") if fid != ''])
... View more
11-18-2013
01:05 PM
|
0
|
0
|
1960
|
|
POST
|
Also, the Union tool with the NO_GAPS option along with a subsequent Dissolve will also fill gaps in polygons.
... View more
11-15-2013
01:28 PM
|
0
|
0
|
3673
|
|
POST
|
You also could use a wildcard(s) to denote the keeper group. Also a demo of a practical use of the Python set() object. keeperString = "*_t"
keeperFcSet = set(arcpy.ListFeatureClasses(keeperString))
allFcSet = set(arcpy.ListFeatureClasses())
delFcSet = allFcSet.difference(keeperFcSet)
for delFc in delFcSet:
try:
arcpy.Delete_management(delFc)
except:
print "Can't delete " + str(delFc)
... View more
11-15-2013
07:33 AM
|
0
|
0
|
708
|
|
POST
|
How about something like: Traffic_Islands = "Island+Kerb Topology\\Traffic_Islands"
Kerb_Channel = "Island+Kerb Topology\\Kerb_Channel"
class ButtonClass1(object):
"""Implementation for SetKerbType_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
if len(arcpy.Describe(Traffic_Islands).fidset.split(";")) > 0:
arcpy.CalculateField_management(Traffic_Islands, "KERB_TYPE", "\"SM3\"", "VB", "")
else:
#tell the user they are doing something wrong
if len(arcpy.Describe(Kerb_Channel).fidset.split(";")) > 0:
arcpy.CalculateField_management(Kerb_Channel, "KERBTYPE", "\"SM3\"", "VB", "")
else:
#tell the user they are doing something wrong
... View more
11-12-2013
02:26 PM
|
0
|
0
|
1960
|
|
POST
|
Did you try deleting the exsting normal.gxt and normal.mxt templates (BTW: These typically ARE NOT recreated when you upgrade/reinstall). Usually I always delete and my entire user profile if I upgrade ArcGIS and/or have the need to use the same profile to run ArcGIS on a local install and a remote box like Citrix or a Remote Desktop.
... View more
11-12-2013
01:59 PM
|
0
|
0
|
1092
|
|
POST
|
Another option is to just use a dictionary... this way there is no dependency on 3rd party modules. Although I admit I need to check out pandas as it seems pretty cool. The dictionary option though is a built-in, simple, and powerful one, and can be made to be quite robust with not a lot of code. A very simple example: valueDict = {r[0]:[r[1],r[2]] for r in arcpy.da.SearchCursor(myFC, ["OID@","ID","NAME"])}
#add/calc a new "field" that is float(OID - 1) * OID
for key in valueDict:
valueDict[key].append(float(key -1) * key) However, the real power comes from building RDBMS-like table structures, and being able to run complex queries (especially recursive ones) crazy fast. Adding calcing fields via Dictionaries or Numpy Arrays (pandas) will be orders of magnitude faster than any ESRI table/tool - even in the in_memory workspace. Clinton, how many records are you dealing with here... 23 hours seems a bit over the top.
... View more
11-06-2013
08:07 AM
|
0
|
0
|
609
|
|
POST
|
It depends... Some operations (such as AddField or CalculateField) can operate directly on the in_memory table. Other operations (such as Frequency or SummaryStatistics) create a new output table that, depending on your specifications, may be written to either the in_memory workspace or to disk. That said, reading input from in_memory and then writting the output to in_memory would of course be the fastest option you have. Only worry is if you have enough available RAM to complete the process(es)...
... View more
11-04-2013
01:41 PM
|
0
|
0
|
3630
|
|
POST
|
How about just leaving the field values (aka the dictionary values) as a tuple? It'd be slightly faster and more memory efficient that way... Unless you need to change the values in place (have the field values be mutable), I'd go with a tuple. def makeFeatureDict(myFC, keyField, fields):
cursorFields = [keyField] + fields
valueDict = {r[0]:r[1:] for r in arcpy.da.SearchCursor(myFC, cursorFields)}
del cursorFields
return valueDict Also, I was curious about performace and memory use metrics for this (tuple vs list), so I ran a little test: ... 2.1 million records and 4 value fields (one as the key) ... reporting on average time and RAM use for 3 runs of each method tuple method 23 sec @404,000k memory use list method 27 sec @455,000k memory use
... View more
11-01-2013
01:48 PM
|
0
|
0
|
2117
|
|
POST
|
Is there a way to pause the map update (using code) that I can incorporate in my script? Not a direct way to do this I think, but how just turning the layers off until the script is done executing? A related post: http://forums.arcgis.com/threads/94756-Use-Arcpy-to-Unselect-the-currently-selected-Features-in-all-layers?p=338920&viewfull=1#post338920
... View more
11-01-2013
08:39 AM
|
0
|
0
|
2365
|
|
POST
|
It'd look something like this I think - see how for each loop of the search cursor, the data (the searchRow tuple) gets fed dirtectly to the insertRow? import arcpy inputTbl = r"C:\Users\cc1\Desktop\NEW.gdb\WAYNE" outputTbl = str(arcpy.CreateTable_management("in_memory", "WAYNE").getOutput(0)) arcpy.AddField_management(outputTbl, "SOS_VOTERID","TEXT", field_length=25) arcpy.AddField_management(outputTbl, "FEAT_SEQ","LONG") insertRows = arcpy.da.InsertCursor(outputTbl, ["SOS_VOTERID","FEAT_SEQ"]) searchRows = arcpy.da.SearchCursor(inputTbl, ["SOS_VOTERID","FEAT_SEQ"]) for searchRow in searchRows: insertRows.insertRow(searchRow) del searchRow, searchRows, insertRows
... View more
10-31-2013
04:40 PM
|
0
|
0
|
3630
|
|
POST
|
The way I get it, all the SA commands now generate a scratch raster in whatever workspace you have defined using arcpy.env.workspace. The scratch name is auto generated and my understanding is that there is no way to directly control it. Upon doing a .save() the scratch raster is renamed (and even reformatted if you specify a file extention) to your specified name and made to be permanant... Are you saying that upon running .save('my_name'), your raster will not retain the name you gave it?
... View more
10-31-2013
03:42 PM
|
0
|
0
|
2333
|
|
POST
|
I could be wrong, but I think the issue is this line: outExtractByMask.save(IntermediateFiles+"\\fp_1") As I recall, the .save() doesn't allow you to "move" the output raster to a different workspace than what arcpy.env.workspace is set to... Rather it simply "renames and makes permanent" the scratch raster. So your code would have to be just outExtractByMask.save("fp_1") ...and the "fp_1" grid would be saved in where ever arcpy.env.workspace is set to at the time.
... View more
10-31-2013
02:30 PM
|
0
|
0
|
2333
|
|
POST
|
Use the sum() function. For example: zonePolys = arcpy.ListFeatureClasses("Zone*")
for fc in zonePolys:
arcpy.AddField_management(fc,"SumOfValues","LONG")
arcpy.MakeFeatureLayer_management("OriginalLayer", "OriginalLayer_Lyr")
arcpy.SelectLayerByLocation_management("OriginalLayer_Lyr","INTERSECT",fc)
someValue = sum([r[0] for r in arcpy.da.SearchCursor("OriginalLayer_Lyr",["FIELD_NM"])])
arcpy.CalculateField_management(fc,"SumOfValues",someValue) #haha get it...
... View more
10-31-2013
02:18 PM
|
1
|
0
|
2811
|
|
POST
|
Update: Dictionary comprehensions now suported in Python 2.7, so an updated syntax would look like: valueDict = {r[0]:(r[1],r[2]) for r in arcpy.da.SearchCursor(myFC, ["OID@","ID","NAME"])}
... View more
10-31-2013
01:58 PM
|
0
|
0
|
2117
|
|
POST
|
I like sets a lot. Most people just use them for calculating unique values, but the real power is in using the set()'s union, intersect, difference, etc. functions... Extreemly fast and efficient! One practical example I use this for is I have this large polygon layer I need to convert to raster in order to get elevation and slope values (from a DEM) using zonal statsistics. A number of the polygons (20% or so) are too small to be converted to a raster, and for those, I still need to get spot elevation and slope values for the centroids via the Sample tool. Basically I make a set for the OIDs for all my original polygons, and another set for the VALUEs of the raster version (which are the OIDs that "made it" to the raster). Now I need to figure out what polygons I must convert to centroids (so as to run the sample tool). BTW: Dealing with 2.5 million polgons. For example: >>> set1 = set((1,2,3,4,5,6,7,8,9,10)) #all the OIDs in the polygon layer >>> set2 = set((1,2,3,7,8,9)) #the OIDs that made it to the raster layer >>> print set1.difference(set2) set([10, 4, 5, 6]) #The polygon OIDs that I need to derive centroids for and then use the Sample tool on
... View more
10-31-2013
01:37 PM
|
0
|
0
|
1501
|
| 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
|