Monday 26 December 2016

arcgis 10.2 - ArcPy function works in ArcMap Python window but not from standalone script?


So I think I'm running into a data/schema lock issue, but I have no idea how to tell, or how to fix it for that matter. Here's the setup:


I have this chain of gp functions:


#extract elevations to stations
arcpy.gp.ExtractValuesToPoints_sa(station_locations, elevation_raster, scratchGDB + "\station_elevations", "NONE", "VALUE_ONLY")

#calculate the mean air temperature for each station over the n-hour time period
arcpy.Statistics_analysis(data_table, scratchGDB + "\station_statistics", "air_temperature MEAN", "site_key")
#join elevations to the statistics table created above
arcpy.JoinField_management(scratchGDB + "\station_statistics", "site_key", scratchGDB + "\station_elevations", "Site_Key", "RASTERVALU")
#select rows in "station_statistics" that have a positive elevation (non-null)
arcpy.TableSelect_analysis(scratchGDB + "\station_statistics", "stats1", "RASTERVALU IS NOT NULL")

scratchGDB is set from:


scratchGDB = arcpy.env.scratchGDB


When I run these four gp functions one at a time in the ArcMap python window, they run successfully. But when I run the debug in PyScripter on the stand-alone script, I get this error from the "arcpy.TableSelect_analysis" function:


table select error


Looking into "ERROR 000210" is what makes me think it's a data lock issue, but I'd like to know what's making it work in the python window and not work in the PyScripter IDE?



Answer



I don't see where you set the env so try changing your Table Select line to:


arcpy.TableSelect_analysis(scratchGDB + "\station_statistics", scratchGDB + "\stats1", "RASTERVALU IS NOT NULL")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...