/// <summary> /// 将矢量图层中所有要素的几何体进行合并操作得到一个新几何体。 /// </summary> /// <param name="featureLayer">输入矢量图层</param> /// <returns>合并后的新几何体</returns> public static IGeometry UnionFeatureToOneGeometry(IFeatureLayer featureLayer) { //定义IGeometry接口的对象,存储每一步拓扑操作后得到的几何体 IGeometry geometry = null; //使用null作为查询过滤器得到图层中所有要素的游标 IFeatureCursor featureCursor = featureLayer.Search(null, false); //获取IFeature接口的游标中的第一个元素 IFeature feature = featureCursor.NextFeature(); //当游标不为空时 while (feature != null) { //如果几何体不为空 if (geometry != null) { //进行接口转换,使用当前几何体的ITopologicalOperator接口进行拓扑操作 ITopologicalOperator topologicalOperator = geometry as ITopologicalOperator; //执行拓扑合并操作,将当前要素的几何体与已有几何体进行Union,返回新的合并后的几何体 if (topologicalOperator != null) { geometry = topologicalOperator.Union(feature.Shape); } } else { geometry = feature.Shape; } //移动游标到下一个要素 feature = featureCursor.NextFeature(); } return(geometry); }
public static IGeometry CreateConvexHull(IFeatureCursor pFeatureCursor) { IGeometryCollection pGeomCollection = (IGeometryCollection) new Polygon(); IGeometryCollection pGeomCollectionIn; IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { pGeomCollectionIn = (IGeometryCollection)pFeature.ShapeCopy; for (int i = 0; i < pGeomCollectionIn.GeometryCount; i++) { pGeomCollection.AddGeometry(pGeomCollectionIn.get_Geometry(i)); } pFeature = pFeatureCursor.NextFeature(); } ITopologicalOperator pTopOp = (ITopologicalOperator)pGeomCollection; //pTopOp.Simplify(); IGeometry pGeom = pTopOp.ConvexHull(); return(pGeom); }
//双击则创建该线,并弹出缓冲窗体 public override void OnDblClick() { //获取折线 并获取当前视图的屏幕显示 if (m_pNewPolygonFeedback == null) { return; } IPolygon pPolygon = m_pNewPolygonFeedback.Stop(); m_pNewPolygonFeedback = null; //不存在,为空。尺寸不够均退出 if (pPolygon == null || pPolygon.IsEmpty) { return; } if (pPolygon.Envelope.Width < 0.01 || pPolygon.Envelope.Height < 0.01) { return; } //创建Topo对象,简化后统一空间参考 ITopologicalOperator pTopo = (ITopologicalOperator)pPolygon; pTopo.Simplify(); pPolygon.Project(m_MapControl.Map.SpatialReference); if (m_frmQuery == null) { m_frmQuery = new frmQuery(m_MapControl, m_enumQueryMode); m_frmQuery.Owner = m_mainFrm; m_frmQuery.FormClosed += new FormClosedEventHandler(frmQuery_FormClosed); } frmBufferSet pFrmBufSet = new frmBufferSet(pPolygon as IGeometry, m_MapControl.Map, m_frmQuery); IGeometry pGeometry = pFrmBufSet.GetBufferGeometry(); if (pGeometry == null || pFrmBufSet.Res == false) { return; } // m_frmQuery.Show(); //m_frmQuery.FillData(m_MapControl.ActiveView.FocusMap, pGeometry); _QuerBar.m_pMapControl = m_MapControl; _QuerBar.EmergeQueryData(m_MapControl.ActiveView.FocusMap, pGeometry, pFrmBufSet.pesriSpatialRelEnum); try { DevComponents.DotNetBar.Bar pBar = _QuerBar.Parent.Parent as DevComponents.DotNetBar.Bar; if (pBar != null) { pBar.AutoHide = false; //pBar.SelectedDockTab = 1; int tmpindex = pBar.Items.IndexOf("dockItemDataCheck"); pBar.SelectedDockTab = tmpindex; } } catch { } m_frmQuery = null; }
/// <summary> /// 在要素上面绘制一个可拖拽的符号 /// </summary> /// <param name="geometry"></param> public void DrawEditSymbol(IGeometry geometry, IDisplay display) { IEngineEditProperties engineProperty = new EngineEditorClass(); ISymbol pointSymbol = engineProperty.SketchVertexSymbol as ISymbol; ISymbol sketchSymbol = engineProperty.SketchSymbol as ISymbol; ITopologicalOperator pTopo = geometry as ITopologicalOperator; sketchSymbol.SetupDC(display.hDC, display.DisplayTransformation); sketchSymbol.Draw(pTopo.Boundary); IPointCollection pointCol = geometry as IPointCollection; for (int i = 0; i < pointCol.PointCount; i++) { IPoint point = pointCol.get_Point(i); pointSymbol.SetupDC(display.hDC, display.DisplayTransformation); pointSymbol.Draw(point); pointSymbol.ResetDC(); } //mMyMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, mMyselectedLayer, null); //----- //ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(sketchSymbol); //ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pointSymbol); //ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(engineProperty); }
/// <summary> /// 计算每个数据点相邻的数据点,找出核心点 /// </summary> private void FindNeighborPoints() { for (int i = 0; i < m_DBSCANPnts.Count; i++) { List <DBSCANPoint> neighborPnts = new List <DBSCANPoint>(); IPoint point = m_DBSCANPnts[i].GetPoint(); ITopologicalOperator topologicalOperator = point as ITopologicalOperator; IGeometry pointBuffer = topologicalOperator.Buffer(m_dEps);//缓冲距离 topologicalOperator.Simplify(); ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = pointBuffer; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; IFeatureLayer featurelayer = m_dataInfo.GetInputLayer() as IFeatureLayer; IFeatureCursor featureCursor = featurelayer.FeatureClass.Search(spatialFilter, false); IFeature feature = featureCursor.NextFeature(); while (feature != null) { neighborPnts.Add(GetDBSCANPointByOID(feature.OID)); feature = featureCursor.NextFeature(); } m_DBSCANPnts[i].SetNeighborPoints(neighborPnts); //标记核心点 if (m_DBSCANPnts[i].GetNeighborPoints().Count >= m_nMinPts) { m_DBSCANPnts[i].SetPointType(1); } System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); } }
/// <summary> /// 鼠标移动时运行 /// </summary> /// <param name="movePT">鼠标地图点</param> public void OnMouseMoveRun(IPoint movePT) { if (polygonFeedback != null) { polygonFeedback.MoveTo(movePT); } // 点集合 IPointCollection pointColTemp = new Polygon(); for (int i = 0; i < pointCollection.PointCount; i++) { pointColTemp.AddPoint(pointCollection.get_Point(i), Type.Missing, Type.Missing); } // 添加当前点 pointColTemp.AddPoint(movePT); if (pointColTemp.PointCount < 3) { return; } // 获得图形 IPolygon polygon = pointColTemp as IPolygon; if (polygon != null) { polygon.Close(); IGeometry geo = polygon as IGeometry; ITopologicalOperator topo = geo as ITopologicalOperator; topo.Simplify(); geo.Project(mapControl.SpatialReference); // 获得面积 IArea area = geo as IArea; totalArea = area.Area; } }
/// 合并列表中所有多边形 /// </summary> /// <param name="orifeature">保留源对象</param> /// <param name="geolist">图形列表</param> /// <returns></returns> public void CreatePolygonFromExistingGeometries(IFeatureLayer lyr, IFeature orifeature, List <IGeometry> geolist) { int i = 0; IGeometry geometry = null; IFeatureClass Featureclass = lyr.FeatureClass; IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace; workspace.StartEditing(false); workspace.StartEditOperation(); //合并图形 ITopologicalOperator2 topologicalOperator2 = orifeature.ShapeCopy as ITopologicalOperator2; for (i = 0; i < geolist.Count; i++) { IGeometry geo = geolist[i]; if (geometry != null) { topologicalOperator2 = geometry as ITopologicalOperator2; } ITopologicalOperator opertor = geo as ITopologicalOperator; opertor.Simplify(); topologicalOperator2.IsKnownSimple_2 = false; topologicalOperator2.Simplify(); geometry = topologicalOperator2.Union(geo); } //更新图形对象 IGeometry geoCombined = (IGeometry)geometry; orifeature.Shape = geoCombined as IGeometry; orifeature.Store(); workspace.StopEditOperation(); workspace.StopEditing(true); }
public IPolygon BoundingPolygon(IList <IPoint> pList, ISpatialReference spatialrefrence) { try { IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; IPointCollection4 pPointColl = (IPointCollection4) new Multipoint(); // edited here int numPoints = pList.Count; WKSPoint[] aWKSPointBuffer = new WKSPoint[numPoints]; for (int i = 0; i < pList.Count; i++) { WKSPoint A = new WKSPoint(); A.X = pList[i].X; A.Y = pList[i].Y; aWKSPointBuffer[i] = A; } pGeoBrg.SetWKSPoints(pPointColl, ref aWKSPointBuffer); // edits here IGeometry pGeom = (IMultipoint)pPointColl; pGeom.SpatialReference = spatialrefrence; ITopologicalOperator pTopOp = (ITopologicalOperator)pGeom; IPolygon pPointColl2 = (IPolygon)pTopOp.ConvexHull(); pPointColl2.SpatialReference = spatialrefrence; // OutputPolygon = pPointColl2; maybe you don't need this line as the object is not used return(pPointColl2); } catch (Exception e) { return(null); } }
private void button2_Click(object sender, EventArgs e) { IActiveView pIActiveView = pmapcontrol.Map as IActiveView; IGraphicsContainer pIGraphicsContainer = pIActiveView.GraphicsContainer; pIGraphicsContainer.DeleteAllElements(); IFeatureLayer pIFeatureLayer = pmapcontrol.get_Layer(0) as IFeatureLayer; IFeatureCursor pIFeatureCursor = pIFeatureLayer.FeatureClass.Search(null, false); IFeature pfeature = pIFeatureCursor.NextFeature(); while (pfeature != null) { ITopologicalOperator pITopologicalOperator = pfeature.Shape as ITopologicalOperator; IPolygon pPolygon = pITopologicalOperator.Buffer(double.Parse(textBox1.Text)) as IPolygon; IElement pIElement = new PolygonElement(); pIElement.Geometry = pPolygon; pIGraphicsContainer.AddElement(pIElement, 0); pfeature = pIFeatureCursor.NextFeature(); } pmapcontrol.Refresh(); this.Close(); }
private void 计算测区范围ToolStripMenuItem_Click(object sender, EventArgs e) { IFeatureClass PointFeatureClass = null; for (int i = 0; i < axMapControl1.LayerCount; i++) { ILayer pFeatureLayer = axMapControl1.get_Layer(i); IFeatureLayer pFlayer = pFeatureLayer as IFeatureLayer; IFeatureClass pFClass = pFlayer.FeatureClass; if (pFClass.ShapeType == esriGeometryType.esriGeometryPoint) { PointFeatureClass = pFClass; break; } } IGeometry ConvexHullGeometry = null; //IFeature MultiPointFeature = Convert_Point2MultiPoint__Class(PointFeatureClass); ; IPointCollection ptCollection = Convert_Point2MultiPoint(PointFeatureClass); //ITopologicalOperator topOperator = MultiPointFeature.Shape as ITopologicalOperator; ITopologicalOperator topOperator = ptCollection as ITopologicalOperator; ConvexHullGeometry = topOperator.ConvexHull(); IPolygon CHpolygon = ConvexHullGeometry as IPolygon; IArea pArea = ConvexHullGeometry as IArea; MessageBox.Show(pArea.Area.ToString()); }
/// <summary> /// 多部分(多外环)的多边形转成多个单部分的多边形 /// </summary> /// <param name="polygon"></param> /// <returns></returns> public static IPolygon[] MultiPartToSinglePart(this IPolygon4 polygon) { List <IPolygon> polygons = new List <IPolygon>(); //外部环 IGeometryBag exteriorRingGeometryBag = polygon.ExteriorRingBag; IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection; for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++) { IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i); IRing ring = exteriorRingGeometry as IRing; ring.Close(); IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(ring); //内部环 IGeometryBag interiorRingGeometryBag = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing); IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection; for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++) { IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k); IRing ring2 = interiorRingGeometry as IRing; ring2.Close(); pGeometryColl.AddGeometry(ring2); } ITopologicalOperator pTopological = pGeometryColl as ITopologicalOperator; pTopological.Simplify(); IPolygon p = pGeometryColl as IPolygon; polygons.Add(p); } return(polygons.ToArray()); }
private void 给出可测区域ToolStripMenuItem_Click(object sender, EventArgs e) { IGeometry buffer; ISelection pSeletion = axMapControl1.Map.FeatureSelection; IEnumFeature pEnumFeature = (IEnumFeature)pSeletion; IGraphicsContainer graphicsContainer = axMapControl1.ActiveView.GraphicsContainer; graphicsContainer.DeleteAllElements(); IFeature pFeature = pEnumFeature.Next(); double bufferDistance = GlobalData.dist; if (bufferDistance <= 0.0) { MessageBox.Show("距离设置错误"); return; } while (pFeature != null) { ITopologicalOperator topoOperator = pFeature.Shape as ITopologicalOperator; buffer = topoOperator.Buffer(bufferDistance); IElement element = new PolygonElementClass(); element.Geometry = buffer; graphicsContainer.AddElement(element, 0); pFeature = pEnumFeature.Next(); } axMapControl1.Refresh(); }
private IPolygon DissolvePolygon(ISpatialReference spatialRef, Dictionary <string, IPolygon> originPolygonDict, string[] originStrArr) { IGeometry geometryBag = new GeometryBagClass(); var geoCollection = (IGeometryCollection)geometryBag; ((IGeometry)geoCollection).SpatialReference = spatialRef; for (int i = 0; i < originStrArr.Length; i++) { var originStr = originStrArr[i]; object missing = Type.Missing; //var polygon = (IPolygon)((IClone)originPolygonDict[originStr]).Clone(); geoCollection.AddGeometry(originPolygonDict[originStr], ref missing, ref missing); } // 找到的要素合并为一个要素 IPolygon outPolygon = new PolygonClass(); ITopologicalOperator topologicalOperator = (ITopologicalOperator)outPolygon; topologicalOperator.ConstructUnion((IEnumGeometry)geometryBag); return(outPolygon); }
public static int GetVertexIndex(IPoint pPoint, IGeometry pGeo) { int functionReturnValue = -2; //图形为空,则退出 IPointCollection pPointCollection = pGeo as IPointCollection; if (pPointCollection == null) { return(functionReturnValue); } ITopologicalOperator pTopoOpt = pPointCollection as ITopologicalOperator; IRelationalOperator pRelationalOperator = pPoint as IRelationalOperator; IProximityOperator pProx = pPoint as IProximityOperator; bool pIsEqual = false; for (int i = 0; i < pPointCollection.PointCount; i++) { pIsEqual = pRelationalOperator.Equals(pPointCollection.get_Point(i)); if (pIsEqual) { functionReturnValue = i; break; } } return(functionReturnValue); }
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); }
/// <summary> /// 创建要素 /// </summary> /// <param name="pGeometry"></param> private void CreateFeature(IGeometry pGeometry) { try { if (m_EngineEditLayers == null) { return; } IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } if (m_EngineEditor == null) { return; } if (pGeometry == null) { return; } ITopologicalOperator pTop = pGeometry as ITopologicalOperator; pTop.Simplify(); IGeoDataset pGeoDataset = pFeatCls as IGeoDataset; if (pGeoDataset.SpatialReference != null) { pGeometry.Project(pGeoDataset.SpatialReference); } m_EngineEditor.StartOperation(); IFeature pFeature = null; pFeature = pFeatCls.CreateFeature(); IZAware ipZAware = pGeometry as IZAware; if (ipZAware.ZAware == true) { ipZAware.ZAware = false; } if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { pFeature.Shape = pGeometry; } else { pFeature.Shape = SupportZMFeatureClass.ModifyGeomtryZMValue(pFeatCls, pGeometry); } pFeature.Store(); m_EngineEditor.StopOperation("添加要素"); m_Map.SelectFeature(pFeatLyr, pFeature); m_activeView.Refresh(); } catch (Exception ex) { //SysLogHelper.WriteOperationLog("要素添加错误", ex.Source, "数据编辑"); } }
public IFeature GetNearToFeature() { if (Polyline == null || PointFeatureLayer == null) { return(null); } ITopologicalOperator pTopologicalOperator = Polyline.ToPoint as ITopologicalOperator; if (pTopologicalOperator == null) { return(null); } ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pTopologicalOperator.Buffer(Tolerance); pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; pSpatialFilter.GeometryField = PointFeatureLayer.FeatureClass.ShapeFieldName; IFeatureCursor pFeatureCursor = PointFeatureLayer.Search(pSpatialFilter, false); IFeature pFeature = pFeatureCursor.NextFeature(); Marshal.ReleaseComObject(pFeatureCursor); return(pFeature); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { int iPiexl = 3; double iMapTolerance = ConvertPixelsToMapUnits(m_MapControl.ActiveView, iPiexl); IGeometry pGeometry = null; ITopologicalOperator pTopo = (ITopologicalOperator)m_pPoint; if (pTopo != null) { pGeometry = pTopo.Buffer(iMapTolerance); } if (m_frmQuery == null) { m_frmQuery = new frmQueryForest(m_MapControl); m_frmQuery.Owner = m_mainFrm; m_frmQuery.FormClosed += new FormClosedEventHandler(frmQuery_FormClosed); } //ygc 2012-8-28 将查询结果数据在主窗体下方显示 // _QuerBar.m_pMapControl = m_MapControl; // _QuerBar.EmergeQueryData(m_MapControl.ActiveView.FocusMap, pGeometry, esriSpatialRelEnum.esriSpatialRelIntersects); m_frmQuery.Show(); ///ZQ 20111119 modify m_frmQuery.FillData(m_MapControl.ActiveView.FocusMap, pGeometry, esriSpatialRelEnum.esriSpatialRelIntersects); }
/// <summary> /// Buffers the input geometry. /// </summary> /// <param name="inputGeometry">The input geometry.</param> /// <param name="bufferDistance">The buffer distance.</param> public static void BufferGeometry(ref IGeometry inputGeometry, double bufferDistance) { if (inputGeometry == null) { return; } if (inputGeometry.IsEmpty) { return; } IGeometry bufferGeometry = null; //// DEBUG - Check area before //if (inputGeometry is IPolygon) //{ // IArea areaBefore = inputGeometry as IArea; // System.Diagnostics.Debug.WriteLine(areaBefore.Area); //} // Get the ITopologicalOperator ITopologicalOperator topoOp = (ITopologicalOperator)inputGeometry; // Perform buffer bufferGeometry = topoOp.Buffer(bufferDistance); //// DEBUG - Check area after //if (bufferGeometry is IPolygon) //{ // IArea areaAfter = bufferGeometry as IArea; // System.Diagnostics.Debug.WriteLine("After Buffer: " + areaAfter.Area); //} inputGeometry = bufferGeometry; }
public virtual void Cut(IGeometry cutter, out IGeometry leftGeom, out IGeometry rightGeom) { this.Topoperator = this.pFeature.ShapeCopy as ITopologicalOperator; IPolyline pcutter = cutter as IPolyline; this.Topoperator.Cut(pcutter, out leftGeom, out rightGeom); }
public string CheckLine(string pipelineName, IPolyline polyline, IFeatureClass featureClass) { string message = ""; ITopologicalOperator topologicalOperator = polyline as ITopologicalOperator; IPolygon polygon = topologicalOperator.Buffer(_dataCheck.DataCheckConfig.LineMinimumSpacing) as IPolygon; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = polygon; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; spatialFilter.GeometryField = featureClass.ShapeFieldName; IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); IFeature feature; while ((feature = featureCursor.NextFeature()) != null) { IPolyline tempPolyline = feature.Shape as IPolyline; if (tempPolyline == null || tempPolyline.IsEmpty) { continue; } IProximityOperator proximityOperator = polyline as IProximityOperator; double d = proximityOperator.ReturnDistance(tempPolyline); if (d < _dataCheck.DataCheckConfig.LineMinimumSpacing) { message += $"{pipelineName}:与 {feature.OID} 的距离为 {d};"; } } Marshal.ReleaseComObject(featureCursor); return(message); }
/// <summary> /// 通过簇的点集计算簇的凸包 /// </summary> /// <returns></returns> public void CreateConvexHull(ISpatialReference spatialReference) { //少于3个点就不做 if (m_pointsList.Count < 3) { return; } IGeometryCollection geometryCollection = new MultipointClass(); for (int i = 0; i < m_pointsList.Count; i++) { geometryCollection.AddGeometry(m_pointsList[i] as IGeometry); } ITopologicalOperator pTopological = geometryCollection as ITopologicalOperator; IGeometry g = pTopological.ConvexHull(); if (g.GeometryType != esriGeometryType.esriGeometryPolygon) { return; } IPolygon convexHull = g as IPolygon; convexHull.SpatialReference = spatialReference; m_convexHull = convexHull; }
public void GetFeatureOnMouseDown(int x, int y) { MyselectedFeature.Clear(); try { if (MyselectedLayer == null) { return; } IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } IPoint point = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IGeometry geometry = point as IGeometry; double length = ConvertPixelsToMapUnits(4); ITopologicalOperator pTopo = geometry as ITopologicalOperator; IGeometry buffer = pTopo.Buffer(length); geometry = buffer.Envelope as IGeometry; ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geometry; switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; break; case esriGeometryType.esriGeometryPolygon: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; break; case esriGeometryType.esriGeometryPolyline: spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; break; } spatialFilter.GeometryField = featureClass.ShapeFieldName; IQueryFilter filter = spatialFilter as IQueryFilter; IFeatureCursor cursor = featureClass.Search(filter, false); IFeature pfeature = cursor.NextFeature(); while (pfeature != null) { MyselectedFeature.Add(pfeature); pfeature = cursor.NextFeature(); } } catch { return; } }
/// <summary> /// 两个几何取相交的部分 /// </summary> /// <param name="_pFeature"></param> /// <param name="_pOther"></param> /// <returns></returns> private IGeometry IntersectGeo(ITopologicalOperator _pFeature, IGeometry _pOther) { IGeometry pOutGeometry = null; pOutGeometry = _pFeature.Intersect(_pOther, esriGeometryDimension.esriGeometry2Dimension); return(pOutGeometry); }
//得到与线相交地物的交叉点 private IPointCollection GetIntersection(IGeometry pGeo, IPolyline pPolyline) { ITopologicalOperator topoOper = (ITopologicalOperator)pGeo; topoOper.Simplify(); IGeometry pResultGeo = topoOper.Intersect(pPolyline, esriGeometryDimension.esriGeometry0Dimension); if (pResultGeo == null) { return(null); } if (pResultGeo is IPointCollection) { IPointCollection pPtCol = pResultGeo as IPointCollection; if (pPtCol.PointCount > 0) { return(pPtCol); } else { return(null); } } return(null); }
private static void InsertFeaturesBoun(IFeatureClass newFeatureClass, IFeatureCursor featureCursorSearch, IGeometry clipGeo) { int intFeatureCount = 0; IFeatureCursor featureCursorInsert = newFeatureClass.Insert(true); IFeatureBuffer featureBufferInsert = newFeatureClass.CreateFeatureBuffer(); IFeature feature = featureCursorSearch.NextFeature(); while (feature != null) { ITopologicalOperator topoOpe = feature.Shape as ITopologicalOperator; IGeometry intersect = topoOpe.Intersect(clipGeo, feature.Shape.Dimension); featureBufferInsert.Shape = intersect; AddFields(featureBufferInsert, feature); featureCursorInsert.InsertFeature(featureBufferInsert); if (++intFeatureCount == 100) { featureCursorInsert.Flush(); intFeatureCount = 0; } feature = featureCursorSearch.NextFeature(); } featureCursorInsert.Flush(); }
protected override void OnDoubleClick() { base.OnDoubleClick(); try { if (LineFeedBack != null) { trackgeom = LineFeedBack.Stop(); LineFeedBack = null; if (GetDriveCenterlineIntersection(trackgeom)) { if (CalculateHouseNumber()) { SetAttributes(); } } mMap.ClearSelection(); ITopologicalOperator to = SelectedPoint.Shape as ITopologicalOperator; IGeometry g = to.Buffer(10); mMap.SelectByShape(g, ArcMap.ThisApplication.SelectionEnvironment, true); IFeatureSelection fsel = Globals.AddressPointLayer as IFeatureSelection; ArcMap.Document.FocusMap.ClearSelection(); ArcMap.Document.ActiveView.Refresh(); ArcMap.Document.FocusMap.ClearSelection(); } } catch { } }
/// <summary> /// 显示轮廓线 张琪 20110629 /// </summary> /// <param name="pPolygon"></param> private void ShowCountour(IPolygon pPolygon) { SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条"); try { Cls3DMarkDraw.DeleteAllElementsWithName(m_pCurrentSceneControl.Scene, ContourName); if (!chkShowContour.Checked) { m_pCurrentSceneControl.SceneGraph.RefreshViewers(); return; } vProgress.EnableCancel = false;//设置进度条 vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); vProgress.SetProgress("正在绘制轮廓线"); ITopologicalOperator pTopo = pPolygon as ITopologicalOperator; IGeometry pPolyLine = new PolylineClass(); pPolyLine = pTopo.Boundary; object StepSize = Type.Missing;; m_SurFace.InterpolateShape(pPolyLine as IGeometry, out pPolyLine, ref StepSize); IGroupElement pGroup = null; //用于绘制三维效果 Cls3DMarkDraw.AddSimpleGraphic(pPolyLine as IGeometry, Cls3DMarkDraw.getRGB(30, 255, 255), 4, ContourName, m_pCurrentSceneControl.Scene, pGroup); m_pCurrentSceneControl.SceneGraph.RefreshViewers(); vProgress.Close(); } catch { vProgress.Close(); } }
/// <summary> /// 按照指定的各部分的权重将一个多边形切分成多个 /// </summary> /// <param name="polygon">被切分的多边形</param> /// <param name="weights">切分后的多边形各个部分的权重</param> /// <param name="direction">切分多边形的方向,0为横向,1为纵向</param> /// <param name="tolerance">面积容差</param> /// <returns></returns> public static List <IPolygon> SplitPolygonByAreaWeights(IPolygon polygon, double[] weights, int direction, double tolerance = 0.001) { if (polygon.IsEmpty) { throw new Exception("几何图形不能为空(Empty)!"); } if (tolerance < 0) { throw new Exception("指定的容差不能小于0"); } var resultPolygons = new List <IPolygon>(); var tmpPolygon = polygon; for (int i = 0; i < weights.Length; i++) { var rate = weights[i] / weights.Skip(i).Sum(); if (rate == 1) { resultPolygons.Add(tmpPolygon); continue; } var resultPolygon = SplitPolygonByAreaRate(tmpPolygon, rate, direction, tolerance) as IPolygon; //截取多边形 ITopologicalOperator logicalOpt = (ITopologicalOperator)tmpPolygon; tmpPolygon = logicalOpt.Difference(resultPolygon) as IPolygon; //获取多边形截取后的剩余部分 resultPolygons.Add(resultPolygon); } return(resultPolygons); }
public static List <IFeature> GetAllFeaturesFromPolygonInGeoFeatureLayer(IPolygon polygon, IFeatureLayer featureLayer, IMap map, double distance = 0) { List <IFeature> list = new List <IFeature>(); if (polygon == null || featureLayer == null || map == null) { return(list); } ITopologicalOperator pTopologicalOperator = polygon as ITopologicalOperator; if (pTopologicalOperator == null) { return(list); } ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pTopologicalOperator.Buffer(distance); pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.OutputSpatialReference[featureLayer.FeatureClass.ShapeFieldName] = map.SpatialReference; pSpatialFilter.GeometryField = featureLayer.FeatureClass.ShapeFieldName; IFeatureCursor pFeatureCursor = featureLayer.Search(pSpatialFilter, false); IFeature pFeature; while ((pFeature = pFeatureCursor.NextFeature()) != null) { list.Add(pFeature); } Marshal.ReleaseComObject(pFeatureCursor); return(list); }