Adding feature class to existing feature dataset with other feature classes

2539
5
02-21-2018 12:29 PM
MascillineHama
New Contributor

Fairly new to python so forgive me if it sounds like i am repeating a question. I am trying to add a series of newly created feature classes to a feature dataset that exists and has other feature classes in it. it creates them and adds them to the dataset, however it deletes whatever other feature class(es) that are in that dataset. I have also created the feature class in the geodatabase within the same place that the feature dataset is located and used FeatureClassToFeatureClass conversion and it acts exactly the same way; deletes whatever is in the dataset and adds the newly created  feature classes. I thought that was weird as they have different names (schema is the same) from the ones contained in there. I even put in code (just in case there was same name issues) to rename the feature class if one with the same name exists. Maybe I am biting more than i can chew! 

The idea here is that I have are several text files related to an area with different data related to that area. I want all the data for that area to stay in one dataset, so that user create the data and keep it in one area. This is so different area can all go into one geodatabase.

The closest I could get to something that i wanted was this threadhttps://community.esri.com/thread/84711 

0 Kudos
5 Replies
JoeBorgione
MVP Emeritus

Try putting this line in your script:

arcpy.env.overwriteOutput = False

And see if that fixes it...

That should just about do it....
0 Kudos
MascillineHama
New Contributor

Thank you Joe. That is 2 weeks that I can never get back!!

I thought the overwiteoutput feature relates to writing over features classes that have the same name, not features classes with different names. I guess because the feature dataset does exist so anything in it can be overwritten and or deleted even if the names are different. 

0 Kudos
MascillineHama
New Contributor

Found a wrinkle to this:

   -  if you run it off the IDE it works perfectly

   -   if you run this in arcmap/arccatalog tool and the flag is falses, it gives me standard datasets exists  error.

Any thoughts on this going around this?

0 Kudos
JoeBorgione
MVP Emeritus

Not sure what to say.  I just wrote this up to test:

import arcpy
arcpy.env.overwriteOutput = False
in_fc = r'C:\Replicas\Replicas.gdb\MasterStreetNameFC'
out_loc = r'C:\Users\JBorgione\Desktop\MyGIS\AddressPointTesting\AddressTest.gdb\test'
out_fc = 'fc4'
arcpy.FeatureClassToFeatureClass_conversion(in_fc,out_loc,out_fc)

In line 4 I specify the name of my target feature dataset.  I've run it in the IDE shell and just by double clicking the .py file and it has worked either way.  (out_fc gets changed before each run)

That should just about do it....
0 Kudos
MascillineHama
New Contributor

I played around with the tool parameters a little and got it to work.

Thanks again Joe, much appreciated

0 Kudos