I have a model that converts shape files to a feature dataset in an existing database. I would like to either overwrite the existing feature classes in the db or delete them and perform the conversion. Which method is the most efficient and how do I do it?
v10.2
Solved! Go to Solution.
Hi there!
First off, let me just say that I feel your pain. This was (just) one of the limitations of ModelBuilder that eventually led me to embrace Python/arcpy as my solution of choice. If you're willing to go that route, you can export to a python script by editing the model and going to the Model menu > Export > to Python script. (Edit: seems like you're already aware of how to do this.)
From there, you have a couple of options. Option 1 is to set the overwriteOutput environment on your script by typing:
arcpy.env.overwriteOutput = True
at the beginning, but after importing the arcpy module.
If this fails to overwrite, you may employ a test for the existence of the feature class that you want to overwrite and if it does exist, delete it before running your conversion tool of choice. It would likely look something similar to:
# Iterate through your shapfiles with a for loop for shp in shapefiles_to_convert: # Get the input to the conversion tool in_shp = shp # Get the feature dataset where your tool will output output_featureDataset = r"path_to_feature_dataset" # Get the base name of your output feature class output_name = arcpy.Describe(shp).baseName # Test to see if the output feature class already exists if arcpy.Exists(output_featureDataset + "\\" + output_name): # Delete it if it does arcpy.Delete_management(output_featureDataset + "\\" + output_name) # Run the conversion tool arcpy.FeatureClassToFeatureClass_conversion(shp, output_featureDataset, output_name)
I hope you find a solution to your problem!
Warm Regards,
Micah Babinski
When I convert shapefile to feature class in the geodatabase, I use Feaure Class to Feature Class tool and it does overwrite by default. Did you try and it didn't overwrite?
Lisa
Liza that is not a batch function unfortunately.
Oh, I see. If you use FeatureClass to Geodatabase (multiple) it doesn't overwrite.
I would use Feaure Class to Feature Class tool and iterators to convert all the shapefiles.
Like this:
that's what I have...my folder GIS setting the env is recursive because the shapefiles are in directories within the folder GIS. When I run the model the second time it takes aproximatly1 second
I get the warning error 000258 name already used when I attempt to run the model again to check that it works
What tool are you using? Is it just warning or the model doesn't run after this error? Do you want to show your model here?
Could you try to save to GDB outside of Feature Dataset?
when I do that I get this
000258: Output S:\Shared\1 Survey Operations\Data Management\Databases\DB\HarkandDB_Nad27.gdb\protrac already exists