5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0) 9. Set pFeatcls = pFeatLayer.FeatureClass 10.
11. Dim pFeatCur As IFeatureCursor 12. Dim pFeatBuf As IFeatureBuffer 13. Dim v As Variant 14.
15. Set pFeatCur = pFeatcls.Insert(True) 16. Set pFeatBuf = pFeatcls.CreateFeatureBuffer 17. v = pFeatCur.InsertFeature(pFeatBuf)
IFeatureClass接口的第八个方法CreateFeatureBuffer(方法,新建一个缓冲,返回一个IFeatureBuffer类型的变量,然后再对这个变量进行操作) 例子代码:
1. Dim pFeatcls As IFeatureClass 2. Dim pFeatLayer As IFeatureLayer 3. Dim pDoc As IMxDocument 4. Dim pMap As IMap 5.
6. Set pDoc = ThisDocument 7. Set pMap = pDoc.Maps.Item(0) 8. Set pFeatLayer = pMap.Layer(0) 9. Set pFeatcls = pFeatLayer.FeatureClass 10.
11. 'create a feature cursor and feature buffer interface 12. Dim pFeatCur As IFeatureCursor 13. Dim pFeatBuf As IFeatureBuffer 14.
15. 'open the feature cursor and feature buffer
16. Set pFeatCur = pFeatcls.Insert(True) 17. Set pFeatBuf = pFeatcls.CreateFeatureBuffer 18.
19. 'get the list of fields 20. Dim pFlds As IFields 21. Dim pFld As IField 22. Dim i As Long
23. Dim pPolygon As IPolygon 24. Dim pPolyline As IPolyline 25. Dim pPt As IPoint 26.
27. Set pPolygon = New Polygon 28. Set pPolyline = New Polyline 29. Set pPt = New Point 30.
31. 'find the geometry field, based on the shape type, 32. 'set the value for the field to the appropriate object 33. Set pFlds = pFeatcls.Fields 34. For i = 1 To pFlds.FieldCount - 1 35. Set pFld = pFlds.Field(i)
36. If (pFld.Type = esriFieldTypeGeometry) Then 37. Dim pGeom As IGeometry
38. Select Case pFeatcls.ShapeType 39. Case esriGeometryPolygon 40. Set pGeom = pPolygon 41. Case esriGeometryPolyline 42. Set pGeom = pPolyline 43. Case esriGeometryPoint 44. Set pGeom = pPt 45. End Select 46.
47. 'set the value in the feature buffer
48. pFeatBuf.Value(i) = pGeom 49.
50. 'if it is not a geometry column, determine what kind of 51. 'field it is, and insert the equivalent of a null value 52. 'for that field type 53. Else
54. If pFld.Type = esriFieldTypeInteger Then 55. pFeatBuf.Value(i) = CLng(0)
56. ElseIf pFld.Type = esriFieldTypeDouble Then 57. pFeatBuf.Value(i) = CDbl(0)
58. ElseIf pFld.Type = esriFieldTypeSmallInteger Then 59. pFeatBuf.Value(i) = CInt(0)
60. ElseIf pFld.Type = esriFieldTypeString Then 61. pFeatBuf.Value(i) = \62. Else
63. MsgBox \64. End If 65. End If 66. Next i 67.
68. 'insert the feature from the buffer into the database 69. pFeatCur.InsertFeature pFeatBuf
14. 关于ITable接口(esriGeoDatabase)
ITable是把要素类当成一个表格来看,每一列对应一个字段(Field),每一行对应一个要素(Feature),所以对要素类(Ifeatureclass)接口的操作均可以类似的在Itable接口中找到。
两个接口可以进行如下强制转化: VB语言
1. Dim pFC As IFeatureClass 2. Dim pTable As ITable
3.
4. Set pTable = pFC C#语言
1. IFeatureClass pFC; 2. ITable pTable; 3. pTable = (ITable)pFC;
ITable接口的第一个方法AddField(Field) (方法,增加一个属性字段到这个表,其中传入的参数为一个IField接口的变量,此变量可以由其他表获得并赋值给要操作的表,可用IFeilds接口的Field属性来获得)
ITable接口的第二个方法GetRow(OID) (方法,通过OID来从表格数据库中获取一行,返回一个IRow接口的变量)此方法类似于IFeatureClass接口的GetFeature方法 例子代码:
1. Dim pWorkspace As IWorkspace 2. Dim pFact As IWorkspaceFactory 3.
4. ' This example uses an SDE connection. This code works the 5. ' same for any open IWorkspace. 6.
7. Dim pPropset As IPropertySet 8. Set pPropset = New PropertySet 9. With pPropset
10. .SetProperty \11. .SetProperty \12. .SetProperty \13. .SetProperty \14. .SetProperty \15. .SetProperty \16. End With
17. Set pFact = New SdeWorkspaceFactory
18. Set pWorkspace = pFact.Open(pPropset, Me.hWnd)
19. Dim pFeatureWorkspace As IFeatureWorkspace 20. Set pFeatureWorkspace = pWorkspace 21.
22. Dim pTable As ITable
23. Set pTable = pFeatureWorkspace.OpenTable(\24. Dim pRow As IRow
25. Set pRow = pTable.GetRow(59) 26. Debug.Print pRow.Value(2)
ITable接口的第三个方法GetRows(oids, Recycling) (方法,得到一个游标ICursor,通过一个oids的OID数组参数和一个Recycling的布尔类型的参数,一般为True)此方法类似于IFeatureClass接口的GetFeatures方法 例子代码:
1. Dim iOIDList() As Long 2. Dim iOIDListCount As Long 3. iOIDListCount = 5 4.
5. ReDim iOIDList(iOIDListCount) 6. iOIDList(0) = 1 7. iOIDList(1) = 2 8. iOIDList(2) = 3 9. iOIDList(3) = 4 10. iOIDList(4) = 50 11.
12. Dim pCursor As ICursor
13. Set pCursor = pTable.GetRows(iOIDList, True) 14. Dim pRow As IRow
15. Set pRow = pCursor.NextRow 16. While Not pRow Is Nothing 17. Debug.Print pRow.Value(2) 18. Set pRow = pCursor.NextRow 19. Wend
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库ArcEngine - 开发接口集(6)在线全文阅读。
相关推荐: