IdentifyDialog类的简单示例

Posted by 蒋波涛 29 August,2006 Views (10)Comment

这个类是用于模拟IdentifyDialog,但是代码写的比较简单,就是简单显示了一下数据,数据显示使用的是MSFlexGrid控件。

Public pMap As IMap
Dim valueArr() As String
Dim FieldCount As Integer

Public Sub AddLayerIdentifyPoint(ByVal pFeatLyr As IFeatureLayer, ByVal pPoint As IPoint)
    Dim pAV As IActiveView
    Set pAV = pMap
   
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pFeatLyr
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeatureLayer.FeatureClass
   
    FieldCount = pFeatureClass.Fields.FieldCount
   
    Dim pToPo As ITopologicalOperator
    Set pToPo = pPoint
    Dim pBufferGeo As IGeometry
    Set pBufferGeo = pToPo.Buffer(ConvertPixelsToMapUnits(pMap, 4))
    Dim pBufferEnv As IEnvelope
    Set pBufferEnv = pBufferGeo.Envelope
   
    Dim pSpatialFilter As ISpatialFilter
    Set pSpatialFilter = New SpatialFilter
    Set pSpatialFilter.Geometry = pBufferEnv
    pSpatialFilter.GeometryField = pFeatureClass.ShapeFieldName
   
    Select Case pFeatureClass.ShapeType
        Case 1
            pSpatialFilter.SpatialRel = esriSpatialRelContains
        Case 3
            pSpatialFilter.SpatialRel = esriSpatialRelCrosses
        Case 4
            pSpatialFilter.SpatialRel = esriSpatialRelIntersects
        Case Else
    End Select
   
    Dim pFeatCursor As IFeatureCursor
    Set pFeatCursor = pFeatureClass.Search(pSpatialFilter, False)
    Dim pFeat As IFeature
    Set pFeat = pFeatCursor.NextFeature
    Dim nField As Integer
   
    Do While Not pFeat Is Nothing
        For nField = 0 To FieldCount - 1
            ReDim Preserve valueArr(2, nField)
            valueArr(0, nField) = pFeat.Fields.Field(nField).Name
            If pFeat.Fields.Field(nField).Name <> "SHAPE" Then
                If pFeat.Value(nField) <> "" Then
                    valueArr(1, nField) = pFeat.Value(nField)
                Else
                    valueArr(1, nField) = "<NULL>"
                End If
            Else
                Select Case pFeatureClass.ShapeType
                    Case 1
                        valueArr(1, nField) = "Point"
                    Case 3
                        valueArr(1, nField) = "Polyline"
                    Case 4
                        valueArr(1, nField) = "Polygon"
                    Case Else
                End Select
            End If
        Next
        Set pFeat = pFeatCursor.NextFeature
    Loop
    DialogShow
End Sub

Public Sub DialogShow()
    Dim pFM2 As New Form2
    pFM2.MSFlexGrid1.Clear
    pFM2.MSFlexGrid1.Cols = 2
    pFM2.MSFlexGrid1.Rows = FieldCount
    Dim i As Integer
    For i = 0 To pFM2.MSFlexGrid1.Rows - 1
        pFM2.MSFlexGrid1.TextMatrix(i, 0) = valueArr(0, i)
        pFM2.MSFlexGrid1.TextMatrix(i, 1) = valueArr(1, i)
    Next
    pFM2.Show
End Sub

Private Function ConvertPixelsToMapUnits(pMap As IMap, pixelUnits As Double) As Double
  Dim pActiveView As IActiveView
  Set pActiveView = pMap
 
  Dim realWorldDisplayExtent As Double
  Dim pixelExtent As Integer
  Dim sizeOfOnePixel As Double

  pixelExtent = pActiveView.ScreenDisplay.DisplayTransformation.DeviceFrame.Right - pActiveView.ScreenDisplay.DisplayTransformation.DeviceFrame.Left
  realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width
  sizeOfOnePixel = realWorldDisplayExtent / pixelExtent
  ConvertPixelsToMapUnits = pixelUnits * sizeOfOnePixel

End Function

调用这个类也很简单:
Private Sub MapControl1_OnMouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long, ByVal mapX As Double, ByVal mapY As Double)
    Dim pid As New IdentifyDialog
    Dim pPt As IPoint
    Set pPt = New Point
    pPt.x = mapX
    pPt.y = mapY
    Set pid.pMap = MapControl1.Map
    pid.AddLayerIdentifyPoint MapControl1.Map.Layer(0), pPt

End Sub

Related Items

Categories : ArcObjects Tags : ArcObjects  
Comments
2006-10-19 15:21:14

hello...
i have a problem for ArcObject.
how can I do and write that create my owner Attributs and can Editor Data when i select a line in Map.
Please Help me,and i hope your anwser.thank you sir.
PS:I Use VBA develop ArcObject.

Posted by hinet Gravatar Icon

2006-10-19 16:18:49

