level 5
glasseswu
楼主
原理是差不多的,接口有点不同了,下面的例子你可以看看
\'Identifies point in scene using x,y coordinates and returns ID of selected point
\'The function was used by taking the x/y coordinates from the Scen1_OnMouseDown
event and passing into the functrion as newY and newY
Public Function IdentifyPointXY(newX As Double, newY As Double) As Double
Dim pActiveView As IActiveView
Dim pMap As IMap
Dim pIdentify As IIdentify
Dim pPoint As IPoint
Dim pEnvelope As IEnvelope
Dim pIDArray As IArray
Dim pIdObj As IIdentifyObj
Dim pFeatIdObj As IFeatureIdentifyObj
Dim pRowObj As IRowIdentifyObject
Dim pIdentifyDialog As IIdentifyDialog
Dim pLayer As ILayer
Dim pFeature As IFeature
Set pLayer = MainForm.Scene1.SceneGraph.Scene.Layer(0)
Set pScene = MainForm.Scene1.SceneGraph.Scene
\'Identify a shapefile point
If TypeOf pLayer Is IFeatureLayer Then
Set pIdentify = pLayer \'topmost layer
Set pPoint = New Point
pPoint.PutCoords newX, newY
Set pEnvelope = pPoint.Envelope
pEnvelope.Expand 0.01, 0.01, False
Set pIDArray = pIdentify.Identify(pEnvelope)
\'Get the FeatureIdentifyObject
If Not pIDArray Is Nothing Then
\'tempLength = pIDArray.Element(0)
Set pFeatIdObj = pIDArray.Element(0)
a = pIDArray.Count
\'Form1.Text4.Text = CStr(tempLength)
Set pIdObj = pFeatIdObj
\'Set pIdObj = pIDArray.Count
Set pRowObj = pFeatIdObj
Set pFeature = pRowObj.Row
\'MainForm.SceneIDText.Text = CStr(pFeature.OID)
Set pScene = MainForm.Scene1.SceneGraph.Scene
Dim pGeom As IGeometry
Set pGeom = pFeature.Shape
Dim bJustOne As Boolean
pScene.SelectByShape pGeom, Nothing, bJustOne
\'Output ID of selected feature
IdentifyPointXY = pFeature.OID
Else
MsgBox "No feature identified.", vbCritical
\'Stop
End If
\'Identify a raster point
ElseIf TypeOf pLayer Is IRasterLayer Then
\'
Dim pRLayer As IRasterLayer
Set pRLayer = pLayer
Dim pSurf As IRasterSurface
Dim p3DProp As I3DProperties
Dim pLE As ILayerExtensions
Set pLE = pLayer
Dim i As Integer
\'look for 3D properties of layer:
For i = 0 To pLE.ExtensionCount - 1
If TypeOf pLE.Extension(i) Is I3DProperties Then
Set p3DProp = pLE.Extension(i)
Exit For
End If
Next
\'look first for base surface of layer:
2011年08月11日 14点08分
1
\'Identifies point in scene using x,y coordinates and returns ID of selected point
\'The function was used by taking the x/y coordinates from the Scen1_OnMouseDown
event and passing into the functrion as newY and newY
Public Function IdentifyPointXY(newX As Double, newY As Double) As Double
Dim pActiveView As IActiveView
Dim pMap As IMap
Dim pIdentify As IIdentify
Dim pPoint As IPoint
Dim pEnvelope As IEnvelope
Dim pIDArray As IArray
Dim pIdObj As IIdentifyObj
Dim pFeatIdObj As IFeatureIdentifyObj
Dim pRowObj As IRowIdentifyObject
Dim pIdentifyDialog As IIdentifyDialog
Dim pLayer As ILayer
Dim pFeature As IFeature
Set pLayer = MainForm.Scene1.SceneGraph.Scene.Layer(0)
Set pScene = MainForm.Scene1.SceneGraph.Scene
\'Identify a shapefile point
If TypeOf pLayer Is IFeatureLayer Then
Set pIdentify = pLayer \'topmost layer
Set pPoint = New Point
pPoint.PutCoords newX, newY
Set pEnvelope = pPoint.Envelope
pEnvelope.Expand 0.01, 0.01, False
Set pIDArray = pIdentify.Identify(pEnvelope)
\'Get the FeatureIdentifyObject
If Not pIDArray Is Nothing Then
\'tempLength = pIDArray.Element(0)
Set pFeatIdObj = pIDArray.Element(0)
a = pIDArray.Count
\'Form1.Text4.Text = CStr(tempLength)
Set pIdObj = pFeatIdObj
\'Set pIdObj = pIDArray.Count
Set pRowObj = pFeatIdObj
Set pFeature = pRowObj.Row
\'MainForm.SceneIDText.Text = CStr(pFeature.OID)
Set pScene = MainForm.Scene1.SceneGraph.Scene
Dim pGeom As IGeometry
Set pGeom = pFeature.Shape
Dim bJustOne As Boolean
pScene.SelectByShape pGeom, Nothing, bJustOne
\'Output ID of selected feature
IdentifyPointXY = pFeature.OID
Else
MsgBox "No feature identified.", vbCritical
\'Stop
End If
\'Identify a raster point
ElseIf TypeOf pLayer Is IRasterLayer Then
\'
Dim pRLayer As IRasterLayer
Set pRLayer = pLayer
Dim pSurf As IRasterSurface
Dim p3DProp As I3DProperties
Dim pLE As ILayerExtensions
Set pLE = pLayer
Dim i As Integer
\'look for 3D properties of layer:
For i = 0 To pLE.ExtensionCount - 1
If TypeOf pLE.Extension(i) Is I3DProperties Then
Set p3DProp = pLE.Extension(i)
Exit For
End If
Next
\'look first for base surface of layer: