public static IEnumFeature SelectByPolygon(IMap pMap, IPolygon pPolygon, esriSpatialRelEnum pSpatialRelEnum) { ISelectionEnvironment selectionEnvironmentClass = new SelectionEnvironmentClass() { AreaSelectionMethod = pSpatialRelEnum, LinearSelectionMethod = pSpatialRelEnum, PointSelectionMethod = pSpatialRelEnum, CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew }; try { pMap.SelectByShape(pPolygon, selectionEnvironmentClass, false); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147467259) { //Logger.Current.Error("",cOMException, ""); } else { MessageBox.Show("执行查询时产生错误。空间索引不存在", "选择"); } } catch (Exception exception) { //Logger.Current.Error("",exception, ""); } return((IEnumFeature)pMap.FeatureSelection); }
public static SelectionEnvironmentClass System_Selection_Environment(IActiveView activeView) { if (m_System_Selection_Option == null) { m_System_Selection_Option = SelectOption.GetSelectOption(); } if (m_System_SelectionEnvironment == null) { m_System_SelectionEnvironment = new SelectionEnvironmentClass(); } double tol = PublicFunction.ConvertPixelsToMapUnits(activeView, m_System_Selection_Option.Tolerate); m_System_SelectionEnvironment.PointSearchDistance = tol; m_System_SelectionEnvironment.LinearSearchDistance = tol; m_System_SelectionEnvironment.AreaSearchDistance = tol; m_System_SelectionEnvironment.PointSelectionMethod = (esriSpatialRelEnum)m_System_Selection_Option.SelectRelection; m_System_SelectionEnvironment.LinearSelectionMethod = (esriSpatialRelEnum)m_System_Selection_Option.SelectRelection; m_System_SelectionEnvironment.AreaSelectionMethod = (esriSpatialRelEnum)m_System_Selection_Option.SelectRelection; m_System_SelectionEnvironment.ClearInvisibleLayers = m_System_Selection_Option.ClearInVisible; m_System_SelectionEnvironment.CombinationMethod = (esriSelectionResultEnum)m_System_Selection_Option.ResultMethod; m_System_SelectionEnvironment.DefaultColor = PublicFunction.GetSelectionColor(m_System_Selection_Option.DefaultColorRGB); m_System_SelectionEnvironment.SearchTolerance = (int)tol; m_System_SelectionEnvironment.ShowSelectionWarning = m_System_Selection_Option.ShowWarning; m_System_SelectionEnvironment.WarningThreshold = m_System_Selection_Option.WarningThreshold; return(m_System_SelectionEnvironment); }
/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { IEnumFeature pEnumFeature = m_MapControl.Map.FeatureSelection as IEnumFeature; if (pEnumFeature == null || m_MapControl.Map.SelectionCount != 1) { return; } pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); if (pFeature == null) { return; } //画出图形各节点 if (MoData.v_bVertexSelectionTracker == true) { ModPublic.DrawEditSymbol(pFeature.Shape, m_MapControl.ActiveView); } //设置点选容差 ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass(); m_dblTolearance = ModPublic.ConvertPixelsToMapUnits(m_hookHelper.ActiveView, pSelectEnv.SearchTolerance); m_pFeature = pFeature; }
private IFeature SelctFeatureBasedMousePoint(IPoint pPoint) { //对点对象做缓冲区运算 ITopologicalOperator pTopo = pPoint as ITopologicalOperator; IGeometry pBuffer = pTopo.Buffer(0.5); IGeometry pGeometry = pBuffer.Envelope; SetAllPolylinePolygonLayersSelectable(); ISelectionEnvironment selEnvironment = new SelectionEnvironmentClass(); selEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; m_map.SelectByShape(pGeometry, selEnvironment, true); IEnumFeature SelectedFeatures = m_map.FeatureSelection as IEnumFeature; SelectedFeatures.Reset(); IFeature extendFeature = SelectedFeatures.Next(); SetAllLayersSelectable(); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent); if (extendFeature != null && extendFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { return(extendFeature); } return(null); }
public void OnClick() { if (_view.SelectedItemType == esriTOCControlItem.esriTOCControlItemLayer && _view.SelectedLayer != null) { IActiveView pActiveView = _view.SelectedMap as IActiveView; if (pActiveView != null) { if (_view.SelectedLayer is IFeatureLayer) { IFeatureSelection featureSelection = _view.SelectedLayer as IFeatureSelection; if (featureSelection != null) { int count = featureSelection.SelectionSet.Count; ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); if ((_view.SelectedLayer as IFeatureLayer).FeatureClass.FeatureCount(null) - count <= (pSelectionEnvironment as ISelectionEnvironmentThreshold).WarningThreshold || MessageBox.Show("所选择记录较多,执行将花较长时间,是否继续?", "选择", MessageBoxButtons.YesNo) != DialogResult.No) { featureSelection.SelectFeatures(null, esriSelectionResultEnum.esriSelectionResultXOR, false); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, featureSelection, null); } } } } } }
//判断鼠标是否在已选择要素的节点上 public static bool MouseOnFeatureVertex(IPoint pPnt, IFeature pFeature, IActiveView pActiveView) { //设置点选择容差 ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass(); double Length = ConvertPixelsToMapUnits(pActiveView, pSelectEnv.SearchTolerance); IPointCollection pointCol = pFeature.Shape as IPointCollection; for (int i = 0; i < pointCol.PointCount; i++) { IGeometry4 pGeom = pointCol.get_Point(i) as IGeometry4; //给pGeom一个确定的空间参考 pGeom.Project(pActiveView.FocusMap.SpatialReference); if (pGeom.IsEmpty) { return(false); } IProximityOperator pObj = pGeom as IProximityOperator; double dblDist = pObj.ReturnDistance(pPnt); if (dblDist < Length) { return(true); } } return(false); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; bool ready = true; if (app == null || app.Current2DMapControl == null) { return; } m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; ISimpleFillSymbol pFillSym = new SimpleFillSymbol(); pFillSym.Color = pColor; pFillSym.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pFillSym.Outline = pLineSym; object symbol = pFillSym as object; IRubberBand band = new RubberPolygonClass(); IGeometry pGeo = band.TrackNew(m_Display, null); app.Current2DMapControl.DrawShape(pGeo, ref symbol); WaitForm.Start("正在查询...", "请稍后"); if (pGeo.IsEmpty) { IPoint searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); //m_ActiveView.FocusMap.SelectByShape(geo, s, false); } if (ready) { IMap pMap = app.Current2DMapControl.Map; ISelectionEnvironment selEnv = new SelectionEnvironmentClass(); pMap.SelectByShape(pGeo, selEnv, false); ISelection pSelection = pMap.FeatureSelection; FrmDxfExport dialog = new FrmDxfExport(pSelection, pMap); WaitForm.Stop(); dialog.ShowDialog(); } } } catch (System.Exception ex) { WaitForm.Stop(); } }
//判断鼠标是否在已选择的记录集上 public static bool MouseOnSelection(IPoint pPnt, IActiveView pActiveView) { //设置点选择容差 ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass(); double Length = ConvertPixelsToMapUnits(pActiveView, pSelectEnv.SearchTolerance); UID pUID = new UIDClass(); pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //UID for IFeatureLayer IEnumLayer pEnumLayer = pActiveView.FocusMap.get_Layers(pUID, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { if (MouseOnSelection(pLayer as IFeatureLayer, pPnt, pActiveView, Length) == true) { return(true); } pLayer = pEnumLayer.Next(); } return(false); }
public SelectionEnv() { _pSelectionEnvironment = new SelectionEnvironmentClass(); _pSelectGeometryType = esriGeometryType.esriGeometryEnvelope; _pSelectType = enumSelectType.SelectByIntersect; _canMultiLayerSelect = false; }
private void GetSelectedFeature() { if (m_activePoint == null) { return; } IPoint mousePoint = m_activePoint; ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelWithin; m_map.SelectByShape(mousePoint as IGeometry, pSelectionEnvironment, true); IEnumFeature SelectedFeatures = m_map.FeatureSelection as IEnumFeature; if (SelectedFeatures == null) { return; } SelectedFeatures.Reset(); m_selectedFeature = SelectedFeatures.Next(); if (m_selectedFeature != null) { m_toolPhase = ToolPhase.Cut; m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent); } }
private void GetSelectedFeature() { if (m_activePoint == null) { return; } IPoint mousePoint = m_activePoint; ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelWithin; //定义缓冲区 double db = MapManager.ConvertPixelsToMapUnits(m_activeView, 4); ITopologicalOperator pTop; pTop = mousePoint as ITopologicalOperator; IGeometry pGeometry = pTop.Buffer(db); m_map.SelectByShape(pGeometry, pSelectionEnvironment, true); IEnumFeature SelectedFeatures = m_map.FeatureSelection as IEnumFeature; if (SelectedFeatures == null) { return; } SelectedFeatures.Reset(); m_selectedFeature = SelectedFeatures.Next(); if (m_selectedFeature != null) { m_toolPhase = ToolPhase.Cut; m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent); } }
/// <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; }
/// <summary> /// 以指定几何体选择图元 /// </summary> /// <param name="pGeometry"></param> /// <param name="ShiftKey"></param> /// <param name="justOne"></param> public void SelectByShape(IGeometry pGeometry, bool ShiftKey, bool justOne) { if (this.m_Scene == null) { return; } //Get a selection environment ISelectionEnvironment pSelectionEnv; pSelectionEnv = new SelectionEnvironmentClass(); if (ShiftKey) { pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd; } else { pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew; } //Select by Shape this.m_Scene.SelectByShape(pGeometry, pSelectionEnv, justOne); //Refresh the scene viewer RefreshViewers(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolCreateParallel.OnMouseDown implementation if (Button == 1 && (m_pMapCtl = ClsGlobal.GetMapControl(m_hookHelper)) != null) { IMap pMap = m_pMapCtl.Map; IPoint po = m_pMapCtl.ToMapPoint(X, Y); ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass(); IGeometry geometry = new PolygonClass(); geometry = m_pMapCtl.TrackRectangle(); pMap.SelectByShape(geometry, pSelectionEnv, true); m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); IEnumFeatureSetup pSelectionsetup = pMap.FeatureSelection as IEnumFeatureSetup; pSelectionsetup.AllFields = true;//这里是关键 IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature; IFeature pF = pFeatureCollection.Next(); if (pF != null && pF.Shape is IPolyline) { FrmParallelLineOffset frm = new FrmParallelLineOffset(); if (frm.ShowDialog() == DialogResult.OK) { IPolyline pPolyline = ConstructOffset(pF.Shape as IPolyline, frm.offset); IFeature pFeature = m_FLayer.FeatureClass.CreateFeature(); pFeature.Shape = pPolyline; pFeature.Store(); m_pMapCtl.Refresh(); } } } }
//得到鼠标靠近的地物 public IFeature GetCloseFeature(IMap pMap, IPoint pPoint, List <IFeature> lstFeatures) { if (pPoint == null || lstFeatures == null || lstFeatures.Count < 1) { return(null); } IFeature pFeat; IGeometry pGeo; ICurve pCurve = null; IPoint pInPoint = null; bool bAsRatio = false; IPoint pNearPoint = null; double dDistOnCurve = 0; double dNearDist = 0; bool bRight = false; IFeature pNearFeature = null; double dSearchDist; ISelectionEnvironment pSelEnv = new SelectionEnvironmentClass(); dSearchDist = Common.DataEditCommon.ConvertPixelDistanceToMapDistance(pMap as IActiveView, (double)pSelEnv.SearchTolerance); for (int i = 0; i < lstFeatures.Count; i++) { pFeat = lstFeatures[i]; pGeo = pFeat.Shape; if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { pCurve = new PolylineClass(); pCurve = pGeo as IPolyline; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { pCurve = new PolygonClass(); pCurve = pGeo as IPolygon; } if (pCurve == null) { return(null); } pCurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pInPoint, bAsRatio, pNearPoint, dDistOnCurve, dNearDist, bRight); if (dNearDist < dSearchDist) { dSearchDist = dNearDist; pNearFeature = pFeat; } } return(pNearFeature); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { if (button == 1) { int dis; IGeometry pGeoSel; IRubberBand band = new RubberRectangularPolygonClass(); IGeometry geo = band.TrackNew(m_Display, null); SelectionEnvironmentClass s = Class.SelectionEnv.System_Selection_Environment(m_ActiveView); dis = Class.SelectionEnv.System_Selection_Environment(m_ActiveView).SearchTolerance; IFeatureSelection pFeaSel = m_pCurEditLayer as IFeatureSelection; if (shift == 1) { pFeaSel.CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; //s.CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; } else { pFeaSel.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; this.m_ActiveView.FocusMap.ClearSelection(); } if (geo.IsEmpty) { IPoint searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeoSel = Class.Common.DoBuffer(searchPoint, dis); //m_ActiveView.FocusMap.SelectByShape(Class.Common.DoBuffer(searchPoint, dis), s, false); } else { pGeoSel = Class.Common.DoBuffer(geo, dis); //m_ActiveView.FocusMap.SelectByShape(Class.Common.DoBuffer(geo, dis), s, false); } ISpatialFilter pSpaFilter = new SpatialFilter(); pSpaFilter.Geometry = pGeoSel; pSpaFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pFeaSel.SelectFeatures(pSpaFilter, pFeaSel.CombinationMethod, false); m_App.Workbench.UpdateMenu(); if (m_ActiveView.FocusMap.SelectionCount > 0) { m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } else { m_ActiveView.Refresh(); } } }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { //Get the scene graph ISceneGraph pSceneGraph = m_pSceneHookHelper.SceneGraph; //Get the scene IScene pScene = (IScene)m_pSceneHookHelper.Scene; IPoint pPoint; object pOwner, pObject; //Translate screen coordinates into a 3D point pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pPoint, out pOwner, out pObject); //Get a selection environment ISelectionEnvironment pSelectionEnv; pSelectionEnv = new SelectionEnvironmentClass(); if (Shift == 0) { pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew; //Clear previous selection if (pOwner == null) { pScene.ClearSelection(); return; } } else { pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd; } //If the layer is a selectable feature layer if (pOwner is IFeatureLayer) { IFeatureLayer pFeatureLayer = (IFeatureLayer)pOwner; if (pFeatureLayer.Selectable == true) { //Select by Shape pScene.SelectByShape(pPoint, pSelectionEnv, false); } } //Refresh the scene viewer pSceneGraph.RefreshViewers(); }
public void PolygonSelect(AxMapControl mapControl) { this.init(); IGeometry pGeometryP; pGeometryP = mapControl.TrackPolygon(); //新建选择集对象 ISelectionEnvironment pSelectionEnvP; pSelectionEnvP = new SelectionEnvironmentClass(); //改变选择集的默认颜色 pSelectionEnvP.DefaultColor = pColor; //选择要素,并将其放入选择集 mapControl.Map.SelectByShape(pGeometryP, pSelectionEnvP, false); mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
public void RectangleSelect(AxMapControl mapControl) { this.init(); IEnvelope pEnv; pEnv = mapControl.TrackRectangle(); //新建选择集对象 ISelectionEnvironment pSelectionEnvR; pSelectionEnvR = new SelectionEnvironmentClass(); //改变选择集的默认颜色 pSelectionEnvR.DefaultColor = pColor; //选择要素,并将其放入选择集 mapControl.Map.SelectByShape(pEnv, pSelectionEnvR, false); mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
//选择实体 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IMap pMap; IActiveView pActiveView; pMap = axMapControl1.Map; pActiveView = pMap as IActiveView; IEnvelope pEnv; pEnv = axMapControl1.TrackRectangle(); ISelectionEnvironment pSelectionEnv; pSelectionEnv = new SelectionEnvironmentClass(); pSelectionEnv.DefaultColor = getRGB(110, 120, 210); pMap.SelectByShape(pEnv, pSelectionEnv, false); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
private void axMapControlContent_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { switch (e.button) { case 1: #region 左键按下,进入点选激活功能模式 IMap pMap = axMapControlContent.Map; pMap.ClearSelection(); IActiveView pActiveView = pMap as IActiveView; IGeometry pGeometry = axMapControlContent.TrackCircle(); ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass(); pSelectionEnv.DefaultColor = GetRGBColor(0, 255, 0); pMap.SelectByShape(pGeometry, pSelectionEnv, false); //获取高亮选择集要素 ISelection selection = pMap.FeatureSelection; IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup; enumFeatureSetup.AllFields = true; IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature; enumFeature.Reset(); IFeature feature = enumFeature.Next(); while (feature != null) { label1.Text = feature.get_Value(feature.Fields.FindField("Name")).ToString();//可以得到任意字段的值 textBoxDescription.Text = feature.get_Value(feature.Fields.FindField("Description")).ToString(); label3.Text = feature.get_Value(feature.Fields.FindField("URL")).ToString(); //axMapControlContent.FlashShape(feature.Shape); feature = enumFeature.Next(); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null); //axMapControlContent.Refresh(); #endregion break; case 2: break; case 4://中键,pan() axMapControlContent.Pan(); break; default: break; } }
public IEnumFeature SelectByPoint(IMap imap_0, IPoint inPoint, double pDist) { IGeometry ipoint0; ISelectionEnvironment selectionEnvironmentClass = new SelectionEnvironmentClass() { AreaSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects, LinearSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects }; if (pDist <= 0) { ipoint0 = inPoint; selectionEnvironmentClass.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects; } else { ipoint0 = ((ITopologicalOperator)inPoint).Buffer(pDist); selectionEnvironmentClass.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelContains; } selectionEnvironmentClass.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; try { imap_0.SelectByShape(ipoint0, selectionEnvironmentClass, false); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147467259) { // CErrorLog.writeErrorLog(this, cOMException, ""); } else { MessageBox.Show("执行查询时产生错误。空间索引不存在", "选择"); } } catch (Exception exception) { //CErrorLog.writeErrorLog(this, exception, ""); } return((IEnumFeature)imap_0.FeatureSelection); }
public static void SelectFeatureByPoint(IMap map,System.Drawing.Point screenPoint,int pixelTol ) { // Construct select envelope tagRECT r; r.left = screenPoint.X - pixelTol; r.right = screenPoint.X + pixelTol; r.top = screenPoint.Y - pixelTol; r.bottom = screenPoint.Y + pixelTol; IEnvelope hotEnvelope=new EnvelopeClass(); // Transform for screen to map IActiveView activeView=map as IActiveView; IDisplayTransformation dispTransf = activeView.ScreenDisplay.DisplayTransformation; dispTransf.TransformRect(hotEnvelope, ref r, 5); // Create select environment hotEnvelope.SpatialReference = map.SpatialReference; ISelectionEnvironment selectEnviroment = new SelectionEnvironmentClass(); selectEnviroment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; // Select by shape map.SelectByShape(hotEnvelope, selectEnviroment, false); }
public IEnumFeature SelectByLine(IMap pMap, IPolyline pLine, double pDist) { IGeometry ipolyline0; ISelectionEnvironment selectionEnvironmentClass = new SelectionEnvironmentClass() { AreaSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects, LinearSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects }; if (pDist <= 0) { ipolyline0 = pLine; selectionEnvironmentClass.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelIntersects; } else { ipolyline0 = ((ITopologicalOperator)pLine).Buffer(pDist); selectionEnvironmentClass.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelContains; } selectionEnvironmentClass.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; try { pMap.SelectByShape(ipolyline0, selectionEnvironmentClass, false); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode != -2147467259) { } else { MessageBox.Show("执行查询时产生错误。空间索引不存在", "选择"); } } catch (Exception exception) { } return((IEnumFeature)pMap.FeatureSelection); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { try { IPoint pPoint = new PointClass(); pPoint.PutCoords(mapX, mapY); FrmMapExportByCoordinate dialog = new FrmMapExportByCoordinate(pPoint); dialog.ShowDialog(); if (dialog.DialogResult == DialogResult.OK) { IPointCollection pColl = new PolygonClass(); pColl.AddPoint(pPoint); IPoint point1 = new PointClass(); point1.PutCoords(mapX + dialog.Length, mapY); pColl.AddPoint(point1); IPoint point2 = new PointClass(); point2.PutCoords(mapX, mapY + dialog.Width); pColl.AddPoint(point2); IPoint point3 = new PointClass(); point3.PutCoords(mapX + dialog.Length, mapY + dialog.Width); pColl.AddPoint(point3); IGeometry pGeo = pColl as IGeometry; DF2DApplication app = DF2DApplication.Application; IMap pMap = app.Current2DMapControl.Map; ISelectionEnvironment selEnv = new SelectionEnvironmentClass(); pMap.SelectByShape(pGeo, selEnv, false); ISelection pSelection = pMap.FeatureSelection; FrmDxfExport dialog1 = new FrmDxfExport(pSelection, pMap); WaitForm.Stop(); dialog1.ShowDialog(); } } catch (System.Exception ex) { } }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs e) { IScreenDisplay screenDisplay = ArcMap.Document.ActiveView.ScreenDisplay; //创建选取多边形 IRubberBand pRubberPolygon = new RubberPolygonClass(); IPolygon pPolygon = pRubberPolygon.TrackNew(screenDisplay, null) as IPolygon; //构建选取环境;选取对象颜色为红色;选取方法为累加 SelectionEnvironment se = new SelectionEnvironmentClass(); se.DefaultColor = getRGB(255, 0, 0); se.CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; //选取要素 IMap map = ArcMap.Document.FocusMap; map.SelectByShape(pPolygon, se, false); //刷新屏幕 ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
public static SelectionEnvironmentClass System_Selection_Environment(IActiveView activeView) { if (m_System_SelectionEnvironment == null) { m_System_SelectionEnvironment = new SelectionEnvironmentClass(); } double tol = Class.Common.ConvertPixelsToMapUnits(activeView, m_Tolerate); m_System_SelectionEnvironment.PointSearchDistance = m_Tolerate; m_System_SelectionEnvironment.LinearSearchDistance = m_Tolerate; m_System_SelectionEnvironment.AreaSearchDistance = m_Tolerate; m_System_SelectionEnvironment.PointSelectionMethod = (esriSpatialRelEnum)m_SelectRelation; m_System_SelectionEnvironment.LinearSelectionMethod = (esriSpatialRelEnum)m_SelectRelation; m_System_SelectionEnvironment.AreaSelectionMethod = (esriSpatialRelEnum)m_SelectRelation; m_System_SelectionEnvironment.ClearInvisibleLayers = m_ClearInVisible; m_System_SelectionEnvironment.CombinationMethod = (esriSelectionResultEnum)m_ResultMethod; m_System_SelectionEnvironment.DefaultColor = Class.Common.GetSelectionColor(m_DefaultColorRGB); m_System_SelectionEnvironment.SearchTolerance = m_Tolerate; return(m_System_SelectionEnvironment); }
/// <summary> /// 地图缩放至指定图形并以选中形式闪烁 /// </summary> /// <param name="axMapControl">地图控件</param> /// <param name="control">任意主线程窗体控件(axMapCtontrol除外)</param> /// <param name="geometry">闪烁的图像</param> /// <param name="nFlashes">闪烁次数</param> public static void MapZoomToSelectFlash(this AxMapControl axMapControl, System.Windows.Forms.Control control, IGeometry geometry, int nFlashes = 2) { MapZoomTo(axMapControl.ActiveView, geometry); ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; Thread th = new Thread(delegate(object data) { for (int i = 0; i < nFlashes; i++) { Thread.Sleep(50); control.Invoke(new Action(() => { axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); axMapControl.Map.SelectByShape(geometry, pSelectionEnvironment, true); axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); })); Thread.Sleep(100); control.Invoke(new Action(() => { axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); axMapControl.Map.ClearSelection(); axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); })); } var stopThreadDelegate = (StopThreadDelegate)data; stopThreadDelegate(Thread.CurrentThread);//停止线程 }); th.Start(new StopThreadDelegate((thread) => { thread.Abort(); })); }
public override void OnDblClick() { try { ArcGIS.Common.Editor.Editor.StartEditOperation(); if (_lineFeedback == null) { return; } _polyline = _lineFeedback.Stop(); if (_lineFeedback != null) { _context.ActiveView.Refresh(); _lineFeedback = null; } if (_polyline == null) { return; } ISelectionEnvironment selectionEnvironment = new SelectionEnvironmentClass(); selectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; _context.FocusMap.SelectByShape(_polyline, selectionEnvironment, false); ISelection selection = _context.FocusMap.FeatureSelection; IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup; IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature; if (enumFeature == null) { return; } enumFeature.Reset(); IFeature feature; List <MultiCheQiModel> modelList = new List <MultiCheQiModel>(); while ((feature = enumFeature.Next()) != null) { IFeatureClass featureClass = feature.Class as IFeatureClass; if (featureClass == null) { continue; } IFeatureLayer featureLayer = _multiCheQiConfig.FlagLayerList.FirstOrDefault( c => c.FeatureClass.FeatureClassID == featureClass.FeatureClassID); if (featureLayer == null) { continue; } modelList.Add(new MultiCheQiModel(featureLayer, feature, _multiCheQiConfig.FieldSettingList, _polyline)); } if (modelList.Count <= 0) { return; } _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, 0); IAnnotationClassExtension annotationClassExtension = _multiCheQiConfig.FlagAnnoLayer.FeatureClass.Extension as IAnnotationClassExtension; IElement headerElement = CommonHelper.CreateHeaderElements(_multiCheQiConfig, _polyline.ToPoint); IFeature headerFeature = _multiCheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature(); IAnnotationFeature headerAnnotationFeature = headerFeature as IAnnotationFeature; headerAnnotationFeature.Annotation = headerElement; headerFeature.Store(); double xLength = headerFeature.Shape.Envelope.Width; double yLength = headerFeature.Shape.Envelope.Height; IPoint headerPoint = new PointClass(); headerPoint.X = (headerElement.Geometry as IPoint).X - xLength / 2; headerPoint.Y = (headerElement.Geometry as IPoint).Y + yLength * (modelList.Count + 0.5); headerElement.Geometry = headerPoint; headerAnnotationFeature.Annotation = headerElement; headerFeature.Store(); annotationClassExtension.Draw(headerAnnotationFeature, _context.ActiveView.ScreenDisplay, null); List <MultiCheQiModel> models = new List <MultiCheQiModel>(modelList.OrderBy(c => c.Distance)); List <IElement> elements = CommonHelper.CreateContentElements(_multiCheQiConfig, models, headerElement.Geometry as IPoint, headerFeature.Shape.Envelope.Width, headerFeature.Shape.Envelope.Height); foreach (IElement element in elements) { IFeature contentFeature = _multiCheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature(); IAnnotationFeature contentAnnotationFeature = contentFeature as IAnnotationFeature; contentAnnotationFeature.Annotation = element; contentFeature.Store(); annotationClassExtension.Draw(contentAnnotationFeature, _context.ActiveView.ScreenDisplay, null); } _context.ActiveView.ScreenDisplay.FinishDrawing(); IPointCollection pointCollection = _polyline as IPointCollection; IPoint point1 = new PointClass(); point1.X = _polyline.ToPoint.X - xLength; point1.Y = _polyline.ToPoint.Y; IPoint point2 = new PointClass(); point2.X = _polyline.ToPoint.X - xLength; point2.Y = _polyline.ToPoint.Y + yLength * (modelList.Count + 1); pointCollection.AddPoint(point1); pointCollection.AddPoint(point2); IFeature lineFeature = _multiCheQiConfig.FlagLineLayer.FeatureClass.CreateFeature(); lineFeature.Shape = pointCollection as IPolyline; lineFeature.Store(); _context.ActiveView.Refresh(); } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { ArcGIS.Common.Editor.Editor.StopEditOperation(); } }
public static void SelectFeatureByPolygon(IMap map,IPolygon polygon) { ISelectionEnvironment selectEnv = new SelectionEnvironmentClass(); selectEnv.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; map.SelectByShape(polygon, selectEnv, false); }
static void Main() { //ESRI License Initializer generated code. if (!RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop)) { MessageBox.Show("没有安装ArcGIS", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DevExpress.UserSkins.BonusSkins.Register(); DevExpress.Skins.SkinManager.EnableFormSkins(); //扩展许可判断 IAoInitialize m_AoInitialize = new AoInitialize(); esriLicenseStatus status = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB); if (status == esriLicenseStatus.esriLicenseFailure || status == esriLicenseStatus.esriLicenseNotLicensed) { MessageBox.Show(string.Format("当前ArcGIS权限不足")); return; } //m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //check the config file Fan.Common.frmDBSet setDbFrom = null; if (!System.IO.File.Exists(Fan.Common.ModuleConfig.m_ConnectFileName)) { setDbFrom = new Fan.Common.frmDBSet(); if (setDbFrom.ShowDialog() != DialogResult.OK) { return; } else { Mod.m_SysDbOperate = setDbFrom.Dbop; } } else { //Read The Connect Info from the config file Fan.DataBase.DBConfig dbConfig = new Fan.DataBase.DBConfig(); dbConfig.ReadConfigFromFile(Fan.Common.ModuleConfig.m_ConnectFileName); Fan.DataBase.DBOperatorFactory dbFac = new Fan.DataBase.DBOperatorFactory(dbConfig); Mod.m_SysDbOperate = dbFac.GetDbOperate(); if (Mod.m_SysDbOperate == null || !Mod.m_SysDbOperate.TestConnect()) { setDbFrom = new Fan.Common.frmDBSet(); if (setDbFrom.ShowDialog() != DialogResult.OK) { return; } else { Mod.m_SysDbOperate = setDbFrom.Dbop; } } } if (setDbFrom != null) { setDbFrom.Dispose(); } frmLogin LoginFrom = new frmLogin(); //登陆主窗体条件设置 if (LoginFrom.ShowDialog() == DialogResult.OK) { LoginFrom.Dispose(); ISelectionEnvironmentThreshold threshold = new SelectionEnvironmentClass(); threshold.WarningThreshold = 2000; Application.Run(new frmMain()); } else { return; } //m_AoInitialize.Shutdown(); //m_AoInitialize = null; m_AOLicenseInitializer.ShutdownApplication(); m_AOLicenseInitializer = null; }
private void FeatureSelectWhenMouseMove(IPoint pointCentre, IPoint pointMouseMoveTo, EnumSelectMode SelectMode) { double currentRadius = FunctionCommon.GetDistance2P(m_PointCentre, pointMouseMoveTo); //1 选择半径太大,不响应 if (currentRadius > GlobeStatus.Setting.PixelMaxRadius * GlobeStatus.MapUnit) { return; } //2 变化距离太小,不响应 double distanceChange = currentRadius - m_LastRadius; if (Math.Abs(distanceChange) < GlobeStatus.Setting.PixelRadiusChangeLimit * GlobeStatus.MapUnit) { return; } //3 开始选择 IGeometry pGeometry = FunctionCommon.GetCircleGeometry(m_PointCentre, currentRadius); ISelectionEnvironment env = new SelectionEnvironmentClass(); env.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; GlobeStatus.Map.SelectByShape(pGeometry, env, false); }
/// <summary> /// 地图定位方法 /// </summary> /// <param name="layerNames">图层名称</param> /// <param name="pColumnContent">要定位网元的名称内容</param> public bool Locate(string layerNames, string pColumnContent) { IFeatureLayer pFeatureLayer = null; string ColumnName = null;//图层中小区对应的名称 string columnLON = null; string columnLAT = null; switch (layerNames) { case LayerNames.GSM900Cell: { pFeatureLayer = GISMapApplication.Instance.GetLayer(LayerNames.GSM900Cell) as IFeatureLayer; ColumnName = "cellname"; columnLON = "longitude"; columnLAT = "latitude"; break; } case LayerNames.GSM1800Cell: { pFeatureLayer = GISMapApplication.Instance.GetLayer(LayerNames.GSM1800Cell) as IFeatureLayer; ColumnName = "cellname"; columnLON = "longitude"; columnLAT = "latitude"; break; } } if (pFeatureLayer == null) { return(false); } IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IQueryFilter queryFilter = new QueryFilter(); queryFilter.WhereClause = ColumnName + "='" + pColumnContent + "'"; IFeatureCursor pFCursor = pFeatureClass.Search(queryFilter, false); IFeature pFeature = pFCursor.NextFeature(); while (pFeature != null) { int indexOfName = pFeatureClass.FindField(ColumnName); int indexLon = pFeatureClass.FindField(columnLON); int indexLat = pFeatureClass.FindField(columnLAT); if (pFeature.get_Value(indexOfName).ToString() == pColumnContent) { //定位到查询的图元 double lon = Convert.ToDouble(pFeature.get_Value(indexLon)); double lat = Convert.ToDouble(pFeature.get_Value(indexLat)); ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass(); pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew; if (pFeatureLayer.Selectable == true) { GISMapApplication.Instance.Scene.ClearSelection(); ICommand pCommand = new ControlsZoomToSelectedCommandClass(); //Select by Shape IPoint pNewCenterPoint = new PointClass(); pNewCenterPoint.X = lon; pNewCenterPoint.Y = lat; PointConvert.Instance.GetProjectPoint(pNewCenterPoint); pSelectionEnv.DefaultColor = GISUtil.GetRGB(255, 0, 0); // 定位居中 ILayer referLayer = GISMapApplication.Instance.GetLayer("建筑物");//定位居中参照图层。 IEnvelope pEnvelope = referLayer.AreaOfInterest; //IEnvelope pEnvelope = pFeatureLayer.AreaOfInterest; pEnvelope.CenterAt(pNewCenterPoint); pEnvelope.Expand(0.1, 0.1, true); GISMapApplication.Instance.FullExtent(pEnvelope); //GISMapApplication.Instance.Scene.ClearSelection(); //GISMapApplication.Instance.Scene.SelectByShape(pFeature.Shape, pSelectionEnv, true); GISMapApplication.Instance.Scene.SelectFeature(pFeatureLayer, pFeature); HandlerFeatureData(layerNames, pFeature); return(true); } } } return(false); }
//选择要素 private void ctMenuMNSelectFeature_Click(object sender, EventArgs e) { IMap pMap = this.mainMapControl.Map; ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.LinearSearchDistance = this.mainMapControl.ActiveView.Extent.Width / 200; pSelectionEnvironment.PointSearchDistance = this.mainMapControl.ActiveView.Extent.Width / 200; pMap.SelectByShape(this.mapRightClickPoint as IGeometry, null, false); this.mainMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
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(); } } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { if (Button == 1) { IPoint pPnt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); ISelectionEnvironment pSelEnv = new SelectionEnvironmentClass(); pSelEnv.SearchTolerance = 3; pSelEnv.CombinationMethod = esriSelectionResultEnum.esriSelectionResultAdd; //����µ�ѡ��Ҫ�� m_hookHelper.FocusMap.SelectByShape(m_pMapControl.TrackRectangle(), pSelEnv, false); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); //GIS.GraphicEdit.FeatureSelect featSelectTool = new GraphicEdit.FeatureSelect(); //featSelectTool.OnCreate(m_hookHelper.Hook); //m_pMapControl.CurrentTool = featSelectTool; m_FeatureExtend = GetExtendLine(); if (m_FeatureExtend != null && m_FeatureRef != null) { bool bSuccess = ExtendLine(m_FeatureExtend, m_FeatureRef); if (bSuccess) { m_hookHelper.FocusMap.ClearSelection(); m_hookHelper.ActiveView.Refresh(); } else { MessageBox.Show(@"������ǰ��ѡ��Ҫ�����쵽�ο���", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else if (Button == 2) { //switch (m_MouseDownCount) //{ // case 0: // if (m_hookHelper.FocusMap.SelectionCount == 1) // { // m_FeatureRef = GetRefPolyline(); // m_MouseDownCount = 1; // } // break; // case 1: // if (m_hookHelper.FocusMap.SelectionCount > 1) // { // m_FeatureExtend= GetExtendLine(); // m_MouseDownCount = 2; // } // break; // case 2: // m_MouseDownCount = 0; // //if (m_FeatureExtend != null && m_FeatureRef != null) // //{ // // bool bSuccess = ExtendLine(m_FeatureExtend, m_FeatureRef); // // m_hookHelper.FocusMap.ClearSelection(); // // m_hookHelper.ActiveView.Refresh(); // //} // //else // //{ // // MessageBox.Show("����ѡ����Ҫ�������Ҫ��", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); // //} // break; //} } } catch { } }
//�õ���꿿���ĵ��� public IFeature GetCloseFeature(IMap pMap, IPoint pPoint, List<IFeature> lstFeatures) { if (pPoint == null || lstFeatures == null || lstFeatures.Count < 1) return null; IFeature pFeat; IGeometry pGeo; ICurve pCurve = null; IPoint pInPoint = null; bool bAsRatio = false; IPoint pNearPoint = null; double dDistOnCurve = 0; double dNearDist = 0; bool bRight = false; IFeature pNearFeature = null; double dSearchDist; ISelectionEnvironment pSelEnv = new SelectionEnvironmentClass(); dSearchDist = Common.DataEditCommon.ConvertPixelDistanceToMapDistance(pMap as IActiveView, (double)pSelEnv.SearchTolerance); for (int i = 0; i < lstFeatures.Count; i++) { pFeat = lstFeatures[i]; pGeo = pFeat.Shape; if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { pCurve = new PolylineClass(); pCurve = pGeo as IPolyline; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { pCurve = new PolygonClass(); pCurve = pGeo as IPolygon; } if (pCurve == null) return null; pCurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pInPoint, bAsRatio, pNearPoint, dDistOnCurve, dNearDist, bRight); if (dNearDist < dSearchDist) { dSearchDist = dNearDist; pNearFeature = pFeat; } } return pNearFeature; }
/// <summary> /// ���Ե��λ���Ƿ����Feature /// </summary> /// <params name="m_hookHelper"></params> /// <params name="X"></params> /// <params name="Y"></params> /// <params name="theFeature"></params> public static void TestExistFeature(IHookHelper m_hookHelper, int X, int Y, ref IFeature theFeature) { 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_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pGeometry = pPoint; dLength = ConvertPixelDistanceToMapDistance(m_hookHelper.ActiveView, 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; List<ILayer> list = GetLayerListByKey(DataEditCommon.g_pMap, "Ĭ��"); for (int i = 0; i < list.Count; i++) { if (list[i].Visible == false || list[i] is IFeatureLayer == false) { continue; } pFeatureLayer = list[i] as IFeatureLayer; pFeatureClass = pFeatureLayer.FeatureClass; if (pFeatureClass == null) { return; } IIdentify2 pID = pFeatureLayer as IIdentify2; IArray pArray = pID.Identify(pSrchEnv, 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); pSelected.Add(pFeatureLayer.Name); pSelected.Add(i); } } pArray.RemoveAll(); } } GetClosestFeatureInCollection(m_hookHelper, list, dLength, pSelected, pPoint, ref pFeat); if (pFeat != null) theFeature = pFeat; else theFeature = null; }
public static void SnapFeaturePoint(IFeature pFeature, IHookHelper m_hookHelper, IPoint m_pSnapPoint, int X, int Y) { if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint pPoint = (IPoint)pFeature.Shape; int x = 0; int y = 0; m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out x, out y); System.Drawing.Point pPointScreen = new System.Drawing.Point(); GetCursorPos(ref pPointScreen); int width = x - X; int height = y - Y; pPointScreen.X = pPointScreen.X + width; pPointScreen.Y = pPointScreen.Y + height; SetCursorPos(pPointScreen.X, pPointScreen.Y); m_pSnapPoint = pPoint; } IPointCollection m_pPointCol; if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) m_pPointCol = new Polyline(); else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) m_pPointCol = new Polygon(); else return; IPointCollection pPntCol; IGeometryCollection pGeoCollection = (IGeometryCollection)pFeature.Shape; for (int i = 0; i < pGeoCollection.GeometryCount; i++) { IGeometry pGeom = pGeoCollection.get_Geometry(i); pPntCol = (IPointCollection)pGeom; m_pPointCol.AddPointCollection(pPntCol); } IPoint pProximity = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); List<double> pdistance = new List<double>(); for (int i = 0; i < m_pPointCol.PointCount; i++) { double tempDist = (m_pPointCol.Point[i].X - pProximity.X) * (m_pPointCol.Point[i].X - pProximity.X) + (m_pPointCol.Point[i].Y - pProximity.Y) * (m_pPointCol.Point[i].Y - pProximity.Y); pdistance.Add(tempDist); } double dbD = double.MaxValue; int index = -1; for (int i = 0; i < pdistance.Count; i++) { if (pdistance[i] < dbD) { dbD = pdistance[i]; index = i; } } ISelectionEnvironment pSelectionEnvironment; pSelectionEnvironment = new SelectionEnvironmentClass(); double dLength = pSelectionEnvironment.SearchTolerance; dLength = DataEditCommon.ConvertPixelDistanceToMapDistance(m_hookHelper.ActiveView, dLength); dLength = dLength * dLength; if (dbD < dLength) { m_pSnapPoint = m_pPointCol.Point[index]; System.Drawing.Point pPointScreen = new System.Drawing.Point(); GetCursorPos(ref pPointScreen); int x = 0; int y = 0; m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(m_pSnapPoint, out x, out y); int width = x - X; int height = y - Y; pPointScreen.X = pPointScreen.X + width; pPointScreen.Y = pPointScreen.Y + height; SetCursorPos(pPointScreen.X, pPointScreen.Y); } else m_pSnapPoint = null; }
private void _selectFeaturesByShape(object shape) { this._axMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; this._axMapCtrl.Map.SelectByShape((IGeometry)shape, pSelectionEnvironment, false); this._axMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != 1) { return; } //设置点选择容差 ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass(); double Length = ModPublic.ConvertPixelsToMapUnits(m_hookHelper.ActiveView, pSelectEnv.SearchTolerance); IPoint pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IGeometry pGeometry = pPoint as IGeometry; ITopologicalOperator pTopo = pGeometry as ITopologicalOperator; IGeometry pBuffer = pTopo.Buffer(Length); //仅与框架别界相交地物会被选取 pGeometry = m_MapControl.TrackRectangle() as IGeometry; bool bjustone = true; if (pGeometry != null) { if (pGeometry.IsEmpty) { pGeometry = pBuffer; } else { bjustone = false; } } else { pGeometry = pBuffer; } UID pUID = new UIDClass(); pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //UID for IFeatureLayer IEnumLayer pEnumLayer = m_MapControl.Map.get_Layers(pUID, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { if (pLayer.Visible == false) { pLayer = pEnumLayer.Next(); continue; } IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; if (pFeatureLayer.Selectable == false) { pLayer = pEnumLayer.Next(); continue; } GetSelctionSet(pFeatureLayer, pGeometry, bjustone, Shift); pLayer = pEnumLayer.Next(); } //触发Map选择发生变化事件 ISelectionEvents pSelectionEvents = m_hookHelper.FocusMap as ISelectionEvents; pSelectionEvents.SelectionChanged(); //刷新 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_hookHelper.ActiveView.Extent); AttributeShow(); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { //Get the scene graph ISceneGraph pSceneGraph = m_pSceneHookHelper.SceneGraph; //Get the scene IScene pScene = (IScene) m_pSceneHookHelper.Scene; IPoint pPoint; object pOwner, pObject; //Translate screen coordinates into a 3D point pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pPoint, out pOwner, out pObject); //Get a selection environment ISelectionEnvironment pSelectionEnv; pSelectionEnv = new SelectionEnvironmentClass(); if(Shift == 0) { pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew; //Clear previous selection if(pOwner == null) { pScene.ClearSelection(); return; } } else pSelectionEnv.CombinationMethod = ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd; //If the layer is a selectable feature layer if(pOwner is IFeatureLayer) { IFeatureLayer pFeatureLayer = (IFeatureLayer) pOwner; if(pFeatureLayer.Selectable == true) { //Select by Shape pScene.SelectByShape(pPoint, pSelectionEnv, false); } } //Refresh the scene viewer pSceneGraph.RefreshViewers(); }
private void axMapControlContent_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { IActiveView pActiveView = axMapControlContent.ActiveView; IMap pMap = axMapControlContent.Map; // 得到一个Envelop对象 IPoint point; point = axMapControlContent.ToMapPoint(e.x, e.y); // 新建选择集环境对象 ISelectionEnvironment pSelectionEnv; pSelectionEnv = new SelectionEnvironmentClass(); pSelectionEnv.DefaultColor = GetRGBColor(233, 150, 122); // 选择要素,将它们放入到选择集 pMap.SelectByShape(point, pSelectionEnv, true); //获取高亮选择集要素 ISelection selection = pMap.FeatureSelection; IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup; enumFeatureSetup.AllFields = true; IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature; enumFeature.Reset(); IFeature feature = enumFeature.Next(); while (feature != null) { label1.Text = feature.get_Value(feature.Fields.FindField("Name")).ToString();//可以得到任意字段的值 textBoxDescription.Text = feature.get_Value(feature.Fields.FindField("Description")).ToString(); label3.Text = feature.get_Value(feature.Fields.FindField("URL")).ToString(); feature = enumFeature.Next(); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
/// <summary> /// �ж���������������Ҫ�� /// </summary> /// <params name="m_hookHelper"></params> /// <params name="pMousePoint">����</params> /// <params name="pFeatureLayer">���ߵ�ͼ��</params> /// <params name="theFeature">�������������ĵ��ߵ�</params> 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; }