Hello everyone,
I've got a question on arcpy. I have a script that is going to select some features out of a few hundred feature classes and export them based off of proximity to my desired location. My issue is I keep getting the 000210 which, to my understanding, means i do not have access to the database I'm trying to write to. I've included my script and error message below. If anyone has any ideas on what might be causing this, i would greatly appreciate the guidance.
''' Created by SGT Russel Klueg 11 JULY 16 About: This script is meant to increase the response time of data creation by allowing for the earthquake to be put in and outputting KMLs of all critical infrastructure within a set distance of the location. ''' import os, time, arcpy, csv from arcpy import env #Allows data to be overwritten env.overwriteOutput = True path = r'C:\Users\JOC-001\Desktop\Python Scripts\Earthquake\Earthquake Infrastructure.mxd' #sets the path listed as the Map Document mxd = arcpy.mapping.MapDocument(path) #declares the Dataframe df = "HSIP" outPath = 'C:/Users/JOC-001/Documents/ArcGIS/Scratch.gdb/' env.workspace = outPath sr = arcpy.SpatialReference("WGS 1984") #Takes the current time and creates a folder from it in YYYYMMDD HHMM format current = time.strftime('%Y%m%d %H%M') os.mkdir(current) earthquake = 'C:/Users/JOC-001/Desktop/Python Scripts/Earthquake/' folder = earthquake + current + '/' print("The output folder for this entire process is below:\n" + folder) #the next few lines take a verified user input to use as the Lat and Long lat = float(raw_input("Please enter the Latitude of the event." + \ "\nNumber should range between between 36.5 and 42.5\n")) while lat < 36.5 or lat > 42.5: lat = float(raw_input("Please enter a valid Latitude between 36.5 and 42.5\n")) long = float(raw_input("Please enter the Longitude of the event." + \ "\nNumber should range between between -87 and -92\n")) while long < -92 or long > -87: long = float(raw_input("Please enter a valid Longitude between -87 and -92\n")) finalCoords = folder + 'coords.csv' #Creates a csv file and moves it into the appropriate folder with open('coords.csv', 'wb') as coords: writer = csv.writer(coords, delimiter=',') data = [['Lat', 'Long'],[lat, long]] writer.writerows(data) os.rename(earthquake+'coords.csv', finalCoords) #Creatst the layer, converts to .shp and buffers it at 50 miles. eventPoint = folder + 'event.lyr' arcpy.MakeXYEventLayer_management(finalCoords, 'Long', 'Lat', 'Event', sr) arcpy.SaveToLayerFile_management('Event', eventPoint) arcpy.FeatureClassToFeatureClass_conversion(eventPoint, outPath, 'finalPoint') arcpy.Buffer_analysis(outPath + 'finalPoint', 'pointBuffer', '50 Miles') bufferFile = outPath + 'pointBuffer' #Iterates through every single layer in the MXD and selects data and exports it. for lyr in arcpy.mapping.ListLayers(mxd): if not lyr.isGroupLayer: name = lyr.name arcpy.SelectLayerByLocation_management(lyr, 'INTERSECT', bufferFile) arcpy.CopyFeatures_management(lyr, name) os.system('pause')
Traceback (most recent call last):
File "C:\Users\JOC-001\Desktop\Python Scripts\Earthquake\Earthquake.py", line 67, in <module>
arcpy.CopyFeatures_management(lyr, name)
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures
raise e
ExecuteError: ERROR 000210: Cannot create output C:/Users/JOC-001/Documents/ArcGIS/Scratch.gdb\Animal Aquaculture Facilities
Failed to execute (CopyFeatures).
Solved! Go to Solution.
I believe I have the issue. I'm using the lyr.name to name the files that are output. The issue with this is that the layer names have spaces in them. I believe if I format those it will fix the issue. Kind of disappointed in myself for overlooking this...
Just saving some people time:
Script:
''' Created by SGT Russel Klueg 11 JULY 16 About: This script is meant to increase the response time of data creation by allowing for the earthquake to be put in and outputting KMLs of all critical infrastructure within a set distance of the location. ''' import os, time, arcpy, csv from arcpy import env #Allows data to be overwritten env.overwriteOutput = True path = r'C:\Users\JOC-001\Desktop\Python Scripts\Earthquake\Earthquake Infrastructure.mxd' #sets the path listed as the Map Document mxd = arcpy.mapping.MapDocument(path) #declares the Dataframe df = "HSIP" outPath = 'C:/Users/JOC-001/Documents/ArcGIS/Scratch.gdb/' env.workspace = outPath sr = arcpy.SpatialReference("WGS 1984") #Takes the current time and creates a folder from it in YYYYMMDD HHMM format current = time.strftime('%Y%m%d %H%M') os.mkdir(current) earthquake = 'C:/Users/JOC-001/Desktop/Python Scripts/Earthquake/' folder = earthquake + current + '/' print("The output folder for this entire process is below:\n" + folder) #the next few lines take a verified user input to use as the Lat and Long lat = float(raw_input("Please enter the Latitude of the event." + \ "\nNumber should range between between 36.5 and 42.5\n")) while lat < 36.5 or lat > 42.5: lat = float(raw_input("Please enter a valid Latitude between 36.5 and 42.5\n")) long = float(raw_input("Please enter the Longitude of the event." + \ "\nNumber should range between between -87 and -92\n")) while long < -92 or long > -87: long = float(raw_input("Please enter a valid Longitude between -87 and -92\n")) finalCoords = folder + 'coords.csv' #Creates a csv file and moves it into the appropriate folder with open('coords.csv', 'wb') as coords: writer = csv.writer(coords, delimiter=',') data = [['Lat', 'Long'],[lat, long]] writer.writerows(data) os.rename(earthquake+'coords.csv', finalCoords) #Creatst the layer, converts to .shp and buffers it at 50 miles. eventPoint = folder + 'event.lyr' arcpy.MakeXYEventLayer_management(finalCoords, 'Long', 'Lat', 'Event', sr) arcpy.SaveToLayerFile_management('Event', eventPoint) arcpy.FeatureClassToFeatureClass_conversion(eventPoint, outPath, 'finalPoint') arcpy.Buffer_analysis(outPath + 'finalPoint', 'pointBuffer', '50 Miles') bufferFile = outPath + 'pointBuffer' #Iterates through every single layer in the MXD and selects data and exports it. for lyr in arcpy.mapping.ListLayers(mxd): if not lyr.isGroupLayer: name = lyr.name arcpy.SelectLayerByLocation_management(lyr, 'INTERSECT', bufferFile) arcpy.CopyFeatures_management(lyr, name)
Error:
Traceback (most recent call last):
File "C:\Users\JOC-001\Desktop\Python Scripts\Earthquake\Earthquake.py", line 67, in <module>
arcpy.CopyFeatures_management(lyr, name)
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures
raise e
ExecuteError: ERROR 000210: Cannot create output C:/Users/JOC-001/Documents/ArcGIS/Scratch.gdb\Animal Aquaculture Facilities
Failed to execute (CopyFeatures).
Ah good point. I'll edit the original post as such. thanks.
The path given with the ERROR 000210 seems goofy, the single backslash with the others being forward slashes. My first guess, you are having an issue creating a valid path for an output. Start by putting some print statements in before executing functions to see what exactly the paths look like that you are passing to different functions.
no time to look in detail, but I am rapidly discovering that any type of slash at the end of a path is not appreciated even if raw formatting is used.... I said appreciated, not necessarily causing an error, until something uses it...
I'll add print statements for all of the paths and I'll reformat so that the slash is added between the file name and the path. I'll update when I have results. Thanks for your help, gentlemen!
I believe I have the issue. I'm using the lyr.name to name the files that are output. The issue with this is that the layer names have spaces in them. I believe if I format those it will fix the issue. Kind of disappointed in myself for overlooking this...