/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IMapControl3 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl3; ISelection pSelection = pMapCtr.Map.FeatureSelection; int i = 0; IEnumFeature pEnumFeature = pSelection as IEnumFeature; IEnumFeatureSetup m_EnumFeatureSetup = pEnumFeature as IEnumFeatureSetup; m_EnumFeatureSetup.AllFields = true; pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); if (pFeature != null) { while (pFeature != null) { i++; pFeature = pEnumFeature.Next(); } if (i == 1) { pEnumFeature.Reset(); IFeature mFeature = pEnumFeature.Next(); Frmprofile frmprofile = new Frmprofile(mFeature, pMapCtr); frmprofile.ShowInTaskbar = false; frmprofile.StartPosition = FormStartPosition.CenterScreen; frmprofile.ShowDialog(); } else { MessageBox.Show("只能选中一条线路进行剖面分析", "提示", MessageBoxButtons.OK); } } else { MessageBox.Show("请先选中一条路线", "提示", MessageBoxButtons.OK); } }
/// <summary> /// 从地图控件获取所有被选中的要素 /// </summary> /// <param name="mapControl"></param> /// <returns></returns> public static List <IFeature> getFeaturesFromMapSelection(AxMapControl mapControl) { ISelection selection = mapControl.Map.FeatureSelection; IEnumFeature selectedFeatures = selection as IEnumFeature; List <IFeature> fList = new List <IFeature>(); IFeature f = null; while ((f = selectedFeatures.Next()) != null) { fList.Add(f); } return(fList); }
}//选择地图要素 public void getSelectedFeature() { try { IMap map = axMapControl2.Map; ISelection selection = map.FeatureSelection; IEnumFeatureSetup iEnumFeatureSetup = (IEnumFeatureSetup)selection; iEnumFeatureSetup.AllFields = true; IEnumFeature enumFeature = (IEnumFeature)iEnumFeatureSetup; enumFeature.Reset(); IFeature feature = enumFeature.Next(); while (feature != null) { string hehe = feature.get_Value(5).ToString(); MessageBox.Show(hehe); feature = enumFeature.Next(); } } catch (Exception e) { } }
private void SaveSelectedFeaturesToQueryFeatureClass() { try { ISelection selection = m_map.FeatureSelection; IEnumFeature selFeatures = selection as IEnumFeature; selFeatures.Reset(); IFeature selFeature = selFeatures.Next(); while (selFeature != null) { IFeature feature = queryFeatureClass.CreateFeature(); feature.Shape = selFeature.Shape; feature.Store(); selFeature = selFeatures.Next(); } m_map.ClearSelection(); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } catch { } }
private IFeature Find_FirstFeature() { if (m_Map == null) { return(null); } IEnumFeature pEnumFeature = (IEnumFeature)m_Map.FeatureSelection; IFeature pFeature = null; pFeature = pEnumFeature.Next(); while (pFeature != null) { if (pFeature.ShapeCopy.GeometryType == esriGeometryType.esriGeometryPoint) { break; } pFeature = pEnumFeature.Next(); } return(pFeature); }
private void MirrorCopy(IPolyline ipolyline_0) { Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation(); IEnumFeature enumFeature = _context.FocusMap.FeatureSelection as IEnumFeature; enumFeature.Reset(); for (IFeature feature = enumFeature.Next(); feature != null; feature = enumFeature.Next()) { try { IGeometry shape = GeometryOperator.Mirror(feature.Shape, ipolyline_0); IRow row = RowOperator.CreatRowByRow(feature); (row as IFeature).Shape = shape; row.Store(); } catch { } } Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation(); (_context.FocusMap as IActiveView).Refresh(); }
public override void OnClick(object sender, EventArgs args) { Yutai.ArcGIS.Common.Editor.Editor.DrawNode = true; SketchToolAssist.CurrentTask = this; IEnumFeature featureSelection = _context.FocusMap.FeatureSelection as IEnumFeature; featureSelection.Reset(); IEnvelope envelope = featureSelection.Next().Shape.Envelope; envelope.Expand(10, 10, false); _context.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, envelope); base.OnClick(); }
public override void OnMouseDown(int button, int shift, int x, int y) { if (button != 1) { return; } if (_context.Config.EngineSnapEnvironment.SnapToleranceUnits == esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels) { _tolerance = ArcGIS.Common.Helpers.CommonHelper.ConvertPixelsToMapUnits(_context.ActiveView, _tolerance); } this.SelectByClick(x, y); IEnumFeature enumFeature = _context.FocusMap.FeatureSelection as IEnumFeature; _pointFeature = enumFeature.Next(); IPoint linkPoint = _pointFeature?.Shape as IPoint; if (linkPoint == null) { return; } this.SelectByShape(linkPoint); IFeatureSelection featureSelection = _lineFeatureLayer as IFeatureSelection; ICursor cursor; featureSelection.SelectionSet.Search(null, false, out cursor); if ((_lineFeature1 = cursor.NextRow() as IFeature) == null) { return; } if ((_lineFeature2 = cursor.NextRow() as IFeature) == null) { return; } FrmDeletePipeline frm = new FrmDeletePipeline(_lineFeature1, _lineFeature2, linkPoint, _lineFeatureLayer); if (frm.ShowDialog() == DialogResult.OK) { _pointFeature.Delete(); _lineFeature1.Delete(); _lineFeature2.Delete(); int oid = frm.FeatureOID; IFeature feature = _lineFeatureLayer.FeatureClass.GetFeature(oid); _context.FocusMap.ClearSelection(); _context.FocusMap.SelectFeature(_lineFeatureLayer, feature); _context.ActiveView.Refresh(); } }
private List <ESRI.ArcGIS.Geometry.IGeometry> GetDataGeometry(IMap pMap) { List <IGeometry> lstGeometrys = new List <IGeometry>(); //IGeometry pTempGeo = null; if (pMap.SelectionCount < 1) { System.Windows.Forms.MessageBox.Show("请使用地图工具条中的【选择要素】工具在当前地图中选择要素!然后方可该功能。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } IActiveView pAv = pMap as IActiveView; ISelection pSelection = pMap.FeatureSelection; if (pSelection == null) { return(null); } IEnumFeature pEnumFea = pSelection as IEnumFeature; IFeature pFea = pEnumFea.Next(); while (pFea != null) { if (pFea.ShapeCopy != null) { if (pFea.Shape.GeometryType != esriGeometryType.esriGeometryPolygon) { pFea = pEnumFea.Next();//while循环,continue的时候千万记得 后移! continue; } lstGeometrys.Add(pFea.ShapeCopy); } pFea = pEnumFea.Next(); } return(lstGeometrys); }
public override void OnClick() { Dictionary <IGeometry, IElement> ges = new Dictionary <IGeometry, IElement>(); IEnumFeature features = myHook.MapControl.Map.FeatureSelection as IEnumFeature; features.Reset(); IFeature feature = features.Next(); while (feature != null) { IElement ele = null; if (feature is IAnnotationFeature) { IAnnotationFeature af = feature as IAnnotationFeature; ele = af.Annotation; } ges.Add(feature.ShapeCopy, ele); feature = features.Next(); } ControlsPaste.GeometriesToBePasted = ges; }
public void Excute() { IPolygon tempLine = SketchToolAssist.TempLine as IPolygon; IInvalidArea invalidAreaClass = new InvalidArea() { Display = (_context.FocusMap as IActiveView).ScreenDisplay }; invalidAreaClass.Add(tempLine); tempLine.SimplifyPreserveFromTo(); IEnumFeature featureSelection = _context.FocusMap.FeatureSelection as IEnumFeature; featureSelection.Reset(); IFeature feature = featureSelection.Next(); if (feature != null) { IPolygon shapeCopy = feature.ShapeCopy as IPolygon; if (!(shapeCopy as IRelationalOperator).Disjoint(tempLine)) { IGeometry geometry = (shapeCopy as ITopologicalOperator).Difference(tempLine); if (!geometry.IsEmpty) { invalidAreaClass.Add(feature); Yutai.ArcGIS.Common.Editor.Editor.SetGeometryZM(geometry, shapeCopy); Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation(); try { feature.Shape = geometry; feature.Store(); IGeometry geometry1 = (shapeCopy as ITopologicalOperator).Difference(geometry); if (!geometry1.IsEmpty) { Yutai.ArcGIS.Common.Editor.Editor.SetGeometryZM(geometry1, shapeCopy); IFeature feature1 = RowOperator.CreatRowByRow(feature as Row) as IFeature; feature1.Shape = geometry1; feature1.Store(); } } catch (Exception exception) { CErrorLog.writeErrorLog(this, exception, ""); } Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation(); _context.UpdateUI(); } } } invalidAreaClass.Invalidate(-2); }
private void method_2() { this.bool_0 = false; IEnumFeature featureSelection = this.imap_0.FeatureSelection as IEnumFeature; IGeometryCollection geometryBagClass = new GeometryBag() as IGeometryCollection; featureSelection.Reset(); for (IFeature i = featureSelection.Next(); i != null; i = featureSelection.Next()) { esriGeometryType geometryType = i.Shape.GeometryType; if ((geometryType == esriGeometryType.esriGeometryPolygon ? true : geometryType == esriGeometryType.esriGeometryPolyline)) { IClone shape = i.Shape as IClone; object value = Missing.Value; geometryBagClass.AddGeometry(shape.Clone() as IGeometry, ref value, ref value); this.bool_0 = true; } } this.isegmentGraph_0.SetEmpty(); this.isegmentGraph_0.Load(geometryBagClass as IEnumGeometry, false, true); }
private List <ESRI.ArcGIS.Geometry.IGeometry> GetDataGeometry(IMap pMap) { List <IGeometry> lstGeometrys = new List <IGeometry>(); //IGeometry pTempGeo = null; if (pMap.SelectionCount < 1) { System.Windows.Forms.MessageBox.Show("需要选择范围"); return(null); } IActiveView pAv = pMap as IActiveView; ISelection pSelection = pMap.FeatureSelection; if (pSelection == null) { return(null); } IEnumFeature pEnumFea = pSelection as IEnumFeature; IFeature pFea = pEnumFea.Next(); while (pFea != null) { if (pFea.ShapeCopy != null) { if (pFea.Shape.GeometryType != esriGeometryType.esriGeometryPolygon) { continue; } lstGeometrys.Add(pFea.ShapeCopy); } pFea = pEnumFea.Next(); } return(lstGeometrys); }
public override void OnClick() { try { frmMaxAllowableOffset _frmMaxAllowableOffset = new frmMaxAllowableOffset() { Text = "平滑" }; if (_frmMaxAllowableOffset.ShowDialog() == DialogResult.OK) { double maxAllowableOffset = _frmMaxAllowableOffset.MaxAllowableOffset; IEnumFeature featureSelection = _context.FocusMap.FeatureSelection as IEnumFeature; featureSelection.Reset(); IFeature feature = featureSelection.Next(); IWorkspaceEdit editWorkspace = Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace; editWorkspace.StartEditOperation(); IPolycurve shape = null; while (feature != null) { shape = feature.Shape as IPolycurve; if (shape != null && editWorkspace == (feature.Class as IDataset).Workspace) { shape.Smooth(maxAllowableOffset); feature.Shape = shape; feature.Store(); } feature = featureSelection.Next(); } editWorkspace.StopEditOperation(); _context.ActiveView.Refresh(); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public override void OnMouseDown(int button, int shift, int x, int y) { if (button != 1) { return; } if (_context.Config.EngineSnapEnvironment.SnapToleranceUnits == esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels) { _tolerance = ArcGIS.Common.Helpers.CommonHelper.ConvertPixelsToMapUnits(_context.ActiveView, _tolerance); } this.SelectByClick(x, y); IEnumFeature enumFeature = _context.FocusMap.FeatureSelection as IEnumFeature; IFeature feature = enumFeature.Next(); if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPoint) { _pointFeature = feature; } if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { _lineFeature = feature; } if (_pointFeature == null || _lineFeature == null) { return; } _context.FocusMap.SelectFeature(_pointFeatureLayer, _pointFeature); _context.FocusMap.SelectFeature(_lineFeatureLayer, _lineFeature); try { double distance = GeometryHelper.GetDistance(_lineFeature, _pointFeature); if (MessageBox.Show($@"要素:{_pointFeature.OID},距离线{distance:0.0000}米,是否继续?", @"提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { IFeature secondFeature = CommonHelper.CutOffPolylineByPoint(_lineFeatureLayer.FeatureClass, _lineFeature, _pointFeature, _gdbhFieldName, _qdbhFieldName, _zdbhFieldName); _context.FocusMap.SelectFeature(_pointFeatureLayer, _pointFeature); _context.FocusMap.SelectFeature(_lineFeatureLayer, _lineFeature); _context.FocusMap.SelectFeature(_lineFeatureLayer, secondFeature); _context.ActiveView.Refresh(); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public void GetSortInfos(ArrayList pSortInfos) { IMap map = _context.FocusMap; IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection; IFeature feature = enumFeature.Next(); if (feature != null) { do { if (feature.FeatureType == esriFeatureType.esriFTSimpleEdge) { IPolyline egLine = feature.Shape as IPolyline; IPoint newCenter = new PointClass(); egLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.01, true, newCenter); IEdgeFeature pEgFeature = feature as IEdgeFeature; IFeatureClass pClass = feature.Class as IFeatureClass; INetworkClass pNetworkClass = pClass as INetworkClass; INetElements network = pNetworkClass.GeometricNetwork.Network as INetElements; IEnumFeature enumFeatures = pNetworkClass.GeometricNetwork.SearchForNetworkFeature(newCenter, esriFeatureType.esriFTSimpleEdge); IEdgeFeature edgeFeature = (IEdgeFeature)enumFeatures.Next(); ISimpleEdgeFeature simpedgeFeature = (ISimpleEdgeFeature)edgeFeature; pSortInfos.Add(new SortInfo { SmID = simpedgeFeature.EID, SmFNode = edgeFeature.FromJunctionEID, SmTNode = edgeFeature.ToJunctionEID }); } feature = enumFeature.Next(); } while (feature != null); } }
private void Near_Click(object sender, EventArgs e) { ISelection selection = mMapControl.Map.FeatureSelection; IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup; enumFeatureSetup.AllFields = true; IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature; enumFeature.Reset(); IFeature feature = enumFeature.Next(); IPoint center = feature.Shape as IPoint; AreaNear a = new AreaNear(mMapControl, center); a.Show(); }
public static void GetClosestSelectedFeature(IPoint inPoint, IMap pMap, out IFeature pFeature) { pFeature = null; IProximityOperator ipoint0 = (IProximityOperator)inPoint; IEnumFeature featureSelection = (IEnumFeature)pMap.FeatureSelection; featureSelection.Reset(); IFeature i = featureSelection.Next(); if (i != null) { double num = ipoint0.ReturnDistance(i.ShapeCopy); pFeature = i; for (i = featureSelection.Next(); i != null; i = featureSelection.Next()) { double num1 = ipoint0.ReturnDistance(i.Shape); if (num1 < num) { num = num1; pFeature = i; } } } }
private bool JudgeGeometryType(IEnumFeature SelectedFeatures) { SelectedFeatures.Reset(); IFeature feature = SelectedFeatures.Next(); if (feature == null) { return(false); } esriGeometryType geometryType = feature.ShapeCopy.GeometryType; while ((feature = SelectedFeatures.Next()) != null) { if (geometryType != feature.ShapeCopy.GeometryType) { return(false); } } if (geometryType == currentLayer.FeatureClass.ShapeType) { return(true); } return(false); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ModifyShape.OnMouseDown implementation m_MapControl.Map.ClearSelection(); m_MapControl.ActiveView.Refresh(); SelectMouseDown(X, Y); IEnumFeature pSelected = (IEnumFeature)m_MapControl.Map.FeatureSelection; IFeature pFeature = pSelected.Next(); if (pFeature == null) { return; } IActiveView pActiveView = m_MapControl.ActiveView; IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //设置捕捉容差 double tol = ConvertPixelsToMapUnits(pActiveView, 4); IGeometry pGeom = pFeature.Shape; IObjectClass pObjectClass = pFeature.Class; m_EditFeature = pFeature; switch (pGeom.GeometryType) { case esriGeometryType.esriGeometryPoint: m_Feedback = new MovePointFeedbackClass(); m_Feedback.Display = pActiveView.ScreenDisplay; IMovePointFeedback pPointMove = (IMovePointFeedback)m_Feedback; pPointMove.Start((IPoint)pGeom, pPoint); break; case esriGeometryType.esriGeometryPolyline: m_Feedback = new MoveLineFeedbackClass(); m_Feedback.Display = pActiveView.ScreenDisplay; IMoveLineFeedback m_MoveLineFeedback = (IMoveLineFeedback)m_Feedback; m_MoveLineFeedback.Start((IPolyline)pGeom, pPoint); break; case esriGeometryType.esriGeometryPolygon: m_Feedback = new MovePolygonFeedbackClass(); m_Feedback.Display = pActiveView.ScreenDisplay; IMovePolygonFeedback m_MovePolygonFeedback = (IMovePolygonFeedback)m_Feedback; m_MovePolygonFeedback.Start((IPolygon)pGeom, pPoint); break; } }
/// <summary> /// Converts an Esri enumerable interface to a DotNet IEnumerable. /// </summary> /// <param name="esriEnum">An enumerable Esri interface, e.g. /// map.FeatureSelection as IEnumFeature .</param> /// <returns>The adapted dotnet enumeration.</returns> public static IEnumerable <IFeature> Enumerate(this IEnumFeature esriEnum) { // Return all columns of the feature if (esriEnum is IEnumFeatureSetup) { ((IEnumFeatureSetup)esriEnum).AllFields = true; } IFeature feature; esriEnum.Reset(); while ((feature = esriEnum.Next()) != null) { yield return(feature); } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { //鼠标在选择集的范围外为选择功能 IPoint pPnt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (ModPublic.MouseOnSelection(pPnt, m_hookHelper.ActiveView) == false && m_bMouseDown == false) {//若光标不在选择的对象上,为选择功能 ControlsEditSelFeature clsSelectFeature = new ControlsEditSelFeature(); clsSelectFeature.OnCreate(m_hookHelper.Hook); clsSelectFeature.OnClick(); m_MapControl.CurrentTool = clsSelectFeature as ITool; return; } //鼠标在选择要素节点上时为节点移动功能 if (m_MapControl.Map.SelectionCount == 1) { IEnumFeature pEnumFeature = m_MapControl.Map.FeatureSelection as IEnumFeature; pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); if (ModPublic.MouseOnFeatureVertex(pPnt, pFeature, m_hookHelper.ActiveView) == true && MoData.v_bVertexSelectionTracker == true) { ControlsMoveVertex pControlsMoveVertex = new ControlsMoveVertex(); pControlsMoveVertex.OnCreate(m_hookHelper.Hook); pControlsMoveVertex.OnClick(); m_MapControl.CurrentTool = pControlsMoveVertex as ITool; return; } } //捕捉节点 if (MoData.v_bSnapStart) { ModPublic.SnapPoint(pPnt, m_hookHelper.ActiveView); } if (Button != 1) { return; } //进行移动 if (m_MapControl.Map.SelectionCount > 0 && m_pMoveGeometryFeedback != null && m_pNewLineFeedback != null) { m_pMoveGeometryFeedback.MoveTo(pPnt); m_pNewLineFeedback.MoveTo(pPnt); } }
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 selFeature = SelectedFeatures.Next(); //SetAllLayersSelectable(); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent); return(selFeature); }
private IPolyline method_0() { IScene scene = this._plugin.Scene; IPolyline result; if (scene.SelectionCount == 1) { IEnumFeature enumFeature = scene.FeatureSelection as IEnumFeature; IFeature feature = enumFeature.Next(); if (feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { IPolyline polyline = feature.ShapeCopy as IPolyline; result = polyline; return(result); } } result = null; return(result); }
public override void OnDblClick() { IEnumFeature pEnumFeature = m_MapControl.Map.FeatureSelection as IEnumFeature; if (pEnumFeature == null) { return; } pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); if (pFeature == null) { return; } ModPublic.DrawEditSymbol(pFeature.Shape, m_hookHelper.ActiveView); MoData.v_bVertexSelectionTracker = true; }
public void ActiveCommand() { if (!this.Enabled) { _context.ShowCommandString("", CommandTipsType.CTTCommandTip); if (_context.Config.IsInEdit) { _context.ShowCommandString("节点编辑工具", CommandTipsType.CTTInput); _context.ShowCommandString("请选择线或面要素", CommandTipsType.CTTCommandTip); } else { _context.ShowCommandString("还未启动编辑,请先启动编辑", CommandTipsType.CTTUnKnown); } } else { _context.ShowCommandString("", CommandTipsType.CTTCommandTip); _context.ShowCommandString("节点编辑工具", CommandTipsType.CTTInput); if (_context.FocusMap.SelectionCount == 1) { IEnumFeature featureSelection = _context.FocusMap.FeatureSelection as IEnumFeature; featureSelection.Reset(); IFeature feature = featureSelection.Next(); esriGeometryType geometryType = feature.Shape.GeometryType; if ((geometryType == esriGeometryType.esriGeometryPolyline ? false : geometryType != esriGeometryType.esriGeometryPolygon)) { this.ifeature_0 = null; this.ipointCollection_0 = null; } else { this.ifeature_0 = feature; this.ipointCollection_0 = this.ifeature_0.Shape as IPointCollection; } } this.ShowCommand(); } }
/// <summary> /// 判断有没有选择要素 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> bool isSelect() { bool b = true; IMap map = axMapControl1.Map; ISelection selection = map.FeatureSelection; IEnumFeatureSetup iEnumFeatureSetup = (IEnumFeatureSetup)selection; iEnumFeatureSetup.AllFields = true; IEnumFeature pEnumFeature = (IEnumFeature)iEnumFeatureSetup; pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); if (pFeature == null) { b = false; } return(b); }
/// <summary> /// 获得当前视图上的选择要素 /// </summary> /// <param name="pMap"></param> /// <returns></returns> private IGeometry ConstructUnion(IMap pMap) { ISelection pSelection = pMap.FeatureSelection; // IEnumFeature pEnumFeature = pSelection as IEnumFeature; IFeature pFeature = pEnumFeature.Next(); //考虑到有点 线 面的情况 所以只选第一个要素 if (pFeature == null) { return(null); } IGeometry pGeometry = pFeature.ShapeCopy; ITopologicalOperator2 pTopo2 = pGeometry as ITopologicalOperator2; pTopo2.IsKnownSimple_2 = false; pTopo2.Simplify(); return(pTopo2 as IGeometry); }
private void CreatePolygonsFromFeatures(IFeatureClass getpolygon_fc) { IDataset dataset = getpolygon_fc as IDataset; IWorkspaceEdit workspace = dataset.Workspace as IWorkspaceEdit; if (!workspace.IsBeingEdited()) { workspace.StartEditing(true); if (!workspace.IsBeingEdited()) { return; } workspace.StartEditOperation(); } IFeatureConstruction construction = new FeatureConstructionClass(); IEnumFeature featureSelection = this.m_hookHelper.FocusMap.FeatureSelection as IEnumFeature; if (featureSelection.Next() != null) { construction.ConstructPolygonsFromFeatures(null, getpolygon_fc, null, false, false, featureSelection, null, 0.01, null); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add chooseAddress.OnClick implementation List <IFeature> pList = new List <IFeature>();//用于存储选中的要素 IEnumFeature pEnumFeature = me.Map.FeatureSelection as IEnumFeature; IFeature pFeature = pEnumFeature.Next(); //while (pFeature != null) //{ // pList.Add(pFeature); // pFeature = pEnumFeature.Next(); //} ITopologicalOperator to = pFeature.Shape as ITopologicalOperator; IPolygon poly = to.Buffer(1) as IPolygon; ISpatialFilter ipSpatialFilter = new SpatialFilterClass(); ipSpatialFilter.Geometry = poly; ipSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureSelection ipFeatSelect = m_hookHelper.FocusMap.get_Layer(0) as IFeatureSelection; ipFeatSelect.Clear(); ipFeatSelect.SelectFeatures(ipSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); ICursor cur = null; ipFeatSelect.SelectionSet.Search(null, true, out cur); IFeature feature = cur.NextRow() as IFeature; feature = cur.NextRow() as IFeature; if (feature != null) { MessageBox.Show("选址成功 可以添加"); return; } MessageBox.Show("选址失败 该处不可以添加"); }
/// <summary> /// Removes features from the map selection. /// </summary> /// <param name="features">A feature enumeration of those features to remove from the selection.</param> /// <param name="layer">The layer to which the features belong.</param> public static void RemoveFeaturesFromSelection(IEnumFeature features, ILayer layer) { if (features != null) { features.Reset(); IFeature feature = features.Next(); IFeatureSelection featureSelection = ((IFeatureLayer)layer) as IFeatureSelection; ISelectionSet selSet = featureSelection.SelectionSet; while (feature != null) { RemoveFeatureFromSelection(feature, selSet); feature = features.Next(); } featureSelection.SelectionChanged(); } }