ArcGIS接口详细说明

Dim pLayerAsILayer

Set pMxDocument =Application.Document Set pMap =pMxDocument.FocusMap Set pLayer =pMxDocument.SelectedLayer pMap.MoveLayer pLayer, pMap.LayerCount- 1

End Sub

IMap接口的第十二个方法SelectByShape(Shape, env, justOne) (方法,从Layer中依靠一个图形的范围shape和一个选择的环境env来选择要素,而在所有图层中只从IFeatureLayer的图层中进行选择)

20. 关于IPropertySet接口(esriSystem)

IPropertySet接口的第一个方法SetProperties (names, values ) (方法,设置属性) IPropertySet接口的第二个方法SetProperty (name, value ) (方法,设置属性)

例子代码:

Dim pPropset AsIPropertySet Set pPropset = NewPropertySet With pPropset

.SetProperty\ .SetProperty\ .SetProperty\ .SetProperty\ .SetProperty\ .SetProperty\ End With

Dim pFactSDE AsIWorkspaceFactory Set pFactSDE = NewSdeWorkspaceFactory

Dim pWorkSpaceSDE AsIWorkspace

Set pWorkSpaceSDE = pFactSDE.Open(pPropset,Me.hWnd)

'Example of howtouseapropertysettoopenaPersonalGeodatabaseworkspace.

Dim pPropset AsIPropertySet Set pPropset = NewPropertySet

pPropset.SetProperty\

Dim pFactAccess AsIWorkspaceFactory Set pFactAccess = NewAccessWorkspaceFactory

Dim pWorkSpaceAccess AsIWorkspace

Set pWorkSpaceAccess =pFactAccess.Open(pPropset,Me.hWnd) 21. 关于IFeatureWorkspace接口(esriGeoDatabase)

IFeatureWorkspace接口的第一个方法OpenFeatureClass (Name) (方法,从一个要素工作空间打开一个要素,返回一个IFeatureClass类型的变量)

例子代码:

'This example opensashapefileasafeatureclass. Public Sub OpenFeatureClass_Example() Dim pWorkspaceFactoryAsIWorkspaceFactory

Set pWorkspaceFactory= New ShapefileWorkspaceFactory Dim pFeatureWorkspaceAsIFeatureWorkspace

