|
POST
|
I am trying to identify the current user folder as part of a larger process. I am using the code from os.path import expanduser HOME = expanduser("~") If I run the script in the foreground the result is: print HOME 'C:\Users\jlay' However if I enable background processing the result is print HOME 'H:\' Can someone tell me why that is? And how to correct it?
... View more
06-17-2014
10:48 AM
|
0
|
2
|
1014
|
|
POST
|
That doesn't release the database either. Argh! this is completely frustrating! I guess ultimately it doesn't really matter. I've inserted a try statement before the delete code (which is the very last process) to bypass the error and complete the script. The zips are created, which is really all I need. I can manually delete the garbage. I just wish I knew what was causing the issue. Like I said previously, leaving the S_POL_ARTable searchcursor business out COMPLETELY resolves the problem. I just I could figure out what it was about that section of code that causes the issue.
... View more
04-22-2014
07:51 AM
|
0
|
2
|
7486
|
|
POST
|
the delete database is part of the same process. The bit of code that deletes makes a list (Delete_Shapes) of all the *.shp and *.gdb in the directory. Then, it runs through the list using a for loop and deletes each object. # Delete Files
Delete_Shapes = []
for shapefile in os.listdir(OUTPATH):
if fnmatch.fnmatch(shapefile, '*.shp'):
Delete_Shapes.append(shapefile)
elif fnmatch.fnmatch(shapefile, '*.gdb'):
Delete_Shapes.append(shapefile)
else:
pass
del shapefile
for shapefile in Delete_Shapes:
get_file = os.path.join(OUTPATH, shapefile)
arcpy.AddMessage("Deleting " + shapefile)
arcpy.Delete_management(get_file) In the code above, OUTPATH is the root directory, not the database itself.
... View more
04-22-2014
06:09 AM
|
0
|
0
|
7486
|
|
POST
|
Yeah... arcpy.env.overwriteOutput = True didn't work either.
... View more
04-22-2014
05:53 AM
|
0
|
0
|
7485
|
|
POST
|
Thanks James, I'll try env.overwrite. In answer to your other question, yes, I'm trying to delete the entire database after it has been zipped. We zip the data so that they are easily deliverable to FEMA, engineers, public, etc. After they are zipped, I don't need the database or shapes anymore because the master statewide files are stored in SDE--the the script exports FIRM data by county. I didn't think that bit of code should have anything to do with the delete error either. Which is precisely why I've been scratching head for the last two days. It's just weird. Nonetheless, when i strip the script of that bit of code, the files zip and then get deleted without issue. With the code, the geodatabase is locked by RuntimeLocalServer.exe.
... View more
04-22-2014
05:19 AM
|
0
|
0
|
7485
|
|
POST
|
Yes, that was the first thing I tried. I haven't been able to find anything that will release the database programmatically. There are no .LOCK files in the database, yet arc seems to think that it is still in use. I can't even delete the database in Catalog outside of the script. I have to exit completely first.
... View more
04-22-2014
02:37 AM
|
0
|
0
|
7485
|
|
POST
|
I've written a long script that selects a bunch of different feature classes and exports them to a file geodatabase by an attribute. Then I export those feature classes to shapefiles. Next, I zip the geodatabase into its own file and all the shapes into their own file. Finally, I delete the geodatabase and shapes so that all I'm left with is the 2 zip files (We do this for a FEMA product) in the output folder. No problems. Recently I learned that I needed to include several tables in the database as well, so I inserted some code that searches one table for an attribute and writes the output to a list. Then I use that list to query ANOTHER table to create a table in the database. The problem is, now with this new bit of code, the geodatabase will not delete and I receive ExecuteError: ERROR 000601: Cannot delete C:\~Working\FRIS\Test2\Alamance\NCFlood_Prelim_Alamance_GDB.gdb. May be locked by another application. Failed to execute (Delete). New bit of code: # L_COMM_INFO
CIDList = []
S_POL_AR = os.path.join(FRIS_FGDB, "S_POL_AR")
S_POL_ARTable = arcpy.SearchCursor(S_POL_AR)
for ID in S_POL_ARTable:
FIELD = "CID"
Val = ID.getValue(FIELD)
CIDList.append(Val)
NewCIDList = list(set(CIDList))
L_COMMUNITY_INFO = "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.L_COMMUNITY_INFO"
L_COMMUNITY_INFOView = os.path.join(FRIS_FGDB, "L_COMM_INFOView")
L_COMMUNITY_INFOTable = os.path.join(FRIS_FGDB, "L_COMM_INFO")
arcpy.TableToTable_conversion (L_COMMUNITY_INFO, FRIS_FGDB, "L_COMM_INFO")
arcpy.TruncateTable_management (L_COMMUNITY_INFOTable)
arcpy.MakeTableView_management (L_COMMUNITY_INFO, L_COMMUNITY_INFOView)
for ITEM in NewCIDList:
CLAUSE = ("{0} = '{1}'".format ("CID", ITEM))
arcpy.SelectLayerByAttribute_management (L_COMMUNITY_INFOView, "NEW_SELECTION", CLAUSE)
arcpy.Append_management (L_COMMUNITY_INFOView, L_COMMUNITY_INFOTable)
arcpy.Delete_management (L_COMMUNITY_INFOView, "")
del L_COMMUNITY_INFOTable The delete code looks like this: # Delete Files
Delete_Shapes = []
for shapefile in os.listdir(OUTPATH):
if fnmatch.fnmatch(shapefile, '*.shp'):
Delete_Shapes.append(shapefile)
elif fnmatch.fnmatch(shapefile, '*.gdb'):
Delete_Shapes.append(shapefile)
else:
pass
del shapefile
for shapefile in Delete_Shapes:
get_file = os.path.join(OUTPATH, shapefile)
arcpy.AddMessage("Deleting " + shapefile)
arcpy.Delete_management(get_file) The error occurs every time with the new code and never without. When I use Unlocker.exe to unlock and delete the folder so that I can start all over again, I am told that RuntimeLocalServer.exe is the process locking the database. What is wrong with the new bit of code that causes the RuntimeLocalServer lock? And how do I fix it?
... View more
04-21-2014
04:52 PM
|
0
|
15
|
21387
|
|
POST
|
Wayne, you were correct. My error was actually that one of the feature classes did not contain the "CO_FIPS" field. I missed it because the export was already produced in an earlier process.
... View more
04-21-2014
05:37 AM
|
0
|
0
|
599
|
|
POST
|
I'm extremely confused. I set up a loop to select features by attribute from a list of feature classes. The script runs completely through the list doing exactly what it's supposed to do. But then I receive and invalid expression error. Messages: Selecting by COFIPS Selecting S_POL_AR Selecting S_COMMUNITY_GROUP Selecting V_P_FLD_HAZ_AR Selecting V_P_FLD_HAZ_LN Selecting V_P_HYDRAMODEL Failed script FRISGeodatabasev12... Traceback (most recent call last): File "\\Ncemjfhqfs01\gtm\GIS\GTM_GIS_Tools\Scripts\FRISGeodatabase_v1.2.py", line 260, in <module> arcpy.SelectLayerByAttribute_management (featurelayer, "NEW_SELECTION", CLAUSE) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). The cod is as follows: PrelimSelectByCOFIPS = ["Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.BASE\NC_FLOOD.DBO.S_POL_AR", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.BASE\NC_FLOOD.DBO.S_COMMUNITY_GROUP", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.FLOOD\NC_FLOOD.DBO.V_P_FLD_HAZ_AR", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.FLOOD\NC_FLOOD.DBO.V_P_FLD_HAZ_LN", "Database Connections\NC_FLOOD.sde\NC_FLOOD.DBO.FLOOD\NC_FLOOD.DBO.V_P_HYDRAMODEL"]
# Select Features by COFIPS
arcpy.AddMessage("Selecting by COFIPS")
CLAUSE = ('{0} = {1}'.format ("CO_FIPS", COFIPS))
for feature in PrelimSelectByCOFIPS:
outfeaturename = string.join(feature.rstrip().split('.')[-1:],'.')
arcpy.AddMessage("Selecting " + outfeaturename)
featurelayer = os.path.join(FRIS_FGDB, outfeaturename + "_layer")
COFIPSfeature = os.path.join(FRIS_FGDB, outfeaturename)
arcpy.MakeFeatureLayer_management(feature, featurelayer)
arcpy.SelectLayerByAttribute_management (featurelayer, "NEW_SELECTION", CLAUSE)
arcpy.CopyFeatures_management(featurelayer, COFIPSfeature)
arcpy.Delete_management(featurelayer) I have the exact same loop set up two other times before this in the script to select by location and to clip by selected feature and neither of those give me any issue. What is going on here?
... View more
04-21-2014
04:34 AM
|
0
|
2
|
755
|
|
POST
|
OK, looking at the support page for Error: 000732: Dataset does not exist or is not supported it suggests to turn off background processing. That worked. Any clue to why that would be? My previous question is still valid, however. Is there a better way to handle xlsx spreadsheets?
... View more
02-18-2014
09:42 AM
|
0
|
0
|
942
|
|
POST
|
I've stumped IT. Most of the folks here in the office still live in the spreadsheet world which means that the table I'm trying to access is updated frequently--yet they still want maps created from the spreadsheets. Is there a better way to handle an .xls table than TableToTable conversion? I've tried to create an ODC connection to an Access database that is linked to the table, but because the tables are linked, instead of imported into the .accdb, they don't show up.
... View more
02-18-2014
09:34 AM
|
0
|
0
|
942
|
|
POST
|
You're right. It must be something different with my system. The script works fine everywhere else. Checking with IT now.
... View more
02-14-2014
07:20 AM
|
0
|
0
|
942
|
|
POST
|
Having a weird problem running a TableToTable conversion using a python script. The script has worked without issue for months. This morning I continue to get a 000732 : <value>: Dataset <value> does not exist or is not supported error. I have tried recreating the excel spread sheet, moving it to a different location, rewriting the script, exporting the code from model builder, etc. If I try to run the process from ToolBox I get the same error. The weird thing is if I run the same process on the same xlsx in model builder, I have no problem. Suggestions? OUTFILE = arcpy.GetParameterAsText(0)
NCFMPFolder = arcpy.GetParameterAsText(1)
DATE = str(datetime.date.today())
Sheet1 = os.path.join(NCFMPFolder,"DeliveryTracking.xlsx\Sheet1$")
DeliveryTrackinggdb = os.path.join(NCFMPFolder,"DeliveryTracking.gdb")
# Process: Table to Table
arcpy.TableToTable_conversion(Sheet1, DeliveryTrackinggdb, "Tracking", "", "DO \"DO\" true true false 8 Double 6 15 ,First,#,Sheet1,DO,-1,-1;TASK \"TASK\" true true false 255 Text 0 0 ,First,#,Sheet1,TASK,-1,-1;SUB_TASK \"SUB_TASK\" true true false 255 Text 0 0 ,First,#,Sheet1,SUB_TASK,-1,-1;CONT \"CONT\" true true false 255 Text 0 0 ,First,#,Sheet1,CONT,-1,-1;COUNTY \"COUNTY\" true true false 255 Text 0 0 ,First,#,Sheet1,COUNTY,-1,-1;APPRVD \"APPRVD\" true true false 8 Date 0 0 ,First,#,Sheet1,APPRVD,-1,-1;STATUS \"STATUS\" true true false 255 Text 0 0 ,First,#,Sheet1,STATUS,-1,-1", "")
... View more
02-14-2014
03:02 AM
|
0
|
5
|
1602
|
|
POST
|
Never mind. I see my problem. nf1val.setValue(NONFLOOD, 0) should be nf1row.setValue(NONFLOOD, 0)
... View more
06-10-2013
09:20 AM
|
0
|
0
|
3297
|
|
POST
|
I'm hoping someone can tell me whats going on with the below bit of code. I keep getting the error AttributeError: 'float' object has no attribute 'setValue' and I'm not sure how to resolve it. Can someone please explain? NONFLOOD = "GRIDfield"
NF1curs = arcpy.UpdateCursor(BuildingGridSelect)
for nf1row in NF1curs:
nf1val = nf1row.getValue(NONFLOOD)
if nf1val < 0:
nf1val.setValue(NONFLOOD, 0)
NF1curs.updateRow(nf1row) nf1val may result in a negative float value (e.g. -2.32076), but what is the correct syntax to update the value to 0?
... View more
06-10-2013
09:13 AM
|
0
|
1
|
11611
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 07-17-2023 01:26 PM | |
| 1 | 05-26-2015 07:18 AM | |
| 1 | 05-28-2015 05:03 AM | |
| 1 | 04-11-2019 09:19 AM | |
| 1 | 01-12-2016 07:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-13-2024
09:06 PM
|