阅读:1731回复:5
请高手帮忙看看这段代码(vb+ao)
<P>我要做元素的选择,以下代码在8.3中用语句5是正确的,用4没有选中元素,</P>
<P>而在9.0中用语句5会出现自动化错误,用4还是没有选中元素,</P> <P>请大侠们指点一二</P> <P>Dim pEnumElement As IEnumElement<BR>Dim pGraphicsContainer As IGraphicsContainer<BR> <BR>Set pGraphicsContainer = MapControl1.Map<BR>Set pEnumElement = pGraphicsContainer.LocateElementsByEnvelope(pEnvelope) '4<BR>Set pEnumElement = pGraphicsContainer.LocateElements(pPoint,5) '5<BR>If pEnumElement Is Nothing Then Exit Sub</P> |
|
1楼#
发布于:2005-07-07 11:03
这段代码在逻辑上没什么错误,你再好好看看上下文,也许是一个非常小的错误,如某个变量少了一个字母!
|
|
2楼#
发布于:2005-07-07 16:09
<P>我想应该不是有错,因为在8.3下是可以的</P>
<P>有没有哪位大侠在engine中做过元素选择功能,还有其他办法吗?</P> |
|
3楼#
发布于:2005-07-07 17:50
<img src="images/post/smile/dvbbs/em08.gif" />已经解决了,代码没错,只是pPoint忘了赋值
|
|
4楼#
发布于:2005-11-21 11:40
<P 0cm 0cm 0pt"><FONT face="Times New Roman">Option Explicit</FONT></P>
<P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">'Implements ICommand</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Dim ss As String</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Dim pSelected As IEnumFeature</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Dim pFeature As IFeature</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private m_pApp As IApplication</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private m_pFeedbackEnv As INewEnvelopeFeedback</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private m_pPoint As IPoint</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private m_bIsMouseDown As Boolean</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private m_pFLayer As IFeatureLayer ' layer to search</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private Sub Form_Resize()</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MapControl1.Top = Me.ScaleTop</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MapControl1.Height = Me.ScaleHeight</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MapControl1.Width = Me.ScaleWidth</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">End Sub</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">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)</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pMxDoc As IMxDocument</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pActiveView As IActiveView</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Set pMxDoc = m_pApp.Document</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pActiveView = MapControl1.ActiveView</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Store current point, set mousedown flag</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set m_pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' MsgBox m_pPoint.ID</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> m_bIsMouseDown = True</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set m_pFeedbackEnv = Nothing</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'MsgBox m_pPoint.x</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">End Sub</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private Sub MapControl1_OnMouseMove(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long, ByVal mapX As Double, ByVal mapY As Double)</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> On Error GoTo ErrorHandler</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> If Not m_bIsMouseDown Then Exit Sub</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Get the ActiveView for the map</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pMxDoc As IMxDocument</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pActiveView As IActiveView</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Set pMxDoc = m_pApp.Document</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pActiveView = MapControl1.ActiveView</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Create a rubber banding box, if it hasn't been created already</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> If (m_pFeedbackEnv Is Nothing) Then</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set m_pFeedbackEnv = New NewEnvelopeFeedback</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set m_pFeedbackEnv.Display = pActiveView.ScreenDisplay</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> m_pFeedbackEnv.Start m_pPoint</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' MsgBox m_pPoint.x</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> End If</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Store current point, and use to move rubberband</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set m_pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> m_pFeedbackEnv.MoveTo m_pPoint</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Exit Sub</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">ErrorHandler:</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MsgBox "An error has occured within the Zoom Out Tool." ; vbCr ; vbCr ; _</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> "Error Details : " ; Err.Description, vbExclamation + vbOKOnly, "Error"</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">End Sub</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">Private Sub MapControl1_OnMouseUp(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long, ByVal mapX As Double, ByVal mapY As Double)</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pEnv As IEnvelope</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pFilter As ISpatialFilter</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pActiveView As IActiveView</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pMxDoc As IMxDocument</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Dim pFeat As IFeature</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> On Error GoTo ErrorHandler</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Get the ActiveView for the map</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Set pMxDoc = m_pApp.Document</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pActiveView = MapControl1.ActiveView</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">'''''''''''''''''''''''''''''''''''</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">'Set pFilter = New SpatialFilter</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Set pFilter.Geometry = pActiveView.Extent</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'pFilter.SpatialRel=esri</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> '''''''''''''''''''''''''''''''''''''''''''''''''</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Refresh the selections</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' If user dragged an envelope...</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> If (Not m_pFeedbackEnv Is Nothing) Then</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Use it to calculate new extent</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pEnv = m_pFeedbackEnv.Stop</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Select all feature that intersect with that shape</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MapControl1.Map.SelectByShape pEnv, Nothing, False</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'pMxDoc.FocusMap.SelectByShape pEnv, Nothing, False</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Else...</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Else</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Select by point</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'pMxDoc.FocusMap.SelectByShape m_pPoint, Nothing, False</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MapControl1.Map.SelectByShape m_pPoint, Nothing, False</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> End If</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> If (MapControl1.Map.SelectionCount <> 1) Then Exit Sub</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> If MapControl1.Map.SelectionCount = 1 Then</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MsgBox "</FONT>已经选中一个要素<FONT face="Times New Roman">"</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> End If</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pSelected = MapControl1.Map.FeatureSelection</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> pSelected.Reset</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> ' Refresh the selecti</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pFeature = pSelected.Next</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> If (Not pFeature Is Nothing) Then</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MsgBox pFeature.Value(pFeature.Fields.FindField("</FONT>编号<FONT face="Times New Roman">"))</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set pFeature = pSelected.Next</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> End If</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Reset rubberband and mousedown state</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> Set m_pFeedbackEnv = Nothing</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> m_bIsMouseDown = False</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 'Exit Sub</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">ErrorHandler:</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> MsgBox "An error has occured within the Select Tool." ; vbCr ; vbCr ; _</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> "Error Details : " ; Err.Description, vbExclamation + vbOKOnly, "Error"</FONT></P> <P 0cm 0cm 0pt"><p><FONT face="Times New Roman"> </FONT></p></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> </FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">End Sub</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman"> 请那位高手看看我这段代码怎么有什么错误。</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">pFeature.Value(pFeature.Fields.FindField("编号")) 为空值。</FONT></P> <P 0cm 0cm 0pt"><FONT face="Times New Roman">请问高手,怎么选中一个要素,并得到该要素某个字段值</FONT></P> |
|
5楼#
发布于:2005-11-25 14:32
你把<FONT face="Times New Roman">MapControl1.Map.SelectByShape m_pPoint, Nothing, False中的m_pPoint的类型转换为IGeometry再试试看!</FONT>
|
|