private List <IPoint> SplitPolyline(IPolyline polyline, IPointCollection intersectpointsColl, IPoint presentCP) { IEnumVertex pEnumVertex = intersectpointsColl.EnumVertices; //IPolycurve2 has SplitAtPoints IPolycurve2 pPolyCurve = polyline as IPolycurve2; pPolyCurve.SplitAtPoints(pEnumVertex, false, true, -1); IGeometryCollection geoColl = pPolyCurve as IGeometryCollection; //MessageBox.Show(geoColl.GeometryCount.ToString()); List <IPoint> ptlist = new List <IPoint>(); // The results are pathclass IPath resultPath; for (int i = 0; i < geoColl.GeometryCount; i++) { object obj = Type.Missing; resultPath = new PathClass(); resultPath = (IPath)geoColl.get_Geometry(i); IGeometryCollection lineColl = new PolylineClass(); lineColl.AddGeometry(resultPath, ref obj, ref obj); IPolyline line = (IPolyline)lineColl; IRelationalOperator pRelOperator = (IRelationalOperator)line; if (pRelOperator.Touches(presentCP) || pRelOperator.Contains(presentCP)) { IPoint temPT1 = resultPath.FromPoint; IPoint temPT2 = resultPath.ToPoint; //pGeometryCollection.AddGeometry(temPT1); //pGeometryCollection.AddGeometry(temPT2); ptlist.Add(temPT1); ptlist.Add(temPT2); } } return(ptlist); }
//几何图形坐标转换 private void GeometryCoordConvert(ref IGeometry pConvertGeometry, double A1, double B1, double C1, double A2, double B2, double C2, double A3, double C3) { object a = System.Reflection.Missing.Value; object b = System.Reflection.Missing.Value; bool isRing = false; if (pConvertGeometry.GeometryType != esriGeometryType.esriGeometryPoint)//如果为线要素或面要素 { IArray pArrayPoint = new ArrayClass(); IArray pGeometryArray = new ArrayClass(); IGeometryCollection pGeometryCollection = pConvertGeometry as IGeometryCollection; for (int i = 0; i < pGeometryCollection.GeometryCount; i++) { IGeometry pGeometry = pGeometryCollection.get_Geometry(i); if (pGeometry.GeometryType != esriGeometryType.esriGeometryPoint)// { #region if (pGeometry.GeometryType == esriGeometryType.esriGeometryRing) { isRing = true; } if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon) { pGeometry = CommonFunction.GetPolygonBoundary((IPolygon)pGeometry); } ISegmentCollection pSegmentCol = (ISegmentCollection)pGeometry; ISegmentCollection pNewSegmentCol = new PolylineClass(); for (int k = 0; k < pSegmentCol.SegmentCount; k++)//遍历几何形体的每个节(片断) { //该节为直线段 if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryLine) { IPointCollection pPointCol1 = new MultipointClass(); ILine pLine = (ILine)pSegmentCol.get_Segment(k); IPoint pFromPoint = pLine.FromPoint; pPointCol1.AddPoint((IPoint)pFromPoint, ref a, ref b); IPoint pToPoint = pLine.ToPoint; pPointCol1.AddPoint((IPoint)pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol1);//对点集做镜像 //修改线段的端点坐标 pLine.FromPoint = pPointCol1.get_Point(0); pLine.ToPoint = pPointCol1.get_Point(1); pNewSegmentCol.AddSegment((ISegment)pLine, ref a, ref b); } //该节为圆弧 else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryCircularArc) { IPointCollection pPointCol2 = new MultipointClass(); ICircularArc pCircularArc = (ICircularArc)pSegmentCol.get_Segment(k); try { IPoint pCenterPoint = pCircularArc.CenterPoint; pPointCol2.AddPoint((IPoint)pCenterPoint, ref a, ref b); IPoint pFromPoint = pCircularArc.FromPoint; pPointCol2.AddPoint((IPoint)pFromPoint, ref a, ref b); IPoint pToPoint = pCircularArc.ToPoint; pPointCol2.AddPoint((IPoint)pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol2);//对点集做镜像 //构造新的圆弧 ICircularArc pArc = new CircularArcClass(); pArc.PutCoords(pPointCol2.get_Point(0), pPointCol2.get_Point(1), pPointCol2.get_Point(2), (pCircularArc.IsCounterClockwise ? esriArcOrientation.esriArcCounterClockwise : esriArcOrientation.esriArcClockwise)); pNewSegmentCol.AddSegment((ISegment)pArc, ref a, ref b); } catch { } } //该节为贝塞尔曲线 else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryBezier3Curve) { IPointCollection pPointCol3 = new MultipointClass(); IBezierCurve pBezierCurve = (IBezierCurve)pSegmentCol.get_Segment(k); //记录该节贝塞尔曲线的4个控制点 IPoint pFromPoint = new PointClass(); pBezierCurve.QueryCoord(0, pFromPoint); pPointCol3.AddPoint(pFromPoint, ref a, ref b); IPoint pFromTangentPoint = new PointClass(); pBezierCurve.QueryCoord(1, pFromTangentPoint); pPointCol3.AddPoint(pFromTangentPoint, ref a, ref b); IPoint pToTangentPoint = new PointClass(); pBezierCurve.QueryCoord(2, pToTangentPoint); pPointCol3.AddPoint(pToTangentPoint, ref a, ref b); IPoint pToPoint = new PointClass(); pBezierCurve.QueryCoord(3, pToPoint); pPointCol3.AddPoint(pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol3);//对点集做镜像 //修改该节贝塞尔曲线的4个控制点 pBezierCurve.PutCoord(0, pPointCol3.get_Point(0)); pBezierCurve.PutCoord(1, pPointCol3.get_Point(1)); pBezierCurve.PutCoord(2, pPointCol3.get_Point(2)); pBezierCurve.PutCoord(3, pPointCol3.get_Point(3)); pNewSegmentCol.AddSegment((ISegment)pBezierCurve, ref a, ref b); } }//end for 遍历几何形体的每个节(片断) CommonFunction.GeometryToArray(pNewSegmentCol as IGeometry, pArrayPoint); IPolycurve2 pPolycurve2 = CommonFunction.BuildPolyLineFromSegmentCollection(pNewSegmentCol); pGeometry = (IGeometry)pPolycurve2; #endregion } if (pConvertGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//由线构成面 { pGeometry = CommonFunction.PolylineToPolygon(pGeometry as IPolyline); } pGeometryArray.Add(pGeometry); } if (pGeometryArray.Count > 1) { pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry; if (isRing == true) { for (int i = 1; i < pGeometryArray.Count; i++) { pConvertGeometry = CommonFunction.DiffenceGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry); } } else { for (int i = 1; i < pGeometryArray.Count; i++) { pConvertGeometry = CommonFunction.UnionGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry); } } } else { pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry; } CommonFunction.AddZMValueForGeometry(ref pConvertGeometry, pArrayPoint); } else { PointCoordConvert(ref pConvertGeometry, A1, B1, C1, A2, B2, C2, A3, C3); } }
//分割线 public virtual ZhFeature[] SplitPolyline(ZhFeature[] zhFeatures, ZhFeature[] pUsedZHFeatures) { List <ZhFeature> pMuliFeatures = new List <ZhFeature>(); List <IGeometry> GeoList = new List <IGeometry>(); GeoList.Clear(); List <IGeometry> CutterGeoList = new List <IGeometry>(); IPointCollection pMultipoint = null; IGeometry[] cgGeoArray = null; //几何对象分割 foreach (ZhFeature tpByFeat in zhFeatures) { CutterGeoList.Clear(); cgGeoArray = null; object obj = Type.Missing; IPolyline cutterPolyline = new PolylineClass(); pMultipoint = (IPointCollection)cutterPolyline; //求相交点的所有集合 foreach (ZhFeature tpUsedFeat in pUsedZHFeatures) { //求相交点集合 cgGeoArray = this.MuliCutPolyline(tpByFeat, tpUsedFeat); foreach (IGeometry tGeo in cgGeoArray) { if (((IRelationalOperator)pMultipoint).Contains(tGeo) == false) { pMultipoint.AddPoint((IPoint)tGeo, ref obj, ref obj); } } } //添加原线端点 //pMultipoint.AddPointCollection((IPointCollection)tpByFeat.pFeature.ShapeCopy); //拓朴化处理 去掉重复点操作 //ITopologicalOperator pTop = pMultipoint as ITopologicalOperator; //pTop.Simplify(); //pMultipoint = pTop as IPointCollection; //清除原对象 GeoList.Clear(); //用相交点集合分割线 if (tpByFeat.pFeature.Shape is IPolycurve2) { //IPoint outVertex = null; //IPoint preVertex = null; //int outPartIndex = 0; //int vertexIndex = 0; IPolycurve2 Curve2 = tpByFeat.pFeature.Shape as IPolycurve2; IEnumVertex SplitPoints = pMultipoint.EnumVertices; Curve2.SplitAtPoints(SplitPoints, true, true, -1); IGeometryCollection pcgGeoColl = Curve2 as IGeometryCollection; for (int i = 0; i < pcgGeoColl.GeometryCount; i++) { IGeometry tpcgGeo = pcgGeoColl.get_Geometry(i); IGeometryCollection oGeoCol = new PolylineClass(); oGeoCol.AddGeometries(1, ref tpcgGeo); if (((ITopologicalOperator)oGeoCol).IsSimple == false) { ((ITopologicalOperator)oGeoCol).Simplify(); } GeoList.Add(oGeoCol as IGeometry); } #region IEnumSplitPoint //IEnumSplitPoint cgEnumPoint=Curve2.SplitAtPoints(SplitPoints,false,false,-1); //cgEnumPoint.Reset(); //cgEnumPoint.Next(out outVertex, out outPartIndex, out vertexIndex); //while (outVertex != null && outVertex.IsEmpty != true && cgEnumPoint.IsLastInPart()!=true) //{ // preVertex=outVertex; // cgEnumPoint.Next(out outVertex, out outPartIndex, out vertexIndex); // if (preVertex != null && outVertex != null && outVertex.IsEmpty!=true) // { // IPolyline pcgPolyline = new PolylineClass(); // (pcgPolyline as IPointCollection).AddPoint(preVertex, ref obj, ref obj); // (pcgPolyline as IPointCollection).AddPoint(outVertex, ref obj, ref obj); // if (pcgPolyline.IsEmpty != true) // { // GeoList.Add(pcgPolyline); // } // } //} #endregion } //创建分割后对象 ZHFeatureByGeoList ZhFeature tpFeat = null; foreach (IGeometry pGeo in GeoList) { if (pGeo.IsEmpty != true) { tpFeat = this.CreateFeature(); //属性拷贝(含GHDM赋码) tpByFeat.CopyField(ref tpFeat); tpFeat.pFeature.Shape = pGeo; //保存 //tpFeat.pFeature.Store(); pMuliFeatures.Add(tpFeat); } } } return(pMuliFeatures.ToArray()); }
public void SplitPolylines() //分割线 { m_pLineFeed = (INewLineFeedback)m_pFeedback; IPolyline pFeatureScissors = (IPolyline)m_pLineFeed.Stop(); //结束绘制切割线 if (pFeatureScissors.Length == 0) { Reset(); return; } ITopologicalOperator pTopologim_CalOperator = (ITopologicalOperator)pFeatureScissors; ILayer pFeatureLayer; pFeatureLayer = m_App.CurrentEditLayer; IGeometry pOldGeometry; IFeature pOldFeature; IWorkspaceEdit pWorkspaceEdit; pWorkspaceEdit = (IWorkspaceEdit)CommonFunction.GetLayerWorkspace(pFeatureLayer); if (pWorkspaceEdit == null) { return; } if (!pWorkspaceEdit.IsBeingEdited()) { return; } pWorkspaceEdit.StartEditOperation(); for (int i = 0; i < m_OriginFeatureArray.Count; i++) //遍历每个选中的要素 { pOldFeature = (IFeature)m_OriginFeatureArray.get_Element(i); pOldGeometry = (IGeometry)pOldFeature.Shape; IArray pArray = new ArrayClass(); //将地理要素的坐标信息添加到点数组中 pArray = CommonFunction.GeometryToArray(pOldGeometry); //跳转到拓扑操作接口,求“剪刀”与选中要素的交点 IGeometry pIntersectGeo = pTopologim_CalOperator.Intersect(pOldGeometry, esriGeometryDimension.esriGeometry0Dimension); if (pIntersectGeo == null) { return; //无交点,则返回 } ITopologicalOperator pTopOp = (ITopologicalOperator)pIntersectGeo; pTopOp.Simplify(); IPointCollection pPointCol = (IPointCollection)pIntersectGeo; //交点的集合 //用相交的点集合打断该线 IPointCollection pTmpPointCol = new MultipointClass(); pTmpPointCol.AddPointCollection(pPointCol); //临时点集 IPolycurve2 pPolyCurve; pPolyCurve = (IPolycurve2)pOldGeometry; //被剪切的线要素 ((ITopologicalOperator)pPolyCurve).Simplify(); IGeometryCollection pGeoCollection; IGeometryCollection pTmpGeoCollection; //保存每次打断产生的线段 pTmpGeoCollection = (IGeometryCollection)pPolyCurve; pGeoCollection = (IGeometryCollection)pPolyCurve; for (int j = 0; j < pPointCol.PointCount; j++) //遍历每个交点 { IPoint pSplitPoint = pPointCol.get_Point(j); int GeoCount = 0; int pGeoCollectionCount = pGeoCollection.GeometryCount; while (GeoCount < pGeoCollectionCount) //遍历每个几何形体 { IPolycurve2 pTmpPolycurve2; pTmpPolycurve2 = CommonFunction.BuildPolyLineFromSegmentCollection((ISegmentCollection)pGeoCollection.get_Geometry(GeoCount)); bool bProject; //是否投影 bool bCreatePart; //是否创建新的附件 bool bSplitted; //分裂是否成功 int lNewPart; int lNewSeg; bProject = true; bCreatePart = true; ((ITopologicalOperator)pTmpPolycurve2).Simplify(); pTmpPolycurve2.SplitAtPoint(pSplitPoint, bProject, bCreatePart, out bSplitted, out lNewPart, out lNewSeg); if (bSplitted) //更新pGeoCollection { pGeoCollection.RemoveGeometries(GeoCount, 1); pTmpGeoCollection = (IGeometryCollection)pTmpPolycurve2; pGeoCollection.AddGeometryCollection(pTmpGeoCollection); } GeoCount++; } } IGeometryCollection pGeometryCol = pGeoCollection; //被打断后的线的集合 for (int intCount = 0; intCount < pGeometryCol.GeometryCount; intCount++) { IPolycurve2 pPolyline = CommonFunction.BuildPolyLineFromSegmentCollection((ISegmentCollection)pGeometryCol.get_Geometry(intCount)); CommonFunction.AddFeature(m_MapControl, (IGeometry)pPolyline, m_App.CurrentEditLayer, pOldFeature, pArray); } pOldFeature.Delete(); } m_App.Workbench.CommandBarManager.Tools["2dmap.DFEditorTool.Undo"].SharedProps.Enabled = true; pWorkspaceEdit.StopEditOperation(); Reset(); }
private IArray method_2(IGeometry igeometry_0, IGeometry igeometry_1) { IArray array; if (!(igeometry_0 == null ? false : igeometry_1 != null)) { array = null; } else if (igeometry_0.GeometryType == esriGeometryType.esriGeometryPolyline) { IGeometry geometry = ((ITopologicalOperator)igeometry_0).Intersect(igeometry_1, esriGeometryDimension.esriGeometry0Dimension); if (geometry != null) { ((ITopologicalOperator)geometry).Simplify(); IEnumVertex enumVertices = ((IPointCollection)geometry).EnumVertices; if (enumVertices != null) { IPolycurve2 igeometry0 = (IPolycurve2)igeometry_0; if (igeometry0.SplitAtPoints(enumVertices, true, true, -1).SplitHappened) { IGeometryCollection geometryCollection = (IGeometryCollection)igeometry0; IArray arrayClass = new ESRI.ArcGIS.esriSystem.Array(); try { bool zAware = false; bool mAware = false; double zMin = 0; try { zAware = (igeometry_0 as IZAware).ZAware; zMin = (igeometry_0 as IZ).ZMin; } catch { } try { mAware = (igeometry_0 as IMAware).MAware; } catch { } for (int i = 0; i < geometryCollection.GeometryCount; i++) { IGeometry geometry1 = geometryCollection.Geometry[i]; IGeometryCollection polylineClass = new Polyline() as IGeometryCollection; (polylineClass as IZAware).ZAware = zAware; (polylineClass as IMAware).MAware = mAware; polylineClass.AddGeometries(1, ref geometry1); if (zAware) { (polylineClass as IZ).SetConstantZ(zMin); } (polylineClass as ITopologicalOperator).Simplify(); arrayClass.Add(polylineClass); } } catch (Exception exception) { Trace.WriteLine(exception); } array = arrayClass; } else { array = null; } } else { array = null; } } else { array = null; } } else { array = null; } return(array); }
public override void OnMouseDown(int int_0, int int_1, int int_2, int int_3) { IFeature feature; int i; IPoint point; if (int_0 == 1) { IActiveView focusMap = (IActiveView)_context.FocusMap; IPoint anchorPoint = SketchToolAssist.AnchorPoint; double mapUnits = Common.ConvertPixelsToMapUnits(_context.FocusMap as IActiveView, _context.Config.EngineSnapEnvironment.SnapTolerance); Yutai.ArcGIS.Common.Editor.Editor.GetClosesFeature(_context.FocusMap, anchorPoint, mapUnits, esriGeometryType.esriGeometryPolyline, out feature); if (feature == null) { MessageService.Current.Warn("没有点击的要素上,请设置较大的捕捉范围!"); } else { IPolycurve2 shape = feature.Shape as IPolycurve2; IEnvelope envelope = shape.Envelope; object value = Missing.Value; IHitTest hitTest = shape as IHitTest; IPoint pointClass = new Point(); double num = 0; int num1 = -1; int num2 = -1; bool flag = false; if (hitTest.HitTest(anchorPoint, mapUnits, esriGeometryHitPartType.esriGeometryPartBoundary, pointClass, ref num, ref num1, ref num2, ref flag)) { Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation(); IGeometryCollection polylineClass = new Polyline() as IGeometryCollection; for (i = 0; i < num1; i++) { polylineClass.AddGeometry((shape as IGeometryCollection).Geometry[i], ref value, ref value); } IPointCollection geometry = (shape as IGeometryCollection).Geometry[num1] as IPointCollection; IPointCollection pathClass = new ESRI.ArcGIS.Geometry.Path(); for (i = 0; i < num2 + 1; i++) { point = (geometry.Point[i] as IClone).Clone() as IPoint; pathClass.AddPoint(point, ref value, ref value); } pathClass.AddPoint((pointClass as IClone).Clone() as IPoint, ref value, ref value); polylineClass.AddGeometry(pathClass as IGeometry, ref value, ref value); if ((polylineClass as IPointCollection).PointCount > 1) { Yutai.ArcGIS.Common.Editor.Editor.SetGeometryZM(polylineClass as IGeometry, shape); feature.Shape = polylineClass as IGeometry; feature.Store(); } pathClass = new ESRI.ArcGIS.Geometry.Path(); pathClass.AddPoint((pointClass as IClone).Clone() as IPoint, ref value, ref value); for (i = num2 + 1; i < geometry.PointCount; i++) { point = (geometry.Point[i] as IClone).Clone() as IPoint; pathClass.AddPoint(point, ref value, ref value); } polylineClass = new Polyline() as IGeometryCollection; polylineClass.AddGeometry(pathClass as IGeometry, ref value, ref value); for (i = num1 + 1; i < (shape as IGeometryCollection).GeometryCount; i++) { polylineClass.AddGeometry((shape as IGeometryCollection).Geometry[i], ref value, ref value); } if ((polylineClass as IPointCollection).PointCount > 1) { IFeature feature1 = RowOperator.CreatRowByRow(feature as Row) as IFeature; Yutai.ArcGIS.Common.Editor.Editor.SetGeometryZM(polylineClass as IGeometry, shape); feature1.Shape = polylineClass as IGeometry; feature1.Store(); } Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation(); (_context.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, null, envelope); (_context.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } } } }