I have blogged earlier about creating helper functions for arcpy which can make you more productive. The basic idea is that you can wrap some of the chunks of code you call often in various projects and then store and maintain them just in one place. A great example of this would be using arcpy.Describe():
Let’s say you have a geodatabase and as a part of your workflow you need to find out some of its properties. You would get individual properties of the geodatabase; alternatively, you would construct a dictionary to access various attributes stored within the same Python object, just like you see in the sample above.
Today I want to show you how to implement this by using the object-oriented programming (OOP) paradigm. You haven’t probably seen that many examples of building new classes for use with arcpy. This is just a really primitive sample that can help you get a sense what is like to build a class and what advantages it provides. It’s important to understand that you might benefit from building own classes that are not present in arcpy. Even more, a new class might inherit all of its properties from an existing arcpy class such as arcpy.SpatialReference(), but be extended with extra properties and methods that you have yourself created.
As you see, we have started just by obtaining the geodatabase properties via the Describe properties. But then we went further and created own properties that would hold some useful information you would like have at hand while working with the geodatabase. It might be super helpful to have JSON like representation of all the features in the feature class, for instance. Let’s see now how we can quickly access various objects inside the geodatabase.
There is a ton of other things you could do now when you have all the feature classes and its features available. One thing to keep in mind is that it does take some time to read the features and feature classes properties, so when creating an instance of a large geodatabase, this process can take quite a long time. Unless you don’t need to access all the features within all the feature classes within the geodatabase, try to construct only those objects which are relevant for your work.