Do u want update a feature?it is very easy.While u get a feature,you can get the feature's shape,use IFeature.Shape,then you can set a new value to it,as well as other fields.
for example:
pFeat.value(pFeat.findField("Name"))="jack"
pFeat.shape=pNewShape
pFeat.store
------------------------------
you can also read the blog's article about cursor or read my book.Sly smile

Posted by 蒋波涛 Gravatar Icon

2006-10-31 11:58:06

teacher....
i have another problem.
how can i do that i select some line in map,and about line's attribute
information will show in TextBox
when i click my button and my userform will show.

Please Help me,and i hope your anwser.thank you sir.
PS:I Use VBA develop ArcObject.

Posted by hinet Gravatar Icon

2006-10-31 16:31:08

Using VBA develop AO,you should create a UIToolControl in "Customize——Commands——UIControls".The item is different from macro,it has many events,so you can create a UIToolControl1_MouseDown event。
In the event,you should use IMap:selectbyShape.then u will create a selection.you will get information about the selected features in the selectionset of each featurelayer.
of course,it is very simple description about it.you can buy my book in this web store:http://www.welan.com.tw/.
I wish it can give u more help for u.

Posted by 蒋波涛 Gravatar Icon

2006-12-17 15:17:23

用VB+AE实现对矢量图编辑功能,在AE有一例子,但不能显示vertex; 在AO例子中,有显示vertex颜色和大小的程序,但不能直接转到VB+AE中,下面程序是AO显示vertex颜色和大小的,如何脱离ArcMap?
Dim pEditor As IEditor
Dim pID As New UID
Dim pEditProps As IEditProperties
Dim pVertexSym As ISimpleMarkerSymbol
Dim pVertexColor As IRgbColor
Dim pSelectedColor As IRgbColor
Dim pSelectedVertexSym As ISimpleMarkerSymbol
pID = "esricore.editor"
Set pEditor = Application.FindExtensionByCLSID(pID)
Set pEditProps = pEditor
Set pVertexColor = New RgbColor
pVertexColor.Blue = 150
Set pVertexSym = New SimpleMarkerSymbol
With pVertexSym
.Color = pVertexColor
.Style = esriSMSDiamond
.Size = 8
End With
Set pEditProps.SketchVertexSymbol = pVertexSym
Set pSelectedVertexSym = New SimpleMarkerSymbol
Set pSelectedColor = New RgbColor
pSelectedColor.Red = 255
With pSelectedVertexSym
.Color = pSelectedColor
.Size = 8
.Style = esriSMSDiamond
End With
Set pEditProps.SelectedVertexSymbol = pSelectedVertexSym

Posted by lzh Gravatar Icon

2006-12-17 17:53:56

IEditor InterfaceSee Also
IEditEvents Interface | IEditTask.OnDeleteSketch Method | IEditSketch Interface | IEditTask.Name Property | ISnapEnvironment Interface | IEditProperties Interface | IEditTask.Deactivate Method | Editor Class | IEditTask.OnFinishSketch Method | IEditEvents2 Interface | IEditor Interface | IEditTask.Activate Method | IEditLayers Interface | IDatasetEditInfo Interface | IDatasetEdit Interface | IApplication Interface | IMap Interface Language
Visual Basic 6.0

Show All
Provides access to members that control the behavior of the editor. Note: the IEditor interface has been superseded by IEditor2. Please consider using the more recent version.

Product Availability
Available with ArcGIS Desktop.

看最后一句英文。

Posted by 蒋波涛 Gravatar Icon

2006-12-17 21:24:54

Dim pLine As ILine
Dim pFromPoint As IPoint
Dim pToPoint As IPoint
pFromPoint = New Point
pFromPoint.PutCoords(30, 30)
pToPoint = New Point
pToPoint.PutCoords(10, 10)
pLine = New Line
pLine.PutCoords(pFromPoint, pToPoint)
通过上面的方法产生一个Line对象后,然后定义 Dim pEle As IElement;将pEle对象的Geometry进行如下设置:
pEle.Geometry = pLine
但是为什么提示上面不正确呢。IElement的
Geometry时候可以设置为ILine对象。


2006-12-17 21:26:55

上面的问题是IElement的Geometry属性是否可以设置为ILine。

Posted by 补充 Gravatar Icon

2006-12-17 22:05:24

问题已经解决了,对于Geometry的理解看来还是有些问题。对于波涛的书理解也还不够,另外对象模型图也复杂了点。有时候弄的晕头转向的。希望波涛能够对于AO体系结构和模型的介绍能够再多些。谢谢!

Posted by 问题解决了 Gravatar Icon

2008-12-24 16:07:24

请问如何在SCENECONTROL里面调用IIdentifyDialog,我已经实现MapControl了,就是实现不了SceneControl,谢谢啦
-------------------------------------------------
没弄过这个东西,并且对Scene并不看好
由 jbttm 于 2008-12-26 9:02:10 最后编辑

Posted by 何金胜 Gravatar Icon

Leave a comment

Or, take a look at Archives and Categories

目录

存档