Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
gp.setproduct("ArcInfo")

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,\
                    interface=esriGeoDatabase.IWorkspaceFactory)
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, 
 None))

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.

share|improve this question
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! –  Ragi Yaser Burhum Nov 4 '11 at 21:27
    
You can pretty it up a bit with some helper functions. –  blah238 Nov 4 '11 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 Nov 8 '11 at 9:57
add comment

1 Answer

up vote 3 down vote accepted

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).

share|improve this answer
2  
Everything is correct, except you do not want to call IFeature::Store using an UpdateCursor (it defeats the purpose of using an UpdateCursor). You want to call UpdateFeature instead. help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/… –  Ragi Yaser Burhum Nov 4 '11 at 21:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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