wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1795回复:3

看看我的查询代码,错在哪里?

楼主#
更多 发布于:2004-12-21 11:59
<P>这段代码是实现IDentify的,对面查询没有问题,可是无法查询线和点(无法捕捉到线或点)。觉得很是奇怪,请问,错在哪里。</P>
<P>‘***************************************代码************************************</P>
<P>Private Function QueryTopMost(ByVal X As Long, ByVal Y As Long) As Boolean</P>
<P>   Dim pMap As IMap
   Dim pIdentify As IIdentify
   Dim pPoint As IPoint
   Dim pIDArray As IArray
   Dim pActiveView As IActiveView
   Dim i As Integer
   Dim blnHasFlash As Boolean '是否闪烁过了
   Dim intLayer As Integer
   Set pActiveView = m_pMap
 
   For intLayer = 0 To m_pMap.LayerCount - 1</P>
<P>      If m_pMap.Layer(intLayer).Visible Then
        
         Set pIdentify = m_pMap.Layer(intLayer) 'm_pLayerTop
         Set pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
         Set pIDArray = pIdentify.Identify(pPoint)
    
         If Not pIDArray Is Nothing Then</P>
<P>            Set m_pLayerTop = m_pMap.Layer(intLayer)</P>
<P>            Call IdentifyFlash(pIDArray, pActiveView, blnHasFlash)
            QueryTopMost = True
            Exit Function
         Else</P>
<P>            QueryTopMost = False
         End If</P>
<P>      End If</P>
<P>   Next intLayer</P>
<P>End Function
’*********************************************************************</P>
<P>当程序运行到Set pIDArray = pIdentify.Identify(pPoint)时,pIDArray 为Nothing,不知道为啥没有值?那个兄弟给指点一下。
</P>
喜欢0 评分0
wavvylia
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数384
  • QQ
  • 铜币555枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-12-21 17:33
<P>查到原因了,原来代码执行到Set pIDArray = pIdentify.Identify(pPoint)时,它需要一个容差值的,也就是说他要求要给定一个很小的区域而不是一个点,这样它才能捕捉到IFeature,所以pIDArray为空也就不奇怪了。呵呵,希望大家不要再走此弯路。
</P>
举报 回复(0) 喜欢(0)     评分
zhousky
论坛版主
论坛版主
  • 注册日期2003-08-01
  • 发帖数281
  • QQ
  • 铜币1027枚
  • 威望3点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-12-22 08:26
<P>这是我的代码,仅供参考</P><P>Public Sub mapIdentify(map As MapControl, x As Long, y As Long, tvw As TreeView, lvw As ListView, txtText As TextBox)
  tvw.Nodes.Clear
  lvw.ListItems.Clear
  Dim pPoint As IPoint
  Set pPoint = map.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)
  txtText.Text = "X= " ; Round(pPoint.x, 2) ; "  Y= " ; Round(pPoint.y, 2)
  Dim pEnv As IEnvelope
  Set pEnv = pPoint.Envelope
  pEnv.Expand map.Extent.Width / 300, map.Extent.Height / 300, False
  Dim pArray As IArray
  Dim i As Integer
  Dim j As Integer
  Dim pLayer As ILayer
  Dim pFeatureLayer As IFeatureLayer
  Dim pCompositeLayer As ICompositeLayer
  bHasAttribute = False  '------------------如果为真,就会显示属性表-----------------------
  For i = 0 To map.LayerCount - 1
    If TypeOf map.Layer(i) Is IGroupLayer And map.Layer(i).Name = "控沉分析" Then
      Set pCompositeLayer = map.Layer(i)
      For j = 0 To pCompositeLayer.Count - 1
        Set pLayer = pCompositeLayer.Layer(j)
        'Debug.Print pLayer.Name
        Set pFeatureLayer = pLayer
        Set pArray = GetArray(pLayer, pEnv)
        If Not pArray Is Nothing Then
          bHasAttribute = True
          Call AddFeatureToTvw(tvw, pFeatureLayer, pArray)
        End If
      Next
    End If
  Next
  '---------------------------窗口打开后,要在窗口中显示第一个子结点属性-------------------------
  If tvw.Nodes.Count <> 0 Then
    tvw.Nodes.Item(2).Selected = True
    Call AnalysisNode(lvw, tvw.SelectedItem, map, frmIdentify.chkLandSubsidence, frmIdentify.chkPointAttribute)
  End If
End Sub
</P>
不要看我噢
举报 回复(0) 喜欢(0)     评分
Qoo
Qoo
路人甲
路人甲
  • 注册日期2004-12-09
  • 发帖数216
  • QQ
  • 铜币1752枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2005-02-24 11:53
<P>我也不知道怎么搞,急于想知道!</P><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部