Enterprise Geodatabase feature class naming

197
2
Jump to solution
02-11-2022 07:10 AM
Boyang_Wang
Occasional Contributor II

Hi,

Not sure if this is typical, but whenever I create a feature class in my enterprise geodatabase, its name will have the database and username added. For example, if I create a feature class called FC, its name will become "database.username.FC".

This creates a problem when I try to use python to backup my enterprise geodatabase feature classes using FeatureClassToFeatureClass. I don't want my backup feature class name has "database.username." in it. How can I get the feature class name only without using string manipulation?

Thanks!

1 Solution

Accepted Solutions
KimGarbade
Occasional Contributor III

For enterprise GDBs (at least in SQL Server in my case) this is common, but usually its not an issue, although I haven't tried Feature Class to Feature Class backup using a python script.  That being said....

In Python the output name is an input into the Feature Class to Feature Class function:

arcpy.conversion.FeatureClassToFeatureClass(in_features, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword})

So if you have a variable something like txtInFeatures (to use as the 'in_features' in the function reference above) and its value is in the form "DatabaseName.Owner.FeatureClassName", I would use something like this to generate the txtOutName (to use as the 'out_name' in the function reference above)

txtOutName = txtInFeatures[txtInFeatures.rindex('.')+1:]

below is a snip of a test I ran in a python emulator. Code on the left, result on the right.

KimGarbade_1-1644597986166.png

Hope this helps.

 

View solution in original post

2 Replies
KimGarbade
Occasional Contributor III

For enterprise GDBs (at least in SQL Server in my case) this is common, but usually its not an issue, although I haven't tried Feature Class to Feature Class backup using a python script.  That being said....

In Python the output name is an input into the Feature Class to Feature Class function:

arcpy.conversion.FeatureClassToFeatureClass(in_features, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword})

So if you have a variable something like txtInFeatures (to use as the 'in_features' in the function reference above) and its value is in the form "DatabaseName.Owner.FeatureClassName", I would use something like this to generate the txtOutName (to use as the 'out_name' in the function reference above)

txtOutName = txtInFeatures[txtInFeatures.rindex('.')+1:]

below is a snip of a test I ran in a python emulator. Code on the left, result on the right.

KimGarbade_1-1644597986166.png

Hope this helps.

 

Boyang_Wang
Occasional Contributor II

This works great as I can use the same code for different database names and owner names. Thanks!

0 Kudos