|
POST
|
mdenil, Although the Zen is enlightening, the overwrite function still won't work as needed. Is there a specific piece of code you could suggest? I'm a python novice. I think what Mark is getting at is inserting something like this before the TableToTable call to explicitly delete the table if it's already there:
tabName = srow.WATERSHED + ".dbf")
tabPath = os.path.join(outTable,tabName)
if arcpy.exists(tabPath): arcpy.Delete_management(tabPath)
arcpy.TableToTable_conversion("Points_lyr", outTable , tabName)
However, my experience is that arcpy.env.overwriteOutput seems to work fine as long as there are no outstanding file locks (ie active layers pointing to it, etc).
... View more
09-11-2012
11:28 AM
|
0
|
0
|
3482
|
|
POST
|
Hi, I have a script that writes .dbf files to a folder. The first time the script runs it does what it is supposed to. The second time I run it however, it says the first .dbf to be created already exists and stops. It's not overwriting the files. I have arcpy.env.overwriteOutput = True and had it successfully working to overwrite at one point in the development of the script. I'm not sure what made it stop working. I'm pretty sure I added the field mapping and the listing of the files in the log file after it was running smoothly but, have commented them out and it still gives me the error message. Any suggestions would be appreciated....I have no idea what is causing the problem. # Import arcpy module import arcpy, sys, traceback, time, datetime, os # Set overwrite option arcpy.env.overwriteOutput = True # INPUT NEEDED: Set Read me file workspace CURDATE = datetime.date.today() logpath = "X:\\Script\Out\ReadMe" logfile1 = logpath + str (" ") + str(CURDATE) + ".txt" if arcpy.Exists(logfile1): arcpy.Delete_management(logfile1) log1 = open(logfile1, "a") print "Generate Readme file " + str(CURDATE) print >> log1, time.strftime("%c") print >> log1, "End Processing " #Set the current workspace for input file geodatabase arcpy.env.workspace = "X:\\Script\Input.gdb" #Set Local variables specifyting the output table folder: outTable = "X:\\Script\Out" print "Start Processing" #Set a Search Cursor on the Polygons srows = arcpy.SearchCursor("Polygons", "","", "WATERSHED", "" ) srow = srows.next() print "Get Polygon" mapFields = ["ID", "STUDY", "NAME"] fieldMappings = arcpy.FieldMappings() for mapField in mapFields: fieldMap = arcpy.FieldMap() fieldMap.addInputField("Points", mapField) fieldMappings.addFieldMap(fieldMap) while srow: pid = srow.ObjectID poly_lyr = arcpy.MakeFeatureLayer_management("Polygons",'pgon_select',""" "ObjectID" = """+ str(pid)) print "Watershed is " + str(srow.WATERSHED) arcpy.MakeFeatureLayer_management("Points", "Points_lyr", "", "", ) print "Make point feature layer" arcpy.SelectLayerByLocation_management("Points_lyr", "INTERSECT", "pgon_select", "", "NEW_SELECTION") print "Select points by " + str(srow.WATERSHED) + " watershed" arcpy.TableToTable_conversion("Points_lyr", outTable , str(srow.WATERSHED)+ ".dbf","") print "Make table " + str(srow.WATERSHED) srow = srows.next() print "Next Polygon" print "Write .dbf tables to log file" print >> log1, "Files generated = " file_list = os.listdir(outTable) for file in file_list: if file.endswith (".dbf"): log1.write(file + "\n") print "End Processing" log1.close() You have neglected to close the cursor when you are done. You must do this, otherwise the cursor stays open -- and you may run into file locking on the next run. del srows Also, using a layer object ("Polygons") with a tool that is attached to an open cursor (outside of directly accessing the geometry or actions like that) is generally bad practice as you are accessing the dataset from two objects at the same time. I think it is much safer to create a list of unique watershed ids first, closing the cursor and then looping on that list. Note the "for" loop construct below. This is the best way to loop through cursors in arcpy (until 10.1 when you should use arcpy.da). #Set a Search Cursor on the Polygons srows = arcpy.SearchCursor("Polygons", "","", "WATERSHED", "" ) sheds= list() for srow in srows: sheds.append(srow.WATERSHED) del row,srows # close/delete cursor variables for shed in sheds: ... arcpy.MakeFeaturelayer_management('"WATERSHED" = \'' + shed + "'"...) ... Hope this helps.
... View more
09-11-2012
08:55 AM
|
0
|
0
|
3482
|
|
POST
|
with that extra second of execution time per added per field my geo proc just got a lot slower. I suggest creating a template table or feature class in the in_memory workspace -- the Add Fields happen very fast with no file-locking issues -- and then you can use the in_memory dataset as a template for CreateTable or CreateFeatureClass to disk.
... View more
09-11-2012
08:46 AM
|
0
|
0
|
3036
|
|
POST
|
Basically, it looks like the ArcMap GUI setting and the python setting are actually separate and both are being used. The geoprocessing environment settings read when a tool dialog is run many not always be in synch, with the application settings, but in the context of a script, the environment settings are entirely local and should override any GP settings set at the application or model or tool level. You may have better luck by specifying it as a boolean. (Easier to spell!) arcpy.qualifiedFieldNames = False
A warning: in arcpy, arcpy.env object names are case-sensitive. For example: >>> arcpy.env.QualifiedFieldNames = False # No error, but will not work
>>> arcpy.env.qualifiedFieldNames = False # will work
arcgisscripting is still there under ArcPy, so they do share environments, and setting either "gp" or "arcpy" should "take" with any tools run. I did this test with 10.1:
>>> import arcpy
>>> import arcgisscripting
>>> gp = arcgisscripting.create(9.3)
>>> gp.QualifiedFieldNames = "QUALIFIED"
>>> gp.QualifiedFieldNames
True
>>> arcpy.env.qualifiedFieldNames
True
>>> gp.QualifiedFieldNames = "UNQUALIFIED"
>>> gp.QualifiedFieldNames
False
>>> arcpy.env.qualifiedFieldNames
False
... View more
09-10-2012
01:33 PM
|
0
|
0
|
1799
|
|
POST
|
An approach you may want to try 1. Add a unique field (add a Long field, populate it with OBJECTID) 2. Copy Rows to create a standalone table 3. Sort to put the rows in the order you need 4. Tag your fields however you want ( you could do this in Excel if you don't need to batch this process ). The approach depends on how you want to tag them (top two, top three, all but smallest, etc). 5. Add a tag field to your original intersected dataset, join your original intersected dataset to your table and copy over tags for use with Eliminate or whatever tool you want.
... View more
09-10-2012
01:12 PM
|
0
|
0
|
795
|
|
POST
|
The user that reported this issue could solve it by resetting their user profile. After doing this the error popup stopped appearing. 1. Close all ArcGIS desktop applications 2. Rename the folder "%APPDATA%\ESRI" to ESRI_old
... View more
09-10-2012
01:06 PM
|
0
|
0
|
1082
|
|
POST
|
Is this a raster layer? If so, this is a bug I have logged, reportedly fixed in 10.1 SP 1. [#NIM066368 Remove Join tool fails when the input is a raster with a joined field.] http://support.esri.com/en/bugs/nimbus/role/beta10_1/TklNMDY2MzY4
... View more
09-10-2012
12:36 PM
|
0
|
0
|
3469
|
|
POST
|
Has anyone seen this error message when trying to start a Python script tool? An error has occurred in the script on this page. Access is denied. file:///c:/Users/username/AppData/Roaming/ESRI/Desktop10.1/ArcToolbox/Dlg / MdDlgContent.htm [ATTACH=CONFIG]17585[/ATTACH] After you select OK the script tool opens and the tool executes fine.
... View more
09-10-2012
12:33 PM
|
0
|
2
|
1536
|
|
POST
|
This is a question for the geoprocessing forum, but I'll go ahead and try to answer it here. ModelBuilder run order is controlled by the processing chain of inputs and outputs. For example, if you connect the output of one tool as input into another tool, the tools will run in the proper order. In situations where there is some ambiguity as to the tool run order, you can use "preconditions" to control the sequence. This is described in the help - just search for "precondition". As for your licensing question, that's a question for the ArcGIS Desktop - Installation/Configuration forum. Your license level should not be modified by an update from 10.0 to 10.1. Hope this helps.
... View more
09-10-2012
11:35 AM
|
0
|
0
|
1604
|