77范文网 - 专业文章范例文档资料分享平台

ArcEngine - 开发接口集(6)

来源:网络收集 时间:2020-02-21 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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)在线全文阅读。

ArcEngine - 开发接口集(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/772901.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: