public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper != null) { IPoint pPt; IActiveView pActiveView; ClsDeclare.g_strUnit = ClsDeclare.g_UnitConverter.CurrentUnitName; pActiveView = m_hookHelper.ActiveView; pPt = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //得到最近地物 Collection pFeatures = null; IFeature pFeature = null; ClsSearch.PfgisGetClosestFeature(m_Map, pPt, ref pFeatures, ref pFeature); if (pFeature == null) { return; } if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { ClsSearch.FlashFeature(pActiveView, pFeature); IPolygon pPolygon; pPolygon = (IPolygon)pFeature.ShapeCopy; IArea pArea; if (ClsDeclare.g_strUnit == "度") { ClsDeclare.g_UnitConverter.SetCurrentMapUnit(ClsDeclare.g_UnitConverter.DefaultMapUnit); ClsDeclare.g_strUnit = ClsDeclare.g_UnitConverter.CurrentUnitName; } pArea = ClsDeclare.g_UnitConverter.ConvertGeometryCoordinate(pPolygon) as IArea; m_dArea = pArea.Area; m_dArea = Convert.ToDouble(string.Format("{0:#######0.00}", m_dArea)); ClsDeclare.g_txtMeasure.Clear(); ClsDeclare.g_txtMeasure.Text = "面要素量算" + "\r" + "\n" + "要素面积:" + Math.Abs(m_dArea) + "平方" + ClsDeclare.g_strUnit + "\r" + "\n" + "要素长度:" + string.Format("{0:#######0.00}", ClsDeclare.g_UnitConverter.ConvertPolyonCoordinate(pPolygon).Length) + ClsDeclare.g_strUnit; } else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { ClsSearch.FlashFeature(pActiveView, pFeature); IPolyline pPolyline; pPolyline = ClsDeclare.g_UnitConverter.ConvertGeometryCoordinate(pFeature.ShapeCopy) as IPolyline; ClsDeclare.g_txtMeasure.Clear(); ClsDeclare.g_txtMeasure.Text = "线要素量算" + "\r" + "\n" + "要素长度:" + string.Format("{0:#######0.00}", pPolyline.Length) + ClsDeclare.g_strUnit; } else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { ClsSearch.FlashFeature(pActiveView, pFeature); IPoint pPointFeature; pPointFeature = ClsDeclare.g_UnitConverter.ConvertGeometryCoordinate(pFeature.ShapeCopy) as IPoint; ClsDeclare.g_txtMeasure.Clear(); ClsDeclare.g_txtMeasure.Text = "点要素" + "\r" + "\n" + "X: " + pPointFeature.X + ClsDeclare.g_strUnit + "\r" + "\n" + "Y: " + pPointFeature.Y + ClsDeclare.g_strUnit; } } else if (m_sceneHookHelper != null) { } else if (m_globeHookHelper != null) { } }
public static void PfgisGetClosestFeature(IMap pMap, IPoint pSearchPt, ref Collection pSelected, ref IFeature pFeatureClosest) { ClsMapLayer pConvert = new ClsMapLayer(); //初始化返回值 pSelected = new Collection(); pFeatureClosest = null; //设置搜索范围 IEnvelope pSrchEnv; pSrchEnv = pSearchPt.Envelope; double SearchDist; SearchDist = 4d; IActiveView pActiveView; pActiveView = pMap as IActiveView; SearchDist = ClsMapLayer.ConvertPixelsToMapUnits(pActiveView, SearchDist); pSrchEnv.Width = SearchDist; pSrchEnv.Height = SearchDist; pSrchEnv.CenterAt(pSearchPt); UIDClass pUID = new UIDClass(); pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; IEnumLayer pLayers; pLayers = pMap.get_Layers(pUID, true); ILayer pLayer; pLayer = pLayers.Next(); while (pLayer != null) { IGeoFeatureLayer pGeoLayer; pGeoLayer = (IGeoFeatureLayer)pLayer; if (pGeoLayer.Selectable && pGeoLayer.Visible && pGeoLayer.FeatureClass != null) { IIdentify2 pID; pID = (IIdentify2)pGeoLayer; //根据查询范围执行查询操作 IArray pArray; pArray = pID.Identify(pSrchEnv, null); IFeatureIdentifyObj pFeatIdObj; IRowIdentifyObject pRowObj; IFeature pFeature; if (pArray != null) { for (int j = 0; j < pArray.Count; j++) { if (pArray.get_Element(j) is IFeatureIdentifyObj) { pFeatIdObj = pArray.get_Element(j) as IFeatureIdentifyObj; pRowObj = pFeatIdObj as IRowIdentifyObject; pFeature = pRowObj.Row as IFeature; pSelected.Add(pFeature, null, null, null); } } pArray.RemoveAll(); } } pLayer = pLayers.Next(); } ClsSearch.PfgisGetClosestFeatureInCollection(SearchDist, pSelected, pSearchPt, ref pFeatureClosest); }