1

I'm pretty new to python and I have some trouble getting this snippet of code to work. I have some lines that work to copy shapefiles and feature classes, but I haven't managed to be able to copy feature classes from a feature dataset.

A "lookup table" exists with info on the source path, source name, target path, target name, etc. There's a field called 'BatchID' that is used as a reference for what the user wants to be copied. That said, there's a raw input that is in the code and once the user enters the number, the data in that row(s) is copied. I keep getting the error:

ERROR 000732: Input Features: Dataset C:...file path here...\test1.gdb\SanTest does not exist or is not supported Failed to execute (CopyFeatures).

Copy Feature dataset- features

            if batch_id == int(btch_num):
                ds = arcpy.ListFeatureClasses('','', source_name)
                for fc in ds:
                    print ('These features') + (fc) + (' are in the feature dataset!')
                    arcpy.CopyFeatures_management(fc, os.path.join(target_path, os.path.splitext(fc)[0]))
  • Welcome to GIS SE! As a new user be sure to take the Tour. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. Please provide a code snippet rather than a copy/paste from your code. Please do not include try/except statements in your code snippet because they can mask error messages that might otherwise be helpful. What is the full error message including line number that you get when running the exact code that you have presented? – PolyGeo Feb 2 '18 at 7:57
  • What is the full error message including line number that you get when running the exact code that you have presented? I would expect to see your code snippet start with import arcpy. – PolyGeo Feb 2 '18 at 8:23
  • 1
    import arcpy is there in my long code. Just not here. If I add it here, among other lines, I'm afraid you may mark it as irrelevant again. So I thought getting the code section that has an issue is what was required in the post. If that's not an issue, I could add it. – Ellbih Feb 2 '18 at 8:57
  • error was indicated in the question. It's ERROR 000732: Input Features does not exist or is not supported – Ellbih Feb 2 '18 at 8:59
  • What gets printed out with: print ds? – BERA Feb 2 '18 at 10:03
1

I used this example in class the other night, it may offer a clue, as it works, basically copies fc out of a dataset, into a folder as shapefiles:

import arcpy

arcpy.env.workspace = "E:/class_5/ForExercise.gdb"
out = "E:/class_5/shp/"

datasets = arcpy.ListDatasets("*", "Feature")

for i in datasets:
    print i +" DataSet Name" 
    fclist = arcpy.ListFeatureClasses('*', "ALL", i)
    for x in fclist:
        print x +" fc in  Dataset"
        arcpy.CopyFeatures_management(x, out + x)

print "Done"

Your error shows a path of ..\test1.gdb\SanTest with the slashes wrong unless you used the "r" in-front of the path. Better yet just flip the slashes on your source.

(fc, os.path.join(target_path, os.path.splitext(fc)[0])) The splitext(fc)[0} is how you remove the .shp off of a shapeFile. The fc in the database probably already has this removed. Another option to define the output is path + os.sep + fc

0

As has been my experience, and also as documented by ESRI, this is often (but not always) due to issues with formatting of paths. You may want to examine what the path in your code os.path.join(target_path, os.path.splitext(fc)[0]) would print out to a string as.

ESRI indicates that the most common causes of this error are:

  • Using backslashes instead of forward slashes
  • Misspelled folder names
  • Having spaces in path names

Source: https://support.esri.com/en/technical-article/000010149

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.