I am trying to use ArcObject in Python. I do have problem with assigning an interface (i.e. IZ.InterpolateZsBetween) to my object with geometry data, code is:

from Comtypes.client import CreateObject, GetModule
import arcgisscripting

gp = arcgisscripting.create(9.3)

esriSystem = GetModule("C:/Program Files (x86)/ArcGIS/com/esriSystem.olb")
esriGeometry = GetModule("C:/Program Files (x86)/ArcGIS/com/esriGeometry.olb")
esriDataSourcesGDB = GetModule("C:/Program Files (x86)/ArcGIS/com/esriDataSourcesGDB.olb")
esriGeoDatabase = GetModule("C:/Program Files (x86)/ArcGIS/com/esriGeoDatabase.olb")

sPath ="c:/temp/test.gdb"
pWSF = CreateObject(esriDataSourcesGDB.FileGDBWorkspaceFactory,\
pWS = pWSF.OpenFromFile(sPath, 0)
pFWS = pWS.QueryInterface(esriGeoDatabase.IFeatureWorkspace)
pFClass = pFWS.OpenFeatureClass("test_z")
pFCursor = pFClass.Search(None, True)
pFeat = pFCursor.NextFeature()
pIZ = pFeat.QueryInferface(esriGeometry.IZ2)

Why this is not working? The output is:

 Traceback (most recent call last):
  File "<pyshell#175>", line 1, in <module>
    pIZ = pFeat.QueryInterface(esriGeometry.IZ2)
   File "C:\Python25\lib\site-packages\comtypes\__init__.py", line 1078, in QueryInterface
 self.__com_QueryInterface(byref(iid), byref(p))
 COMError: (-2147467262, 'Taki interfejs nie jest obs\xb3ugiwany.', (None, None, None, 0, 

So I tried:

pShape = pFeat.ShapeCopy
pIZ = pShape.QueryInterface(esriGeometry.IZ2)
pShape.InterpolateZsBetween(0, 0, 0, 4)

And this is working. But how to stick it back and save it in my feature? I am learning Python and ArcObjects, so please be understandful. Any help will be appreciated.

  • 1
    COM and Python doesn't look very pretty, but this is the route that will get you what you want. +1 for getting this far so fast! Commented Nov 4, 2011 at 21:27
  • You can pretty it up a bit with some helper functions.
    – blah238
    Commented Nov 4, 2011 at 22:56
  • Aparently COM and Python does not go in pair well, but I was thinking that Python would be good place to start my adventure with programming as it seems quite user friendly. Once I'll acomplish this task, I'll start to look at C# or C++. Thanks a lot guys.
    – Tomek
    Commented Nov 8, 2011 at 9:57

1 Answer 1


The IZ interface is implemented only on the Polygon and Polyline classes, which you obtain from the Shape or ShapeCopy properties of an IFeature. You can't QI between interfaces that aren't supported (either implemented or inherited) by an object. Use the documentation for one of the ArcObjects SDKs to see the interfaces each class implements. Reading the Object Model Diagrams (listed under each namespace in the help, example) can also be very helpful to see the inheritance/implementation relationships between the various classes and interfaces.

As for your actual workflow, you'll need to use the Update instead of Search method on your feature class to obtain an update cursor, and then set the Shape property of the feature to the result of the InterpolateZsBetween method and finally call IFeatureCursor.UpdateFeature (thanks for the correction @Ragi).


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.