public override void OnMouseMove(int Button, int shift, int X, int Y) { //Determine tangent to last segment on edit sketch //Set as angle constraint +90 ISegmentCollection pSc = m_EdSketch.Geometry as ISegmentCollection; if (pSc.SegmentCount > 0) { ICurve3 pCurve; if (m_EdSketch.GeometryType == esriGeometryType.esriGeometryPolygon) { pCurve = pSc.get_Segment(pSc.SegmentCount - 2) as ICurve3; } else { pCurve = pSc.get_Segment(pSc.SegmentCount - 1) as ICurve3; } ILine pLine = new Line(); pCurve.QueryTangent(esriSegmentExtension.esriExtendTangentAtTo, 1, true, 10, pLine); base.AngleConstraint = pLine.Angle + (90 * Math.PI / 180); base.Constraint = esriSketchConstraint.esriConstraintAngle; } base.OnMouseMove(Button, shift, X, Y); }
//根据线的方向获取其更新的位置 private void GetFromPointMovepointChangeLocation(IPolyline line, double distance, ref IPoint point, ref IPolyline retureline) { try { IPolyline[] pLines = new IPolyline[2]; IPolyline pSplitLine = new PolylineClass(); pSplitLine = line; IPolyline StarttoPointLine = new PolylineClass(); IPolyline EndtoPointLine = new PolylineClass(); bool splithappened; int partindex, segmentindex; object pObject = Type.Missing; pSplitLine.SplitAtDistance(distance, false, false, out splithappened, out partindex, out segmentindex); ISegmentCollection lineSegCol = pSplitLine as ISegmentCollection; ISegmentCollection startSegCol = StarttoPointLine as ISegmentCollection; ISegmentCollection endSegCol = EndtoPointLine as ISegmentCollection; for (int i = 0; i < segmentindex; i++) { startSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject); } for (int j = segmentindex; j < lineSegCol.SegmentCount; j++) { endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject); } pLines[0] = endSegCol as IPolyline; pLines[1] = startSegCol as IPolyline; point = new PointClass(); point = pLines[0].FromPoint; retureline = pLines[0]; } catch (Exception ex) { MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常"); } }
//根据第一应急处置空间位置点,将即将污染的河流切割成两段 public IPolyline GetPointSplitAtPoint(IPolyline InputLine, IPoint point) { try { IPolyline[] pLines = new IPolyline[2]; IPolyline pSplitLine = new PolylineClass(); pSplitLine = InputLine; IPolyline StarttoPointLine = new PolylineClass(); IPolyline EndtoPointLine = new PolylineClass(); bool projectOnto = true, createPart = false; bool SplitHappened; int partindex, segmentindex; object pObject = Type.Missing; pSplitLine.SplitAtPoint(point, projectOnto, createPart, out SplitHappened, out partindex, out segmentindex); ISegmentCollection lineSegCol = pSplitLine as ISegmentCollection; ISegmentCollection startSegCol = StarttoPointLine as ISegmentCollection; ISegmentCollection endSegCol = EndtoPointLine as ISegmentCollection; for (int i = 0; i < segmentindex; i++) { startSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject); } for (int j = segmentindex; j < lineSegCol.SegmentCount; j++) { endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject); } pLines[0] = endSegCol as IPolyline; pLines[1] = startSegCol as IPolyline; return(pLines[0]); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); return(null); } }
private esriFlowDirection method_7(IGeometry geometry) { ISegmentCollection segmentCollection = (ISegmentCollection)geometry; ISegmentZ segmentZ = (ISegmentZ)segmentCollection.get_Segment(0); ISegmentZ segmentZ2 = (ISegmentZ)segmentCollection.get_Segment(-1); double num; double num2; segmentZ.GetZs(out num, out num2); double num3; segmentZ2.GetZs(out num2, out num3); esriFlowDirection result; if (num > num3) { result = (esriFlowDirection)1; } else if (num < num3) { result = (esriFlowDirection)2; } else { result = (esriFlowDirection)3; } return(result); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button != 1 || m_pFeature == null || m_pVertexFeed == null || m_HitSegmentIndex == -1) { return; } IPoint pPnt = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //如果开启捕捉则以捕捉到的点为准 if (MoData.v_bSnapStart && m_pSnapPoint != null) { pPnt = m_pSnapPoint; } ISegmentCollection pSegmentCollection = m_pFeature.Shape as ISegmentCollection; //检查是否点击第一点 if (m_HitSegmentIndex == 0) { //如果是第一点且是Polygon,更新最后一段 if (m_pFeature.Shape is IPolygon) { pPnt.Z = pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1).ToPoint.Z; pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1).ToPoint = pPnt; } } else { //如果不是第一点,更新上一段(FromPoint as anchor) pPnt.Z = pSegmentCollection.get_Segment(m_HitSegmentIndex - 1).ToPoint.Z; pSegmentCollection.get_Segment(m_HitSegmentIndex - 1).ToPoint = pPnt; } //检查是否点击最后一个节点 if (m_HitSegmentIndex == pSegmentCollection.SegmentCount) { //如果是点击最后一个节点,并且是polygon,更新第一段 if (m_pFeature.Shape is IPolygon) { pPnt.Z = pSegmentCollection.get_Segment(0).FromPoint.Z; pSegmentCollection.get_Segment(0).FromPoint = pPnt; } } else { //如果不是最后一个节点,更新下一段(ToPoint as anchor) pPnt.Z = pSegmentCollection.get_Segment(m_HitSegmentIndex).FromPoint.Z; pSegmentCollection.get_Segment(m_HitSegmentIndex).FromPoint = pPnt; } StoreFeature(m_pFeature, pSegmentCollection, MoData.v_CurWorkspaceEdit); m_MapControl.ActiveView.Refresh(); m_pVertexFeed = null; m_bMouseDown = false; m_HitSegmentIndex = 0; }
private IPolygon polylinetoPolygon(IPolyline pPolyline) { IPointCollection pPtC; ESRI.ArcGIS.Geometry.IPoint pPt0, pPtn; ESRI.ArcGIS.Geometry.ILine pSeg = new LineClass(); IPolygon polygon = new PolygonClass(); ISegmentCollection segmentCollection = (ISegmentCollection)pPolyline; int segmentCount = segmentCollection.SegmentCount; ISegmentCollection segmentCollection2 = (ISegmentCollection)polygon; object value = Missing.Value; object value2 = Missing.Value; for (int i = 0; i < segmentCount; i++) { segmentCollection2.AddSegment(segmentCollection.get_Segment(i), ref value, ref value2); } if (!pPolyline.IsClosed) { pPtC = pPolyline as IPointCollection; pPt0 = pPtC.get_Point(0); polygon.ToPoint = pPt0; //pPtn = pPtC.get_Point(pPtC.PointCount - 1); //pSeg.PutCoords(pPtn, pPt0); //segmentCollection2.AddSegment((ISegment)pSeg, ref value, ref value2); } polygon.SimplifyPreserveFromTo(); return(polygon); }
public static GeoAPI.Geometries.ILinearRing ConvertTo(ESRI.ArcGIS.Geometry.IRing ring) { ESRI.ArcGIS.Geometry.IPoint fromToPoint = ring.FromPoint; List <GeoAPI.Geometries.ICoordinate> list = new List <GeoAPI.Geometries.ICoordinate>(); list.Add(ConvertTo(fromToPoint)); ISegmentCollection segmentCollection = ring as ISegmentCollection; if (segmentCollection != null) { int count = segmentCollection.SegmentCount; for (int i = 0; i < count; i++) { ISegment segment = segmentCollection.get_Segment(i); if (!(segment is ILine)) { throw new ApplicationException("Curves are not supported."); } list.Add(ConvertTo(segment.ToPoint)); } } else { throw new ApplicationException("No segments found in the ring geometry."); } list.Add(ConvertTo(fromToPoint)); list.Reverse(); return(new GisSharpBlog.NetTopologySuite.Geometries.LinearRing(list.ToArray())); }
/// <summary> /// 角度同步,点与线的角度同步 /// </summary> /// <param name="pPolyline">线</param> /// <param name="pPoint">线附近的点(许可的范围内)</param> /// <param name="dAngle">返回点符号的角度</param> /// <param name="pRetPoint">返回的在线上的点的位置</param> /// <returns>是否可以同步角度(如果距离过大,无法执行角度同步)</returns> public static bool SynchronizeAngle(IPolyline pPolyline, IPoint pPoint, ref double dAngle, ref IPoint pRetPoint) { double dRadius = 10; IPoint pHitPoint = new PointClass(); IHitTest pHitTest = pPolyline as IHitTest; double hitDist = 0.0; int hitPartIndex = 0; int hitSegmentIndex = 0; bool bRightSide = false; bool bPointOnLine = pHitTest.HitTest(pPoint, dRadius, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPoint, ref hitDist, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide); if (bPointOnLine) { if (distance(pHitPoint, pPoint) < 0.0001) { pRetPoint = null; } else { pRetPoint = pHitPoint; } ISegmentCollection pSegment = pPolyline as ISegmentCollection; ILine pLine = pSegment.get_Segment(hitSegmentIndex) as ILine; dAngle = pLine.Angle; return(true); } return(false); }
/// <summary>Gets the end point of a turn edge</summary> /// <remarks> /// - The Via node of a turn is assumed to be at the From or To point of the edge /// </remarks> private static IPoint GetTurnEndpoint(IPolyline line, IPoint ptVia, out bool edgeEndAtToPoint, out double position) { IPoint point = null; edgeEndAtToPoint = false; position = 0.0; if ((ptVia.X == line.FromPoint.X) && (ptVia.Y == line.FromPoint.Y)) { point = ((IPointCollection)line).get_Point(1); ISegment segment = ((ISegmentCollection)line).get_Segment(0); position = segment.Length / line.Length; } else { edgeEndAtToPoint = true; IPointCollection pc = (IPointCollection)line; point = pc.get_Point(pc.PointCount - 2); ISegmentCollection sc = line as ISegmentCollection; ISegment segment = sc.get_Segment(sc.SegmentCount - 1); position = (line.Length - segment.Length) / line.Length; } return(point); }
/// <summary> /// 获取线起点 /// </summary> /// <param name="pLine"></param> /// <returns></returns> public static IPoint GetStartPoint(IPolyline pLine) { IPoint pStartPoint = null; try { if (pLine == null) { return(pStartPoint); } ISegmentCollection pLines = pLine as ISegmentCollection; if (pLines.SegmentCount == 0) { return(pStartPoint); } ILine pStarLine = pLines.get_Segment(0) as ILine; if (pStarLine == null) { return(pStartPoint); } pStartPoint = pStarLine.FromPoint; return(pStartPoint); } catch (Exception ex) { return(pStartPoint); } }
private double GetAngle(ICurve curvePath) { IPolyline pPoly = (IPolyline)curvePath; ISegmentCollection pSG = pPoly as ISegmentCollection; ILine pLine = pSG.get_Segment(0) as ILine; return(Math.Round((180 * pLine.Angle) / Math.PI, 3)); }
public override void OnClick() { if (SketchShareEx.m_pAnchorPoint != null) { IPoint point = new Point(); point.PutCoords(SketchShareEx.m_pAnchorPoint.X, SketchShareEx.m_pAnchorPoint.Y); point.SpatialReference = _context.FocusMap.SpatialReference; double snapTolerance = _context.Config.EngineSnapEnvironment.SnapTolerance; IFeature feature; Yutai.ArcGIS.Common.Editor.Editor.GetClosesFeature(_context.FocusMap, point, snapTolerance, out feature); if (feature != null) { IGeometry shapeCopy = feature.ShapeCopy; double num = 0.0; int index = 0; int i = 0; bool flag = false; IPoint point2 = new Point(); point2.PutCoords(0.0, 0.0); if (shapeCopy.GeometryType == esriGeometryType.esriGeometryPolygon || shapeCopy.GeometryType == esriGeometryType.esriGeometryPolyline) { if ((shapeCopy as IHitTest).HitTest(point, 4.0, esriGeometryHitPartType.esriGeometryPartBoundary, point2, ref num, ref index, ref i, ref flag)) { ISegmentCollection segmentCollection = (shapeCopy as IGeometryCollection).get_Geometry(index) as ISegmentCollection; ISegment segment = segmentCollection.get_Segment(i); ILine line = new Line(); line.SpatialReference = _context.FocusMap.SpatialReference; line.PutCoords(point2, segment.FromPoint); double length = line.Length; line.PutCoords(point2, segment.ToPoint); double length2 = line.Length; if (length < length2) { SketchShareEx.m_pAnchorPoint.PutCoords(segment.FromPoint.X, segment.FromPoint.Y); } else { SketchShareEx.m_pAnchorPoint.PutCoords(segment.ToPoint.X, segment.ToPoint.Y); } SketchShareEx.SketchMouseDown(SketchShareEx.m_pAnchorPoint, _context.ActiveView, Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer); } } else if ((shapeCopy.GeometryType == esriGeometryType.esriGeometryMultipoint || shapeCopy.GeometryType == esriGeometryType.esriGeometryPoint) && (shapeCopy as IHitTest).HitTest(point, 4.0, esriGeometryHitPartType.esriGeometryPartVertex, point2, ref num, ref index, ref i, ref flag)) { SketchShareEx.m_pAnchorPoint.PutCoords(point2.X, point2.Y); SketchShareEx.SketchMouseDown(SketchShareEx.m_pAnchorPoint, _context.ActiveView, Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer); } } } }
/// <summary> /// 算出量测计算结果,并在FormDis上进行显示 /// </summary> /// <param name="ipGeo">人机交互生成的实体</param> public void WriteLabelText(IGeometry ipGeo) { switch (m_MeasureType) { case MeasureType.Length: //量测长度 { string strUnit = " " + (this.m_Tool as ToolMeasureLength).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4); //this.m_LabelMeasureType.Text = "Line Measurement"; this.m_LabelMeasureType.Text = "长度量测"; this.m_labelArea.Visible = true; if (ipGeo != null) { IGeometryCollection ipGeoCol = ipGeo as IGeometryCollection; ISegmentCollection ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection; ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine; //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit; //this.m_labelLength.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString() + "米"; this.m_labelArea.Text = "长度:" + (ipGeoCol.get_Geometry(0) as ICurve).Length.ToString("f3") + "米"; } else { this.m_labelArea.Text = "长度:" + "0" + "米"; //this.m_labelLength.Text = "总长度:" + "0" + strUnit; } } break; case MeasureType.Area: //量测面积 { string strUnit = " " + (this.m_Tool as ToolMeasureArea).m_hookHelper.FocusMap.MapUnits.ToString().Substring(4); //this.m_LabelMeasureType.Text = "Area Measurement"; this.m_LabelMeasureType.Text = "面积量测"; this.m_labelArea.Visible = true; if (ipGeo != null) { IGeometryCollection ipGeoCol = ipGeo as IGeometryCollection; ISegmentCollection ipSegmentColl = ipGeoCol.get_Geometry(0) as ISegmentCollection; ILine ipLine = ipSegmentColl.get_Segment(ipSegmentColl.SegmentCount - 1) as ILine; //this.m_labelSegment.Text = "Segment:" + ipLine.Length.ToString() + strUnit; //this.m_labelLength.Text = "Perimeter:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit; //this.m_labelSegment.Text = "段长度:" + ipLine.Length.ToString() + strUnit; //this.m_labelLength.Text = "周长:" + (ipGeoCol.get_Geometry(0) as IRing).Length.ToString() + strUnit; IClone ipClone = ipGeo as IClone; IGeometry ipGeo1 = ipClone.Clone() as IGeometry; ITopologicalOperator ipTopo = ipGeo1 as ITopologicalOperator; ipTopo.Simplify(); this.m_labelArea.Text = "面积:" + ((ipGeo1 as IPolygon) as IArea).Area.ToString(".###") + "平方米"; } else { this.m_labelArea.Text = "面积:" + "0" + "平方米"; } } break; } }
private static bool IsAngle180(IPolyline pPolyLine, ISegment pSegment) { IRelationalOperator pRelOperator; ISegmentCollection pSegC = pPolyLine as ISegmentCollection; ISegment pSeg, pSegStart, pSegEnd; pSegStart = pSegC.get_Segment(0); pSegEnd = pSegC.get_Segment(pSegC.SegmentCount - 1); ISegmentCollection pPolyStart = new PolylineClass(); ISegmentCollection pPolyEnd = new PolylineClass(); ISegmentCollection pPolyL = new PolylineClass(); object missing = Type.Missing; pPolyL.AddSegment(pSegment, ref missing, ref missing); pPolyStart.AddSegment(pSegStart, ref missing, ref missing); pPolyEnd.AddSegment(pSegEnd, ref missing, ref missing); pRelOperator = pPolyL as IRelationalOperator; if (pRelOperator.Touches(pPolyEnd as IGeometry)) { pSeg = pSegEnd; } else if (pRelOperator.Touches(pPolyStart as IGeometry)) { pSeg = pSegStart; } else { return(false); } double k1, k2, k; k1 = Math.Abs((pSeg.FromPoint.Y - pSeg.ToPoint.Y) / (pSeg.FromPoint.X - pSeg.ToPoint.X)); k2 = Math.Abs((pSegment.FromPoint.Y - pSegment.ToPoint.Y) / (pSegment.FromPoint.X - pSegment.ToPoint.X)); k = k1 / k2; if (k > 0.8 && k < 1.2) { return(true); } else { return(false); } }
/// <summary> /// 将构面的环分解成线段集合 /// </summary> /// <param name="pRing">构面的环对象IRing</param> /// <param name="strFeatureCode">线的要素代码</param> /// <param name="strRepresentation">图形表现编码</param> /// <param name="nEntityID">面实体索引</param> /// <returns>VCT线段对象集合</returns> private List<LineNodeEx> GetLineByRing(IRing pRing,string strFeatureCode,string strRepresentation,int nEntityID) { try { List<LineNodeEx> pListLine = new List<LineNodeEx>(); ///获取每个环中的线段集合 ISegmentCollection pExRingSegmentCollection = pRing as ISegmentCollection; ///处理集合中的各个线段 for (int i = 0; i < pExRingSegmentCollection.SegmentCount; i++) { ISegment pSegment = pExRingSegmentCollection.get_Segment(i); LineNodeEx pLineNodeEx = new LineNodeEx();//构造VCT线段对象 pLineNodeEx.SegmentNodes = new SegmentNodes();//构造线段对应的点集合 //pLineNodeEx.IsReverse = bReverse;//设置方向 pLineNodeEx.FeatureCode = strFeatureCode;//设置要素代码 pLineNodeEx.Representation = strRepresentation; pLineNodeEx.PolygonID = nEntityID;///所属面的标识码 BrokenLineNode pBrokenLinNode = new BrokenLineNode();//构造折线 pBrokenLinNode.PointInfoNodes = new PointInfoNodes(); ILine pLine = pSegment as ILine; if (pLine != null) { pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pLine.FromPoint.X, pLine.FromPoint.Y)); pBrokenLinNode.PointInfoNodes.Add(new PointInfoNode(pLine.ToPoint.X, pLine.ToPoint.Y)); } //////如果是反向 ////if (bReverse) ////{ //// PointInfoNodes tempPointInfoNodes = new PointInfoNodes(); //// foreach (PointInfoNode item in pBrokenLinNode.PointInfoNodes) //// { //// tempPointInfoNodes.Add(item); //// } //// pBrokenLinNode.PointInfoNodes = tempPointInfoNodes; ////} pLineNodeEx.SegmentNodes.Add(pBrokenLinNode); pListLine.Add(pLineNodeEx); } return pListLine; } catch(Exception ex) { LogAPI.WriteErrorLog(ex); return null; } }
private static IEnumerable <ISegment> GetSegments( [NotNull] ISegmentCollection segments) { int segmentCount = segments.SegmentCount; for (int i = 0; i < segmentCount; i++) { yield return(segments.get_Segment(i)); } }
private static IGeometry ProcessPoXian(IGeometry Merge) { IPolyline pPolyLine1 = new PolylineClass(); ISegmentCollection pPolyLine2 = new PolylineClass(); ISegment pSegment; ISegmentCollection segmentCollection = Merge as ISegmentCollection; IGeometryCollection pPolyLine = new PolylineClass(); IRelationalOperator pRelOperator; object missing = Type.Missing; string mergedID = ","; for (int i = 0; i < segmentCollection.SegmentCount; i++) { if (mergedID.IndexOf("," + i.ToString() + ",") >= 0) { continue; } pPolyLine1 = new PolylineClass(); (pPolyLine1 as ISegmentCollection).AddSegment(segmentCollection.get_Segment(i), ref missing, ref missing); pRelOperator = pPolyLine1 as IRelationalOperator; for (int j = i + 1; j < segmentCollection.SegmentCount; j++) { if (mergedID.IndexOf("," + j.ToString() + ",") < 0) { pSegment = segmentCollection.get_Segment(j); pPolyLine2.AddSegment(pSegment, ref missing, ref missing); if (pRelOperator.Touches(pPolyLine2 as IGeometry) && IsAngle180(pPolyLine1, pSegment)) { (pPolyLine1 as ISegmentCollection).AddSegment(pSegment, ref missing, ref missing); mergedID = mergedID + j.ToString() + ","; } } } (pPolyLine1 as ITopologicalOperator).Simplify(); (pPolyLine1 as IPolycurve).Generalize(0.02); pPolyLine.AddGeometryCollection(pPolyLine1 as IGeometryCollection); } return(pPolyLine as IGeometry); }
/// <summary> /// 获取Polyline之间的夹角(角度) /// </summary> /// <param name="id1">Base Polyline的OID</param> /// <param name="id2">待比较Polyline的OID</param> /// <param name="featureClass">要素类</param> private double GetPolylineAngle(int id1, int id2, IFeatureClass featureClass) { Posi IItoI = GetRel(id1, id2, featureClass); Posi ItoII = GetRel(id2, id1, featureClass); double[] v1 = null; double[] v2 = null; ISegmentCollection sc1 = featureClass.GetFeature(id1).ShapeCopy as ISegmentCollection; ISegmentCollection sc2 = featureClass.GetFeature(id2).ShapeCopy as ISegmentCollection; if (IItoI == Posi.FROM) { ISegment seg = sc1.get_Segment(0); v1 = new double[2] { seg.ToPoint.X - seg.FromPoint.X, seg.ToPoint.Y - seg.FromPoint.Y }; } else { ISegment seg = sc1.get_Segment(sc1.SegmentCount - 1); v1 = new double[2] { seg.FromPoint.X - seg.ToPoint.X, seg.FromPoint.Y - seg.ToPoint.Y }; } if (ItoII == Posi.FROM) { ISegment seg = sc2.get_Segment(0); v2 = new double[2] { seg.ToPoint.X - seg.FromPoint.X, seg.ToPoint.Y - seg.FromPoint.Y }; } else { ISegment seg = sc2.get_Segment(sc2.SegmentCount - 1); v2 = new double[2] { seg.FromPoint.X - seg.ToPoint.X, seg.FromPoint.Y - seg.ToPoint.Y }; } return(getVetorAngle(v1, v2)); }
private void OnSketchFinished() { //Use the geometry from the sketch and make a narrow buffer to search for fabric lines contained within the buffer IBufferConstruction pBuffConst = new BufferConstruction(); IGeometry pGeom = pBuffConst.Buffer(m_edSketch.Geometry, 0.1); ISpatialFilter pSpatFilter = new SpatialFilter(); pSpatFilter.Geometry = pGeom; pSpatFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; //set up for reporting information about the lines string sReportString = ""; int iTotalLineCount = 0; int iCurveCount = 0; int iMultiSegmentCount = 0; //Create a feature cursor to query the fabric lines table IFeatureCursor pFeatCurs = m_pFabricLines.Search(pSpatFilter, false); IFeature pFeat = pFeatCurs.NextFeature(); while (pFeat != null) { //loop through the found lines //count all the lines iTotalLineCount++; ISegmentCollection pSegColl = (ISegmentCollection)pFeat.Shape; if (pSegColl.SegmentCount > 1) //count lines that have more than 1 segment { iMultiSegmentCount++; } else { if (pSegColl.get_Segment(0) is ICircularArc) { iCurveCount++; //count lines that have a single circular arc geometry segment } } Marshal.ReleaseComObject(pFeat); pFeat = pFeatCurs.NextFeature(); } Marshal.ReleaseComObject(pFeatCurs); //report the results sReportString += "\nTotal parcel lines: " + iTotalLineCount.ToString(); sReportString += "\nCurve parcel lines: " + iCurveCount.ToString(); sReportString += "\nMulti segment parcel lines: " + iMultiSegmentCount.ToString(); MessageBox.Show(sReportString, "Sample: Trace Report"); }
private static IPolyline SegmentCollectionToPolyline(ISegmentCollection segmentCollection) { var polyline = (IPolyline) new PolylineClass(); var geomcoll = (IGeometryCollection)polyline; var pathcoll = (ISegmentCollection) new PathClass(); for (int i = 0; i < segmentCollection.SegmentCount; i++) { var segment = segmentCollection.get_Segment(i); pathcoll.AddSegment(segment); } geomcoll.AddGeometry((IGeometry)pathcoll); geomcoll.GeometriesChanged(); return(polyline); }
//根据距离切割线段,获取切割的点和切割后尾段 public void GetPointSplitAtDistance(IPolyline InputLine, double distance, ref IPolyline retureLine, ref IPoint returePoint) { try { IPolyline[] pLines = new IPolyline[2]; IPolyline pSplitLine = new PolylineClass(); pSplitLine = InputLine; IPolyline StarttoPointLine = new PolylineClass(); IPolyline EndtoPointLine = new PolylineClass(); bool splithappened; int partindex, segmentindex; object pObject = Type.Missing; pSplitLine.SplitAtDistance(distance, false, false, out splithappened, out partindex, out segmentindex); ISegmentCollection lineSegCol = pSplitLine as ISegmentCollection; ISegmentCollection startSegCol = StarttoPointLine as ISegmentCollection; ISegmentCollection endSegCol = EndtoPointLine as ISegmentCollection; for (int i = 0; i < segmentindex; i++) { startSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject); } for (int j = segmentindex; j < lineSegCol.SegmentCount; j++) { endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject); } pLines[0] = endSegCol as IPolyline; pLines[1] = startSegCol as IPolyline; returePoint = new PointClass(); bool asRatio = false; pLines[1].QueryPoint(esriSegmentExtension.esriNoExtension, pLines[1].Length / 2, asRatio, returePoint); retureLine = pLines[0]; } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }
//获取将输入点最近点,该线段分割成两段 public static IPolyline[] GetSubLine(IPoint point, IFeature pFeature) { try { IPolyline pLine = pFeature.Shape as IPolyline; IPolyline[] pLines = new IPolyline[2]; IPolyline StarttoPointLine = new PolylineClass(); IPolyline EndtoPointLine = new PolylineClass(); bool splithappened; int partindex, segmentindex; object pObject = Type.Missing; //IPoint IPoint = GetNearestPoint(point); pLine.SplitAtPoint(point, false, false, out splithappened, out partindex, out segmentindex); ISegmentCollection lineSegCol = (ISegmentCollection)pLine; ISegmentCollection newSegCol = (ISegmentCollection)StarttoPointLine; ISegmentCollection endSegCol = EndtoPointLine as ISegmentCollection; for (int i = 0; i < segmentindex; i++) { newSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject); } for (int j = segmentindex; j < lineSegCol.SegmentCount; j++) { endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject); } lineSegCol.RemoveSegments(0, segmentindex, true); pLines[0] = newSegCol as IPolyline; pLines[1] = endSegCol as IPolyline; return(pLines); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常"); return(null); } }
public ISegment GetSegment() { ISegment result; if (this.VertIndex == -1) { result = null; } else { IGeometryCollection geometryCollection = this.Feature.Shape as IGeometryCollection; ISegmentCollection segmentCollection = geometryCollection.get_Geometry(this.PartIndex) as ISegmentCollection; result = segmentCollection.get_Segment(this.VertIndex); } return(result); }
//中点捕捉 private static void GetMidPntCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IProximityOperator pProximity, double dSearchDist) { IPointCollection pPntColTemp = new MultipointClass(); for (int i = 0; i < listFeats.Count; i++) { IFeature pFeature = listFeats[i]; //判断该Feature图层 if (pFeature.Class.ObjectClassID != pFeatureClass.ObjectClassID) { continue; } if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline || pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { double dScreenSearchDist = pProximity.ReturnDistance(pFeature.Shape); if (dScreenSearchDist < 1.5 * dSearchDist) { IGeometryCollection pGeoCollection = pFeature.Shape as IGeometryCollection; for (int j = 0; j < pGeoCollection.GeometryCount; j++) { IGeometry pGeom = pGeoCollection.get_Geometry(j); ISegmentCollection pSegColl = pGeom as ISegmentCollection; for (int k = 0; k < pSegColl.SegmentCount; k++) { ISegment pSeg = pSegColl.get_Segment(k); IPoint pMidPoint = new PointClass(); double x = (pSeg.FromPoint.X + pSeg.ToPoint.X) / 2; double y = (pSeg.FromPoint.Y + pSeg.ToPoint.Y) / 2; pMidPoint.PutCoords(x, y); object befor = Type.Missing; object after = Type.Missing; m_PointCollection.AddPoint(pMidPoint, ref befor, ref after); pPntColTemp.AddPoint(pMidPoint, ref befor, ref after); } } } } } m_dicPointCollection.Add(pPntColTemp, "MidPnt"); }
private static void HitTest(IFeature ifeature_0, IPoint ipoint_0) { IGeometry shapeCopy = ifeature_0.ShapeCopy; IPoint point = new ESRI.ArcGIS.Geometry.Point(); double num = 0.0; int index = 0; int num2 = 0; bool flag = false; if ( (!(shapeCopy as IHitTest).HitTest(ipoint_0, 0.0001, esriGeometryHitPartType.esriGeometryPartVertex, point, ref num, ref index, ref num2, ref flag) || num >= 0.0001) && (shapeCopy as IHitTest).HitTest(ipoint_0, 0.0001, esriGeometryHitPartType.esriGeometryPartBoundary, point, ref num, ref index, ref num2, ref flag) && num < 0.0001) { ISegmentCollection segmentCollection = (shapeCopy as IGeometryCollection).get_Geometry(index) as ISegmentCollection; ISegment segment = segmentCollection.get_Segment(num2); if (segment is ILine) { ILine line = new Line(); line.PutCoords((segment as ILine).FromPoint, point); ILine line2 = new Line(); line2.PutCoords(point, (segment as ILine).ToPoint); ISegmentCollection segmentCollection2 = new Polyline() as ISegmentCollection; object value = System.Reflection.Missing.Value; object value2 = System.Reflection.Missing.Value; segmentCollection2.AddSegment(line as ISegment, ref value, ref value2); segmentCollection.ReplaceSegmentCollection(num2, 1, segmentCollection2); segmentCollection2 = new Polyline() as ISegmentCollection; object value3 = System.Reflection.Missing.Value; object value4 = System.Reflection.Missing.Value; segmentCollection2.AddSegment(line2 as ISegment, ref value3, ref value4); segmentCollection.InsertSegmentCollection(num2 + 1, segmentCollection2); segmentCollection.SegmentsChanged(); (shapeCopy as IGeometryCollection).GeometriesChanged(); ifeature_0.Shape = shapeCopy; ifeature_0.Store(); } } }
public override void OnMouseMove(int int_2, int int_3, int int_4, int int_5) { IPoint anchorPoint = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(int_4, int_5); this.snapHelper_0.AnchorPoint = anchorPoint; IActiveView arg_3A_0 = _context.FocusMap as IActiveView; this.snapHelper_0.Snap2Point(anchorPoint, this.snapHelper_0.AnchorPoint, esriSimpleMarkerStyle.esriSMSDiamond); if (this.bool_5) { this.bool_1 = true; if (this.bool_2) { this.int_0++; if (this.int_0 >= 2) { this.int_0 = 0; this.ipoint_0 = _context.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(int_4, int_5); this.method_4(); if (!this.isegmentGraphCursor_0.MoveTo(this.ipoint_0)) { this.isegmentGraphCursor_0.FinishMoveTo(this.ipoint_0); } this.ipolyline_0 = this.isegmentGraphCursor_0.CurrentTrace; object value = Missing.Value; object obj = this.int_1; this.iconstructCurve_0.ConstructOffset(this.ipolyline_0, this.double_0, ref obj, ref value); ISegmentCollection segmentCollection = this.iconstructCurve_0 as ISegmentCollection; if (this.isegmentCollection_0 != null && this.isegmentCollection_0.SegmentCount != 0) { this.iline_0.PutCoords(this.ipoint_1, segmentCollection.get_Segment(0).FromPoint); ISegment segment = this.iline_0 as ISegment; segmentCollection.InsertSegments(0, 1, ref segment); } this.method_4(); } } } }
/// <summary> /// 面转线 /// </summary> /// <params name="pPolyline"></params> /// <returns></returns> public static List <ILine> PolygonToListline(IPolygon Polygon) { List <ILine> listline = new List <ILine>(); if (Polygon != null && Polygon.IsEmpty == false) { IGeometryCollection pPolygonGeoCol = Polygon as IGeometryCollection; ISegment pSegment = null; ILine pline = new LineClass(); for (int i = 0; i < pPolygonGeoCol.GeometryCount; i++) { ISegmentCollection pPolygonSegCol = pPolygonGeoCol.get_Geometry(i) as ISegmentCollection; for (int j = 0; j < pPolygonSegCol.SegmentCount; j++) { pSegment = pPolygonSegCol.get_Segment(j); pline = pSegment as ILine; listline.Add(pline); } } } return(listline); }
public ISegmentCollection Modify1Segment(IGeometryCollection polyline, Double searchRadius, Double offsetX, Double offsetY) { IPoint queryPoint = m_activePoint; IPoint hitPoint = new PointClass(); double hitDistance = 0; int hitPartIndex = 0; int hitSegmentIndex = 0; bool rightSide = false; IHitTest hitTest = (IHitTest)polyline; bool foundGeometry = hitTest.HitTest(queryPoint, searchRadius, esriGeometryHitPartType.esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide); if (foundGeometry == true) { IGeometry geometry = polyline.get_Geometry(hitPartIndex); ISegmentCollection segmentCollection = (ISegmentCollection)geometry; ISegment segment = segmentCollection.get_Segment(hitSegmentIndex); ITransform2D transform2D = (ITransform2D)segment; transform2D.Move(offsetX, offsetY); segmentCollection.SegmentsChanged(); return(segmentCollection); } return(null); }
private void button2_Click(object sender, EventArgs e) { IFeatureLayer layer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass pFeatCla = layer.FeatureClass; IFeature pFeature = pFeatCla.GetFeature(0); IGeometry pGeometry = pFeature.Shape; IPolyline pPoly = pGeometry as IPolyline; ISegmentCollection pSegCol = pGeometry as ISegmentCollection; ILine pLine = pSegCol.get_Segment(0) as ILine; IPoint inPoint = new Point(); //已知点 inPoint.X = pPoly.FromPoint.X + 5; inPoint.Y = pPoly.FromPoint.Y + 2; IPoint outPoint = new PointClass(); //曲线上到输入点距离最小的点; double distAlongCurveFrom = 0; //曲线其实点到输出点部分的长度 double distFromCurve = 0; //输出点到输入点的距离 bool isRightSide = true; //输入点是否在曲线的右边 pPoly.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, inPoint, false, outPoint, ref distAlongCurveFrom, ref distFromCurve, ref isRightSide); double lineHeading = pLine.Angle * 180 / PI; //因为当前角度是以四象限X为起点的逆时针角度,对应的是地图东部 //故需要转成以北为起点的顺时针角度 if (lineHeading <= 90) { //1、3、4象限 lineHeading = 90 - lineHeading; } else { //2象限 lineHeading = 360 + (90 - lineHeading); } textBox1.Text = lineHeading.ToString(); //textBox1.Text = string.Format("{0},{1}", distAlongCurveFrom, distFromCurve); //double len = pPoly.Length; //textBox2.Text = len.ToString(); }
static private IPolygon ConstructPolygonFromPolyline(IPolyline pPolyline) { IGeometryCollection pPolygonGeoCol = new PolygonClass(); if ((pPolyline != null) && (!pPolyline.IsEmpty)) { IGeometryCollection pPolylineGeoCol = pPolyline as IGeometryCollection; ISegmentCollection pSegCol = new RingClass(); ISegment pSegment = null; object missing = Type.Missing; for (int i = 0; i < pPolylineGeoCol.GeometryCount; i++) { ISegmentCollection pPolylineSegCol = pPolylineGeoCol.get_Geometry(i) as ISegmentCollection; for (int j = 0; j < pPolylineSegCol.SegmentCount; j++) { pSegment = pPolylineSegCol.get_Segment(j); pSegCol.AddSegment(pSegment, ref missing, ref missing); } pPolygonGeoCol.AddGeometry(pSegCol as IGeometry, ref missing, ref missing); } } return(pPolygonGeoCol as IPolygon); }