How to preserve OBJECTID while exporting feature class to another EGDB using Feature class to feature class

1296
4
Jump to solution
01-11-2023 05:25 AM
Labels (2)
shamnasPC
New Contributor III

Is there any way to preserve OBJECTID while exporting feature class to another EGDB using Feature class to feature class ?

Tags (1)
2 Solutions

Accepted Solutions
TonyContreras_Frisco_TX
Occasional Contributor III

I have found that using the copy function in ArcGIS Desktop keeps the OBJECTID values of the source feature class. Feature Class to Feature Class does not reliably, in my experience. I am not sure if these statements are true in ArcGIS Pro. I still wouldn't count on OBJECTID column being preserved when moving a feature class from one source to another and would recommend abandoning any workflows that rely on the OBJECTID values.

View solution in original post

shamnasPC
New Contributor III

Hi @TonyContreras_Frisco_TX , Yes the copy function works in both Desktop and ArcGIS Pro and It can retain the OBJECTID.

Hence I wrote the below python to achieve it.

import arcpy, os

connection_file = r"\input URL Path"
local_fgdb = r'\outputgdb Patha'

fullname = os.path.join(connection_file, "inputFeatureClassName")
feats=arcpy.FeatureSet(table=fullname)
feats.save(os.path.join(local_fgdb, "inputFeatureClassName"))

View solution in original post

0 Kudos
4 Replies
TonyContreras_Frisco_TX
Occasional Contributor III

I have found that using the copy function in ArcGIS Desktop keeps the OBJECTID values of the source feature class. Feature Class to Feature Class does not reliably, in my experience. I am not sure if these statements are true in ArcGIS Pro. I still wouldn't count on OBJECTID column being preserved when moving a feature class from one source to another and would recommend abandoning any workflows that rely on the OBJECTID values.

shamnasPC
New Contributor III

Hi @TonyContreras_Frisco_TX , Yes the copy function works in both Desktop and ArcGIS Pro and It can retain the OBJECTID.

Hence I wrote the below python to achieve it.

import arcpy, os

connection_file = r"\input URL Path"
local_fgdb = r'\outputgdb Patha'

fullname = os.path.join(connection_file, "inputFeatureClassName")
feats=arcpy.FeatureSet(table=fullname)
feats.save(os.path.join(local_fgdb, "inputFeatureClassName"))
0 Kudos
DavidAnderson_1701
Occasional Contributor

As OBJECTID is a system created primary key, none of the tools are going to keep it other than by luck.   If you want to retain the value, create a new column in the feature class with same data type as OBJECTID, maybe with a name like old_objectid.  The use the field calculator to set the old_objectid = OBJECTID.  Then export.

0 Kudos
shamnasPC
New Contributor III

Hi @DavidAnderson_1701 ,
It can preserve the OBJECTID if we use the copy function like @TonyContreras_Frisco_TX mentioned above.
And no other ArcPy function can preserve the object if there's any non sequential numbers in it (Like by luck)

0 Kudos