/// <summary> /// Performs an identify operation with the provided geometry. /// When identifying layers, typically a small envelope is passed in rather than a point to account for differences in /// the precision of the display and the feature geometry. /// </summary> /// <param name="source">The source.</param> /// <param name="geometry">The geometry.</param> /// <param name="trackCancel"> /// The cancel tracker object to monitor the Esc key and to terminate processes at the request of /// the user. /// </param> /// <returns> /// Returns a <see cref="IEnumerable{IFeatureIdentifyObj}" /> representing the features that have been identified. /// </returns> /// <exception cref="System.ArgumentNullException">geometry</exception> /// <remarks> /// On a FeatureIdentifyObject, you can do a QI to the IIdentifyObj interface to get more information about the /// identified feature. The IIdentifyObj interface returns the window handle, layer, and name of the feature; it has /// methods to flash the /// feature in the display and to display a context menu at the Identify location. /// </remarks> public static IEnumerable <IFeatureIdentifyObj> Identify(this IFeatureLayer source, IGeometry geometry, ITrackCancel trackCancel) { if (geometry == null) { throw new ArgumentNullException("geometry"); } if (source != null) { IIdentify2 identify = (IIdentify2)source; IArray array = identify.Identify(geometry, trackCancel); if (array != null) { for (int i = 0; i < array.Count; i++) { if (trackCancel != null && !trackCancel.Continue()) { break; } IFeatureIdentifyObj featureIdentify = array.Element[i] as IFeatureIdentifyObj; yield return(featureIdentify); } } } }
/// <summary> /// 判断鼠标点击处有无巷道要素 /// </summary> /// <param name="m_hookHelper"></param> /// <param name="pMousePoint">鼠标点</param> /// <param name="pFeatureLayer">导线点图层</param> /// <param name="theFeature">返回离鼠标最近的导线点</param> public void TestExistPointFeature(IHookHelper m_hookHelper, IPoint pMousePoint, IFeatureLayer pFeatureLayer, ref IFeature theFeature) { ArrayList pSelected = new ArrayList(); IFeatureClass pFeatureClass; ISelectionEnvironment pSelectionEnvironment; IFeature pFeature = null; IGeometry pGeometry; ITopologicalOperator pTopolagicalOperator; double dLength; IEnvelope pSrchEnv; pSelectionEnvironment = new SelectionEnvironmentClass(); dLength = pSelectionEnvironment.SearchTolerance; pGeometry = pMousePoint; dLength = DataEditCommon.ConvertPixelDistanceToMapDistance(m_hookHelper.ActiveView, dLength); pSrchEnv = pMousePoint.Envelope; pSrchEnv.Width = dLength; pSrchEnv.Height = dLength; pSrchEnv.CenterAt(pMousePoint); pTopolagicalOperator = (ITopologicalOperator)pGeometry; IGeometry pBuffer = pTopolagicalOperator.Buffer(dLength); pGeometry = pBuffer; IFeature pFeat = null; IMap pMap = m_hookHelper.FocusMap; pFeatureClass = pFeatureLayer.FeatureClass; IIdentify2 pID = pFeatureLayer as IIdentify2; //IArray pArray = pID.Identify(pSrchEnv, null); IArray pArray = pID.Identify(pGeometry, null); IFeatureIdentifyObj pFeatIdObj; IRowIdentifyObject pRowObj; if (pArray != null) { for (int j = 0; j < pArray.Count; j++) { if (pArray.Element[j] is IFeatureIdentifyObj) { pFeatIdObj = pArray.Element[j] as IFeatureIdentifyObj; pRowObj = pFeatIdObj as IRowIdentifyObject; pFeature = pRowObj.Row as IFeature; pSelected.Add(pFeature); } } pArray.RemoveAll(); } theFeature = pFeature; return; //GetClosestFeatureInCollection(m_hookHelper, dLength, pSelected, pMousePoint, ref pFeat); //if (pFeat != null) // theFeature = pFeat; //else // theFeature = null; }
private IArray Identify(ILayer identifyLayer, IGeometry identifyGeom) { //保存结果的变量 IArray identifyObjs = null; //设置查询形状 if (identifyGeom == null) { //返回空值 return(identifyObjs); } //若是点的话做点的缓冲区 IGeometry hitGeometry = identifyGeom; //判断图层类型,设置点击要素 if (hitGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { ITopologicalOperator topoOp = identifyGeom as ITopologicalOperator; hitGeometry = topoOp.Buffer(1); } ///判断图层的类型并作相应处理 ///图层是要素图层 if (identifyLayer is IFeatureLayer) { //获取要素图层 IFeatureLayer featureLayer = identifyLayer as IFeatureLayer; //开始获取信息操作 IIdentify2 identify2 = featureLayer as IIdentify2; //获取查询结果 identifyObjs = identify2.Identify(hitGeometry, null); } ///图层是栅格数据层 else if (identifyLayer is IRasterLayer) { } //返回获取要素的集合 return(identifyObjs); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_pActiveView == null || Button != 1) { return; } ArrayList pSelected = new ArrayList(); IFeatureClass pFeatureClass; IPoint pPoint; ISelectionEnvironment pSelectionEnvironment; IFeature pFeature; IGeometry pGeometry; ITopologicalOperator pTopolagicalOperator; double dLength; IEnvelope pSrchEnv; pSelectionEnvironment = new SelectionEnvironmentClass(); dLength = pSelectionEnvironment.SearchTolerance; pPoint = m_pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint); pGeometry = pPoint; dLength = Common.DataEditCommon.ConvertPixelDistanceToMapDistance(m_pActiveView, dLength); pSrchEnv = pPoint.Envelope; pSrchEnv.Width = dLength; pSrchEnv.Height = dLength; pSrchEnv.CenterAt(pPoint); pTopolagicalOperator = (ITopologicalOperator)pGeometry; IGeometry pBuffer = pTopolagicalOperator.Buffer(dLength); pGeometry = pBuffer; IFeatureLayer pFeatureLayer; IFeature pFeat = null; IMap pMap = m_hookHelper.FocusMap; //for (int i = 0; i < pMap.LayerCount; i++) //{ //if (pMap.get_Layer(i).Name !=Common.DataEditCommon.g_pLayer.Name) continue;//20140216 lyf 只对当前选择图层进行 //if (pMap.get_Layer(i).Visible == false || !(pMap.get_Layer(i) is IFeatureLayer)) //{ // continue; //} if (Common.DataEditCommon.g_pLayer == null) { return; } pFeatureLayer = Common.DataEditCommon.g_pLayer as IFeatureLayer; pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass == null) { return; } IIdentify2 pID = pFeatureLayer as IIdentify2; IArray pArray = pID.Identify(pSrchEnv, null); //20140216 lyf 没有选中图元情况处理 if (pArray == null) { MessageBox.Show(@"未选中当前图层的图元!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //continue; return; } IFeatureIdentifyObj pFeatIdObj; IRowIdentifyObject pRowObj; if (pArray != null) { for (int j = 0; j < pArray.Count; j++) { if (pArray.Element[j] is IFeatureIdentifyObj) { pFeatIdObj = pArray.Element[j] as IFeatureIdentifyObj; pRowObj = pFeatIdObj as IRowIdentifyObject; pFeature = pRowObj.Row as IFeature; pSelected.Add(pFeature); pSelected.Add(pFeatureLayer.Name); pSelected.Add(0); } } pArray.RemoveAll(); } //} GetClosestFeatureInCollection(dLength, pSelected, pPoint, ref pFeat); if (pFeat != null) { if (m_pfrmFeatureAttribute == null) { m_pfrmFeatureAttribute = new FeatureAttribute(pFeat); m_pfrmFeatureAttribute.StartPosition = FormStartPosition.CenterParent; m_pfrmFeatureAttribute.Show(); } else { m_pfrmFeatureAttribute.Close(); m_pfrmFeatureAttribute.Dispose(); m_pfrmFeatureAttribute = new FeatureAttribute(pFeat); m_pfrmFeatureAttribute.StartPosition = FormStartPosition.CenterParent; m_pfrmFeatureAttribute.Show(); } } }