1

I have a strict data model which needs to be enforced for a project. For all featureclasses which exist, I need to check if the fields which are present conform to the data model. I want to do this in python. An example:

The Schema:

`Field1 must called Field_01 and the format is Text with length 255`

`Field2 must called Field_02 and must of Format Int`

`Field3 must called Field_03 and must of Format Date`

If my Featureclase to be tested has 20 fields, I need to loop through all fields describing their formats and compare to the data model.

If they are wrongly named or formated the correct field should be added and the the attributes copied. The old field should then be deleted.

Everyone has these tasks but I have never seen a script to really tackle the problem. Is it worth the trouble writing it?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Robert Buckley
  • 10,175
  • 14
  • 76
  • 156
  • 2
    Have a look at Feature Compare (http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/feature-compare.htm) You can set it to compare schema only. You'd still need to write the code to make one item match the other – KHibma Jun 15 '15 at 13:46

2 Answers2

2

Yes, because it is very easily done using arcpy.ListFields():

Lists the fields in a feature class, shapefile, or table in a specified dataset. The returned list can be limited with search criteria for name and field type and will contain field objects.

The first code sample on that page includes much of what you will need.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
2

As suggested by @Polygeo have a look at the arcpy.ListFields() function this will enable you to query, compare and create fields.

There is another discussion on comparing schemas from different geodatabases. I'd suggest having a look at that. There is some pseudo-code to consider and add-ins that might interest you in How to compare schemas from two File geodatabases?

spk578
  • 1,516
  • 1
  • 11
  • 27