Set pFeatureWorkspace =pWorkspaceFactory.OpenFromFile(\ Dim pFeatureClassAsIFeatureClass

Set pFeatureClass =pFeatureWorkspace.OpenFeatureClass(\ MsgBox \ \ states\

End Sub

22. 关于IWorkspaceEdit接口(esriGeoDatabase)

例子代码:

Public Sub WorkspaceEdit()

Dim pWorkspaceFactoryAsIWorkspaceFactory

Set pWorkspaceFactory= New esriDataSourcesGDB.AccessWorkspaceFactory Dim pFeatureWorkspaceAsIFeatureWorkspace

Set pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(\ Dim pFeatureClassAsIFeatureClass

Set pFeatureClass =pFeatureWorkspace.OpenFeatureClass(\ Dim pWorkspaceEditAsIWorkspaceEdit Set pWorkspaceEdit =pFeatureWorkspace Dim pFeatureAsIFeature Dim iResponseAsInteger

Dim bHasEditsAsBoolean pWorkspaceEdit.StartEditingTrue pWorkspaceEdit.StartEditOperation Set pFeature =pFeatureClass.GetFeature(1) pFeature.Delete

pWorkspaceEdit.StopEditOperation

iResponse = MsgBox(\ If iResponse =vbYesThen pWorkspaceEdit.UndoEditOperation End If

pWorkspaceEdit.HasEditsbHasEdits If bHasEditsThen

pWorkspaceEdit.StopEditingMsgBox(\ End If

End Sub

在实际问题中,如果有多次操作需要更改Feature的时候,切记要将操作对象重新赋值,不然在pWorkspaceEdit.StopEditing(true)的时候会出现错误,报错代码为-2147467259。

(详细代码可见WindowsApplication6的代码,其中详细操作了对字段的编辑过程,其中涉及到很多对字段Field的方法 Add(Field),Delete(Field),get_value(object value),set_value(intindex, object value)等等操作,其中还涉及到Feature经过ICursor类选取与经过FeatureClass类的方法GetFeature选取的区别)

23. 关于IWorkspaceFactory接口(esriGeoDatabase)

IWorkspaceFactory接口的第一个方法Open (ConnectionProperties, hWnd ) (方法,从一个工作工厂打开一个工作空间,并返回IWorkspace类型的变量,方法中的第一个参数ConnectionProperties是IPropertySet接口的变量)

例子代码:

Dim pSdeWorkspaceFactoryAsIWorkspaceFactory Dim pSdeWorkspace AsIWorkspace Dim pConnectionPropertiesAsIPropertySet

Set pConnectionProperties =NewPropertySet With pConnectionProperties .SetProperty\ .SetProperty\ .SetProperty\ .SetProperty\ .SetProperty\

End With

Set pSdeWorkspaceFactory =NewSdeWorkspaceFactory

Set pSdeWorkspace = pSdeWorkspaceFactory.Open(pConnectionProperties,0)

IWorkspaceFactory接口的第二个方法OpenFromFile (fileName, hWnd ) (方法,从一个路径打开一个工作空间,并返回IWorkspace类型的变量)

例子代码:

Dim pSdeWorkspaceFactoryAsIWorkspaceFactory Dim pSdeWorkspace AsIWorkspace

Set pSdeWorkspaceFactory =NewSdeWorkspaceFactory

Set pSdeWorkspace = pSdeWorkspaceFactory.OpenFromFile(\

24. 关于ITopologicalOperator接口(esriGeometry)

例子代码: Share a linesegment

ThissampleusesITopologicalOperator::Intersecttodotheequivalentofaselectbylocationwiththesharealinesegmentoperator.

Public Sub ShareLineSegment()

Dim pMxDocAsIMxDocument Set pMxDoc =ThisDocument Dim pMapAsIMap Set pMap =pMxDoc.FocusMap

Dim pFL1AsIFeatureLayer,pFL2AsIFeatureLayer Set pFL1 =pMap.Layer(0) 'firstlayerofmap Set pFL2 =pMap.Layer(1) 'secondlayer Dim pF1AsIFeature,pF2AsIFeature

Set pF1 =pFL1.FeatureClass.GetFeature(1)'getfeaturewith infirstlayer'sfeatureclass

Dim pfsAsIFeatureSelection Set pfs =pFL2 Dim idAsLong id =pfs.SelectionSet.IDs.Next 'getfirstidinselectionsetanactualfunctionwouldprobablyloopovertheselection

Set pF2 =pFL2.FeatureClass.GetFeature(id)'thisisline2

'isthereanintersectionbwthetwofeatures Dim pTopoAsITopologicalOperator

Set pTopo =pF1.Shape'storetheline1shapeinthetopoop If NotpTopo.IsSimpleThenpTopo.Simplify Dim pGeomAsIGeometry

Set pGeom =pTopo.Intersect(pF2.Shape,esriGeometry1Dimension)'getintersectionwithline2 If pGeom.IsEmptyThen

MsgBox \ Exit Sub End If

'pGeomnowcontainstheintersectionofpf1andpf2 'becausedimension =esriGeometry1Dimension 'itisageometryoftypepolyline

'iftheintersectionofthetwofeaturesconsistedofapointorpointspgeomwouldbeempty 'wecoulduseITopologicalOperator::Intersectwith0dimensiontofindaboutthosepoints

'ifpGeomcontainsonlytwoverticesthentheintersectionisasimplelinesegment '3verticesmeansit'sapolylinewithtwosuccessivesegments

'>3 means we haveseveral segments or a polyline or a combination of these Dim ppc1AsIPointCollection Set ppc1 =pGeom Dim lAsLong,gAsLong l =ppc1.PointCount If l =2Then

MsgBox \ ElseIf l =3Then

MsgBox \

ElseIf l > 3 Then

Dim pGeomCollAsIGeometryCollection Set pGeomColl =pGeom g = pGeomColl.GeometryCount

MsgBox \ End If

End Sub

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4