阅读:1775回复:2
[求助]IIdentify问题
<P>为什么我用IIdentify只能获得面要素,而对于点、线却总是获取不到?代码如下:</P>
<P>public override void OnMouseDown(int Button, int Shift, int X, int Y)<BR> {<BR> base.OnMouseDown (Button, Shift, X, Y);<BR> <BR> //Get the active view<BR> IActiveView activeView = m_HookHelper.ActiveView;<BR> map = activeView.FocusMap;<BR> identify = map.get_Layer(0) as IIdentify;<BR> point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);<BR> idArray = identify.Identify(point);</P> <P> if (idArray != null)<BR> {<BR> featIdObj = idArray.get_Element(0) as IFeatureIdentifyObj;<BR> idObj = featIdObj as IIdentifyObj;<BR> idObj.Flash(activeView.ScreenDisplay);<BR> MessageBox.Show("Layer: " + idObj.Layer.Name + "\n" + "Feature: " + idObj.Name);<BR> }<BR> }</P> <P>请各位高手多执教。</P> |
|
1楼#
发布于:2007-06-18 16:41
<P>因为你没有点中,:),在你的程序里,是需要用户精确的点中要素才显示相关信息的;你可以参照下面的例子,在点的附近建立一个矩形区域来查询要素</P>
<H1>FeatureIdentifyObject Example</H1><PRE><PRE><PRE><P>The following UIToolControl code uses the <STRONG>IIdentify::Identify </STRONG>method to get the <STRONG>FeatureIdentifyObject</STRONG> objects at the mouse-click location. Then, using the <STRONG>IIdentifyObj </STRONG>interface, some of the properties of the feature first identified are reported.</P><CODE><PRE>Private Sub UIToolControl1_MouseDown(ByVal button As Long, _<BR> ByVal shift As Long, ByVal x As Long, ByVal y As Long)<BR> Dim pMxApp As IMxApplication<BR> Dim pDoc As IMxDocument<BR> Dim pMap As IMap<BR> Dim pIdentify As IIdentify<BR> Dim pIDArray As IArray<BR> Dim pFeatIdObj As IFeatureIdentifyObj<BR> Dim pIdObj As IIdentifyObj<BR> Dim tol As Long<BR> Dim pEnv As IEnvelope<BR> Dim r As tagRECT<BR> <BR> Set pMxApp = Application<BR> Set pDoc = Application.Document<BR> Set pMap = pDoc.FocusMap<BR> Set pIdentify = pMap.Layer(0)<BR> tol = pDoc.SearchTolerancePixels<BR> <BR> 'consruct a small rectangle out of the x,y coord and the document's pixel tolerance<BR> r.Left = x - tol 'upper left x, top left is 0,0<BR> r.Top = y - tol 'upper left y, top left is 0,0<BR> r.Right = x + tol 'lower right x, top left is 0,0<BR> r.bottom = y + tol 'lower right y, top left is 0,0<BR> <BR> 'Tranform the device rectange into a geographic rectangle via the display transformation<BR> Set pEnv = New Envelope<BR> pMxApp.Display.DisplayTransformation.TransformRect pEnv, r, esriTransformPosition + esriTransformToMap<BR> <BR> 'setup the spatial reference on the newly hydrated envelope<BR> Set pEnv.SpatialReference = pMap.SpatialReference<BR> <BR> 'identify with the envelope<BR> Set pIDArray = pIdentify.Identify(pEnv)<BR> <BR> 'Get the FeatureIdentifyObject<BR> If Not pIDArray Is Nothing Then<BR> Set pFeatIdObj = pIDArray.Element(0)<BR> Set pIdObj = pFeatIdObj<BR> pIdObj.Flash pMxApp.Display<BR> 'Report info from FeatureIdentifyObject<BR> MsgBox "Layer: " ; pIdObj.Layer.Name ; vbNewLine ; "Feature: " ; pIdObj.Name<BR> Else<BR> MsgBox "No feature identified."<BR> End If<BR>End Sub<BR></PRE></CODE></PRE></PRE></PRE> |
|
|
2楼#
发布于:2007-06-19 10:27
多谢总统,但是我用的是AE,里面没有IMxDocument接口那我应该怎样获得那个容差呢?
|
|