|
POST
|
I'd also recommend changing your environment settings to a larger XY tolerance. I usually set it anywhere from 0.1-5 Meters, but that entirely depends on the resolution you want from the output. Another thing you could try is compacting your FGDB (not compress) sometimes may help clear up phantom problems like this.
... View more
04-12-2012
11:03 AM
|
0
|
0
|
6544
|
|
POST
|
This post could easily be called "How I fell in love with dictionaries" Drawing the idea from this post http://forums.arcgis.com/threads/52511-Cool-cursor-dictionary-constructor-one-liner I've come up with a solution to a nagging problem I know I have been having, and I believe some others have as well, of not being able to reliably use an update cursor when dealing with joined tables. I was really happy with my first foray into dictionaries, and I thought I'd share my work around for anyone looking to optimize some tedious processing with joins. My data was ~900k rows of forest stand data in one table, and a strata reference table of ~50 rows to calculate volumes. My previous method of using a permanent JoinField, processing, then deleting those fields, took approximately 3.5 hours. Temporary joins never worked for me in the manner I needed. Using dictionaries instead of joins, that time was reduced to under 15 minutes. This code goes through any table and creates a list of field names for every field other than OID and the key field you want to reference. Here is the fairly complete code to create the dictionary print "Starting function" # Define and setup variables, tables, key field etc calc_table = arcpy.MakeTableView_management(table_path) vol_tab = join_table_path strata_tab = "in_memory/temp" arcpy.MakeTableView_management(vol_tab, strata_tab) joinField = "STRATA" # Create list of value fields, leaving out OID field and key/join field flistObj = arcpy.ListFields(strata_tab) flist = [] for f in flistObj: if f.type != "OID" and f.name != joinField: flist.append(f.name) # Create empty dict object then populate each key with a sub dict by row using value fields as keys strataDict = {} for r in arcpy.SearchCursor(strata_tab): fieldvaldict = {} for field in flist: fieldvaldict[field] = r.getValue(field) strataDict[r.getValue(joinField)] = fieldvaldict del strata_tab, flistObj In the update cursor you can then either explicitly reference dictionary objects like this rows = arcpy.UpdateCursor(calc_table, "\"%s\" IS NOT NULL" % joinField) for row in rows: strata = row.getValue(joinField) variable = strataDict[strata]["sub_key_field"] What I did was use a reference list to reference the dictionary to keep things legible, and so I could remember what went where. This may not even be necessary for some people, but it helped me conceptually. Without getting in to too much detail, here's essentially my update cursor sans the actual calculations. species = [ ("C","Fb","FB_STEMS"),("C","Sw","SW_STEMS"),("C","Pj","PJ_STEMS"), # 0,1,2 ("C","Pl","PJ_STEMS"),("C","Lt","LT_STEMS"),("C","Sb","SB_STEMS"), # 3,4,5 ("D","Bw","BW_STEMS"),("D","Aw","AW_STEMS"),("D","Pb","PB_STEMS") # 6,7,8 ] sp_fields = [("SP1","SP1_PER"),("SP2","SP2_PER"),("SP3","SP3_PER"), ("SP4","SP4_PER"),("SP5","SP5_PER")] print "Beginning updates" rows = arcpy.UpdateCursor(calc_table, "\"%s\" IS NOT NULL" % joinField) for row in rows: strata = row.getValue(joinField) for sp, per in sp_fields: sp_type = row.getValue(sp) spp_f = float(row.getValue(per)) if spp_f > 0: for grp, spec, stem in species: stem_f = strataDict[strata][stem] (...) Hopefully that didn't get too convoluted, anyone else have anything that might contribute in terms of optimization?
... View more
04-12-2012
09:24 AM
|
1
|
14
|
9899
|
|
POST
|
Enumerations from what I understand are an obsolete (in python) method of accessing data. Back when enumerations were popular I hadn't even heard of python yet, so I'm afraid I won't be much use.
... View more
04-10-2012
01:53 PM
|
0
|
0
|
1444
|
|
POST
|
Some sample data/screen shots would help with next steps, without knowing details, my best guess would be to do something like this. Get a list of contracts, export to shapefile with a where clause of each contract possibility and export to shapefile. Code example, untested. fc = "C:/GIS/test.shp"
contracts = ["A", "B", "C"]
for cont in contracts:
where = "contractfield like '%"+i+"%'"
arcpy.FeatureClassToFeatureClass_conversion(templayer, exportdir, "somename"+cont+".shp", where)
... View more
04-10-2012
12:52 PM
|
0
|
0
|
2332
|
|
POST
|
You never mentioned what version of ArcGIS/Python you are using. You need to set a workspace first. You set a folder path (I presume) in the wildcard parameter. See the help for info on how to use correct syntax. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=ListWorkspaces_method
... View more
04-10-2012
05:51 AM
|
0
|
0
|
1444
|
|
POST
|
I believe you are looking for something like this. import arcpy
fields = arcpy.ListFields(<your_layer>)
field_text = list()
for f in fields:
if fields.type != "Geometry":
field_text.append(f.name)
arcpy.ExportXYv_stats(<your_layer>,field_text,"COMMA","C:/GIS/Exports/test2.asc","ADD_FIELD_NAMES")
... View more
04-10-2012
05:16 AM
|
0
|
0
|
1843
|
|
POST
|
Have you explored the possible causes of the error you are getting? http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00vq0000000n010029.htm
... View more
04-09-2012
02:10 PM
|
0
|
0
|
5996
|
|
POST
|
After two reboots it works, exactly as I executed it before and got an error. Ghost in the machine I guess.
... View more
04-04-2012
10:09 AM
|
0
|
0
|
771
|
|
POST
|
Does killing the PyScripter.exe process or rebooting solve the issue? And does the memory being held by the process release after you delete your in memory workspace or does it persist?
... View more
04-04-2012
10:03 AM
|
0
|
0
|
1042
|
|
POST
|
Are you executing this through IDLE? If so, does killing the process solve the issue? Is memory not being release after each run?
... View more
04-04-2012
09:49 AM
|
0
|
0
|
1042
|
|
POST
|
Just to clarify. A personal geodatabase is an .mdb file, a file geodatabase is a .gdb. You can try getting the feature class describe instead of layer using this, see if that works. desc = Describe(myLyr.dataSource) Edit: If you do want to get the layer describe you can do this. MakeFeatureLayer_management(myLyr, "describe_me")
desc = Describe("describe_me")
... View more
04-04-2012
09:34 AM
|
0
|
0
|
2006
|
|
POST
|
I am writing a standalone python script (i.e not within arcmap) that attempts to extract the coordinates of selected features (as they appear selected in the current map document). The commands that make up my script (see below) work fine if I execute them within the python window in arcmap but not when I try to use them within a standalone script. mxd= mapping.MapDocument(r'c:\GIS\project\map.mxd) myLyr= mapping.ListLayers(mxd, 'features')[0] desc= Describe(myLyr) NB. 'features' is the name of a point feature layer. The datasource of this layer is within a personal geodatabase i.e. within test.gdb. The script blows us when it gets to the last command in spite of the fact that myLyr is indeed a layer (I checked this when debugging). I cannot think of what I am doing wrong so any help will be appreciated. thanks marc You have no closing single quote in your mxd line, so this should be a syntax error and not run at all.
... View more
04-04-2012
08:58 AM
|
0
|
0
|
2006
|
|
POST
|
You can use Eliminate Polygon Part Or Multipart to Singlepart and delete or definition query out the smaller islands.
... View more
04-04-2012
08:00 AM
|
0
|
0
|
5313
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-17-2011 10:36 AM | |
| 1 | 08-16-2012 10:48 AM | |
| 1 | 10-31-2012 08:39 AM | |
| 1 | 07-16-2012 01:52 PM | |
| 1 | 03-15-2012 10:57 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-22-2024
11:12 PM
|