Python Script error 000732

2225
4
12-08-2017 07:47 PM
RachelDiPietro
New Contributor II

I am trying to run a Python Script for a batch of radar shapefiles to do a hotspot analysis, but after one of my lines, I get a 000732 error saying my feature class does not exist or is not supported. Here is the text up until I receive the error:

>>> import arcpy, sys, traceback
>>> arcpy.env.workspace="D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\"
>>> in_path="D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\centILradarF16"
>>> out_path="D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\centILhotspotsF16"
>>> site="KILX"
>>> year="2016"
>>> season="Fall"
>>> time="peak"
>>> feat_class="KILX_V06_20160902_233310.shp"
>>> in_fc=site+year+season+time+"_5pcnt.shp"
>>> out_shp=out_path+in_fc
>>> if arcpy.Exists(out_shp):arcpy.Delete_management(out_shp)
>>> arcpy.CopyFeatures_management(feat_class,out_shp)

Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 2586, in CopyFeatures     raise e ExecuteError: ERROR 000732: Input Features: Dataset KILX_V06_20160902_233310.shp does not exist or is not supported

I checked the ArcGIS Help on unsupported data types, and Personal Geodatabases and Excel files were listed. I am working from a File Geodatabase, and the data types I am working with are shapefiles. I also checked for a Subtypes tab in the feature class properties to re-enter the default subtype code, but there was no Subtypes tab. The pathway in the in_path is the correct location for the shapefile.

I am new to Python, so there could easily be something I am missing here. Any help would be greatly appreciated!

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

pretty long filename

'D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\centILhotspotsF16KILX2016Fallpeak_5pcnt.shp'

# ---- did you mean this?

out_shp = out_path + "\\" + in_fc

out_shp 'D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\centILhotspotsF16\\KILX2016Fallpeak_5pcnt.shp'
DanPatterson_Retired
MVP Emeritus

for assembling filenames, you can use os.path functions or simply

args = [site, year, season, time]

"".join(args)  # ---- join the elements in the args list with no space/separation

'KILX2016Fallpeak'

fn = "".join(args)  # ---- it can be generated and assigned to a variable for future use

"\\".join([out_path, fn])  # ---- and put to work when needed

'D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\centILhotspotsF16\\KILX2016Fallpeak'

# ---- but I would be remiss if I didn't point out that you should never use paths
#  with spaces in them...they work when they feel like it, but can fail when you
#  need them to work.  Plus keep them short and simple
XanderBakker
Esri Esteemed Contributor

Since the error states that the dataset "KILX_V06_20160902_233310.shp" was not found, the first thing to check is to see if that shapefile exists in the workspace D:\\THESIS WORK\\IL Tower Mortality Profile\\Thesis\\

XanderBakker
Esri Esteemed Contributor

What you are trying to do is this (as far as I can deduce from your code):

import arcpy

in_shp = r'D:\THESIS WORK\IL Tower Mortality Profile\Thesis\KILX_V06_20160902_233310.shp'
out_shp = r'D:\THESIS WORK\IL Tower Mortality Profile\Thesis\centILhotspotsF16\KILX2016Fallpeak_5pcnt.shp'

if arcpy.Exists(out_shp):
    arcpy.Delete_management(out_shp)
arcpy.CopyFeatures_management(in_shp, out_shp)
‍‍‍‍‍‍‍‍‍‍‍

or is the input shape located here?

in_shp = r'D:\THESIS WORK\IL Tower Mortality Profile\Thesis\centILradarF16\KILX_V06_20160902_233310.shp'

There are a lot of redundant lines, but surely there are there for a reason (for instance to process multiple datasets later on).

I recommend you to use format or join as Dan pointed out when combining strings to generate the name and to use os.path.join to create the path to an input or output featureclass. Example:

import os

site="KILX"
year="2016"
season="Fall"
time="peak"
fc_name = '{0}{1}{2}{3}_5pcnt.shp'.format(site, year, season, time)

ws = r'D:\THESIS WORK\IL Tower Mortality Profile\Thesis'
fc = os.path.join(ws, fc_name)