0

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?

closed as off-topic by PolyGeo Nov 17 '17 at 0:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

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.

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?

Not the answer you're looking for? Browse other questions tagged or ask your own question.