1

How do I copy a shapefile to a Feature Dataset?

Here is is my script.

import arcpy

import os

arcpy.env.workspace = "C:/temp"

dataset1 = "C:/SDE.gdb/temp1"

arcpy.CopyFeatures_management("scrap.shp", "dataset1")

Instead of copying the scrap.shp located in c:/temp into the dataset called "temp1"...it creates a point feature class called "temp1" in the root of SDE.gdb

  • 1
    I'd think FeatureClassToFeatureClass would be required for this. – Vince Feb 22 at 21:10
2

You are mixing a variable with a string object.

dataset1 = "C:/SDE.gdb/temp1" #dataset1 is a variable
arcpy.CopyFeatures_management("scrap.shp", "dataset1") #dataset1 is a string because of the quotes

Get rid of the quotes.

arcpy.CopyFeatures_management("scrap.shp", dataset1)

Also note that you are copying to a feature class, not a feature dataset.

1

Assuming temp1 is your feature dataset, I like to explicitly define my input and output data. In this case, I am stripping the name of the shapefile and appending it to the feature dataset path using the following:

os.path.join(feature_dataset, os.path.basename(shp).split(".")[0])

Which, in your case, creates a file path to a feature class like so:

C:/SDE.gdb/temp1/scrap

import arcpy, os

shp = 'C:/temp/scrap.shp'
feature_dataset = 'C:/SDE.gdb/temp1'

arcpy.CopyFeatures_management(shp, os.path.join(feature_dataset, os.path.basename(shp).split(".")[0]))

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.