I want to do something like the following:

class SubClassOfSpatialReference(arcpy_spatial_reference_object):
    def __init__(self, input_data):

... etc.

Can I even do this and, if so, what is the parent object that I need to provide in the class definition?

If you type() a spatial reference object, you get arcpy.arcobjects.arcobjects.SpatialReference. I tried that and got AttributeError: 'module' object has no attribute 'arcobjects'. No surprise, really. I imagine that there is also a problem with the fact that the arcpy SpatialReference class invocation takes an argument of a WKID, spatial reference name, or feature dataset from which to copy the spatial reference; there isn't any way to create a new, blank spatial reference object.

Here's another thought: can one subclass an instance, as in:

class SubClassOfSpatialReferenceInstance(arcpy.SpatialReference(54004):

starting in this case with the World_Mercator spatial reference?

What I am ultimately after is a convenient interface for a modifiable spatial reference. Contrary to ESRI documentation of the arcpy SpatialReference class, a majority of the properties are read-only. I figured that, if I could subclass the arcpy Spatial Reference class, then I could override the name(), standardParallel1(), etc. attributes and use WKT string manipulation to make the spatial reference modifiable. I suppose I could make a generic class that deals only with the WKT and implements a CreateSR() method that uses the loadFromString() method to make a spatial reference after all the properties have been set, but it just wouldn't be as slick.


1 Answer 1


You normally get to the SpatialReference class through arcpy, so you'd probably want to do that. And you can't subclass in that way, you have to put the overridden constructor call in your own init:

class WeirdSpatialReferenceSubclass(arcpy.SpatialReference):
    def __init__(self):
        # Force initialize to 54004
        super(WeirdSpatialReferenceSubclass, self).__init__(54004)
    def myPropertyX(self):
        s = self.exportToString()
        # Find some interesting property in s and assign to value
        return value
    def myPropertyX(self, new_value):
        s = self.exportToString()
        # Do some interesting edit of s and assign to new_string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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