public static IGraphic NewPolyline(IPointCollection pc) { IPolyline polyline = Runtime.geometryEngine.newPolyline(pc); IGraphic g = Runtime.graphicEngine.newGraphic(); g.Geometry = polyline; return g; }
public MainForm() { InitializeComponent(); pMulPoint = new MultipointClass(); pPointC = pMulPoint as IPointCollection; pClickedCount = 0; }
public IUiWorkflowTaskCollection Create(IEnumerable<IWorkflowTask> tasks, IPointCollection pointCollection) { var u = new UiWorkflowTaskCollection {UiTasks = new Dictionary<string, IUiWorkflowTask>()}; foreach(var task in tasks) { u.UiTasks.Add(task.Id.ToString(), UiWorkflowTaskFactory.Instance.Create(task, pointCollection.Points[task.Id.ToString()])); } return u; }
// Project a point to polyline. // point: (p), polyline: (pts) // output distance relative to the start point of the polyline: (distance) // output projection point: (outPnt) // return value: // true: the point is projected on the polyline without extending the polyline // false: the point is projected on the polyline through extending the polyline // public static bool ProjectPointToPolyline(IMapPoint p, IPointCollection pts,ref double distance, ref IMapPoint outPnt) { distance = 0.0; double outx = 0.0, outy = 0.0; IMapPoint p0, p1; for (int i = 0; i < pts.Count - 1; ++i) { p0 = pts[i]; p1 = pts[i + 1]; bool canProject = GeometryAlgorithms.ProjectPointToLine(p.X, p.Y, p0.X, p0.Y, p1.X, p1.Y, ref outx, ref outy); if (canProject == true) { distance += GeometryAlgorithms.PointDistanceToPoint(outx, outy, p0.X, p0.Y); outPnt = Runtime.geometryEngine.newMapPoint(outx, outy); return true; } distance += GeometryAlgorithms.PointDistanceToPoint(p0.X, p0.Y, p1.X, p1.Y); } // Project the point by extending the polyline p0 = pts[0]; p1 = pts[pts.Count - 1]; double d0p = GeometryAlgorithms.PointDistanceToPoint(p.X, p.Y, p0.X, p0.Y); double d1p = GeometryAlgorithms.PointDistanceToPoint(p.X, p.Y, p1.X, p1.Y); if (d0p < d1p) { // the map point is closer to the beginning of the polyline, // then extend the beginning segment. p1 = pts[1]; GeometryAlgorithms.ProjectPointToLine(p.X, p.Y, p0.X, p0.Y, p1.X, p1.Y, ref outx, ref outy); distance = GeometryAlgorithms.PointDistanceToPoint(outx, outy, p0.X, p0.Y); distance *= -1.0; outPnt = Runtime.geometryEngine.newMapPoint(outx, outy); } else { // the map point is closer to the endding of the polyline, // since the loop is ended on the last segment, just use the result is OK. distance += GeometryAlgorithms.PointDistanceToPoint(outx, outy, p1.X, p1.Y); outPnt = Runtime.geometryEngine.newMapPoint(outx, outy); } return false; }
/// <summary> /// 构造方法 /// </summary> public CollapsePillarsEntering(IPointCollection pointCollection) { InitializeComponent(); dgrdvCoordinate.RowCount = pointCollection.PointCount; for (int i = 0; i < pointCollection.PointCount - 1; i++) { dgrdvCoordinate[0, i].Value = pointCollection.Point[i].X; dgrdvCoordinate[1, i].Value = pointCollection.Point[i].Y; if (pointCollection.Point[i].Z.ToString(CultureInfo.InvariantCulture) == "非数字" || pointCollection.Point[i].Z.ToString(CultureInfo.InvariantCulture) == "NaN") dgrdvCoordinate[2, i].Value = 0; else dgrdvCoordinate[2, i].Value = pointCollection.Point[i].Z; } }
//!在这儿进行修改,将对高程埋深数据存储在不同位置进行统一处理 private void method_2() { IMap map = m_context.FocusMap; IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection; IFeature feature = enumFeature.Next(); bool isMUsing = false; int qdgcIndex = -1; int qdmsIndex = -1; int zdgcIndex = -1; int zdmsIndex = -1; if (feature == null) { return; } if (feature.FeatureType != esriFeatureType.esriFTSimpleEdge) { return; } this.arrayList_1.Clear(); this.arrayList_2.Clear(); int num = 0; while (feature != null) { 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); ISimpleEdgeFeature simpleEdgeFeature = enumFeatures.Next() as ISimpleEdgeFeature; IFeature realFeature = null; int userClassID, userID, userSubID; network.QueryIDs(simpleEdgeFeature.EID, esriElementType.esriETEdge, out userClassID, out userID, out userSubID); if (pClass.FeatureClassID == userClassID) { realFeature = pClass.GetFeature(userID); } else { IEnumDataset dses = pNetworkClass.FeatureDataset.Subsets; dses.Reset(); IDataset ds = dses.Next(); while (ds != null) { if (ds is IFeatureClass) { IFeatureClass pClass2 = ds as IFeatureClass; if (pClass2.FeatureClassID == userClassID) { realFeature = pClass2.GetFeature(userID); break; } } } } IMAware mAware = realFeature.Shape as IMAware; isMUsing = mAware.MAware; IFeatureLayer pLayer = MapHelper.GetLayerByFeature(map as IBasicMap, realFeature); IBasicLayerInfo lineConfig = PipeConfig.GetBasicLayerInfo(realFeature.Class.AliasName) as IBasicLayerInfo; if (!isMUsing) { qdgcIndex = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDGC)); qdmsIndex = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDMS)); zdgcIndex = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDGC)); zdmsIndex = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDMS)); } PipeLine pipeLine = new PipeLine(); IPolyline polyline = (IPolyline)feature.Shape; IPointCollection pointCollection = (IPointCollection)polyline; int pointCount = pointCollection.PointCount; pipeLine.Clear(); if (isMUsing) { for (int i = 0; i < pointCount; i++) { IPoint point = new ESRI.ArcGIS.Geometry.Point(); if (((SortInfo)this.arrayList_0[num]).bRightDirection) { point = pointCollection.get_Point(i); } else { point = pointCollection.get_Point(pointCount - i - 1); } if (double.IsNaN(point.M)) { pipeLine.PushBack(point.X, point.Y, point.Z, point.Z + 1.0); } else { pipeLine.PushBack(point.X, point.Y, point.Z - point.M, point.Z); } } } else { double height = 0; double qdgc = GetDoubleValue(realFeature, qdgcIndex, out height); double zdgc = GetDoubleValue(realFeature, zdgcIndex, out height); double qdms = GetDoubleValue(realFeature, qdmsIndex, out height); double zdms = GetDoubleValue(realFeature, zdmsIndex, out height); if (qdms == 0) { qdms = 1; } if (zdms == 0) { zdms = 1; } IPoint startPoint = pointCollection.Point[0]; IPoint endPoint = pointCollection.Point[pointCollection.PointCount - 1]; pipeLine.PushBack(startPoint.X, startPoint.Y, qdgc - qdms, qdgc); pipeLine.PushBack(endPoint.X, endPoint.Y, zdgc - zdms, zdgc); } //string text = "管线性质"; string text = lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ) == "" ? "管线性质" : lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ); int num2 = realFeature.Fields.FindField(text); string text2 = ""; if (num2 != -1) { object obj = realFeature.get_Value(num2); if (obj == null || Convert.IsDBNull(obj)) { text2 = ""; } else { text2 = obj.ToString(); } } pipeLine.ID = Convert.ToInt32(realFeature.get_Value(0).ToString()); pipeLine.DatasetName = text2; int num3 = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GXCZ)); pipeLine.Material = num3 == -1 ? "" : realFeature.get_Value(num3).ToString(); //管径 num3 = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ)); string text3 = num3 == -1 ? "" : realFeature.get_Value(num3).ToString(); //断面尺寸 num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC)); string text4 = num3 == -1 ? "" : realFeature.get_Value(num3).ToString(); Color featureColor = CommonUtils.GetFeatureColor(map, realFeature.Class.AliasName, realFeature); pipeLine.Red = (int)featureColor.R; pipeLine.Green = (int)featureColor.G; pipeLine.Blue = (int)featureColor.B; if (text3 != "") { pipeLine.PipeWidthHeight = text3; } if (text4 != "") { pipeLine.PipeWidthHeight = text4; } if (pipeLine.PipeWidthHeight == null) { pipeLine.PipeWidthHeight = ""; } this.arrayList_1.Add(pipeLine); IFeature feature2 = (IFeature)((IEdgeFeature)realFeature).FromJunctionFeature; IFeature feature3 = (IFeature)((IEdgeFeature)realFeature).ToJunctionFeature; IFeature feature4; if (num == 0) { PipePoint pipePoint = new PipePoint(); if (((SortInfo)this.arrayList_0[num]).bRightDirection) { feature4 = feature2; } else { feature4 = feature3; } pipePoint.nID = Convert.ToInt32(feature4.get_Value(0)); pipePoint.nAtPipeSegID = pipeLine.ID; pipePoint.bstrDatasetName = text2; IBasicLayerInfo pointConfig = PipeConfig.GetBasicLayerInfo(feature4.Class.AliasName) as IBasicLayerInfo; num3 = feature4.Fields.FindField(pointConfig.GetFieldName(PipeConfigWordHelper.PointWords.FSW)); if (num3 == -1) { pipePoint.bstrPointKind = ""; } else { pipePoint.bstrPointKind = feature4.get_Value(num3).ToString(); } Color featureColor2 = CommonUtils.GetFeatureColor(map, feature4.Class.AliasName, feature4); pipePoint.Red = (int)featureColor2.R; pipePoint.Green = (int)featureColor2.G; pipePoint.Blue = (int)featureColor2.B; this.arrayList_2.Add(pipePoint); } PipePoint pipePoint2 = new PipePoint(); if (((SortInfo)this.arrayList_0[num]).bRightDirection) { feature4 = feature3; } else { feature4 = feature2; } pipePoint2.nID = Convert.ToInt32(feature4.get_Value(0)); pipePoint2.nAtPipeSegID = pipeLine.ID; pipePoint2.bstrDatasetName = text2; IBasicLayerInfo pointConfig3 = PipeConfig.GetBasicLayerInfo(feature4.Class.AliasName) as IBasicLayerInfo; num3 = feature4.Fields.FindField(pointConfig3.GetFieldName(PipeConfigWordHelper.PointWords.FSW)); if (num3 == -1) { pipePoint2.bstrPointKind = ""; } else { pipePoint2.bstrPointKind = feature4.get_Value(num3).ToString(); } Color featureColor3 = CommonUtils.GetFeatureColor(map, feature4.Class.AliasName, feature4); pipePoint2.Red = (int)featureColor3.R; pipePoint2.Green = (int)featureColor3.G; pipePoint2.Blue = (int)featureColor3.B; this.arrayList_2.Add(pipePoint2); feature = enumFeature.Next(); num++; } this.method_3(this.arrayList_2, this.arrayList_1); this.method_4(this.arrayList_3, this.arrayList_1); this.method_5(this.arrayList_4, this.arrayList_2); this.method_6(); this.method_7(this.arrayList_3); }
/// <summary> /// �½����� /// ��ǰͼ��Ϊ��ͼ��ʱ��ÿ����һ�ξ��µ�һ������� /// ��ǰͼ��Ϊ��ͼ�����ͼ��ʱ����һ�ε��ÿ�ʼ�½�������ӵ�ǰ�㣬 /// �Ժ�ÿ����һ�Σ������¶��������һ����,����NewFeatureEnd������ɶ��� /// ��Map.MouseDown�¼��е��ñ����� /// </summary> /// <param name="x">���X���꣬��Ļ����</param> /// <param name="y">���Y���꣬��Ļ����</param> public void NewFeatureMouseDown( int x, int y) { INewPolygonFeedback pPolyFeed ; INewLineFeedback pLineFeed; try { if (m_pCurrentLayer == null ) return ; if (!(m_pCurrentLayer is IGeoFeatureLayer)) return ; IFeatureLayer pFeatureLayer =(IFeatureLayer) m_pCurrentLayer; if (pFeatureLayer.FeatureClass ==null ) return ; IActiveView pActiveView =(IActiveView) m_pMap; IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); // ������¿�ʼ�����Ķ�������Ӧ�Ĵ���һ���µ�Feedback���� // �������Ѵ��ڵ�Feedback�����мӵ� if (!m_bInUse) { m_pMap.ClearSelection(); //�����ͼѡ�ж��� switch ( pFeatureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: CreateFeature( pPoint); break; case esriGeometryType.esriGeometryMultipoint: m_bInUse = true; m_pFeedback = new NewMultiPointFeedbackClass(); INewMultiPointFeedback pMPFeed =(INewMultiPointFeedback) m_pFeedback; m_pPointCollection = new MultipointClass(); pMPFeed.Start(m_pPointCollection, pPoint); break; case esriGeometryType.esriGeometryPolyline: m_bInUse = true; m_pFeedback = new NewLineFeedbackClass(); pLineFeed = (INewLineFeedback) m_pFeedback; pLineFeed.Start(pPoint); break; case esriGeometryType.esriGeometryPolygon: m_bInUse = true; m_pFeedback = new NewPolygonFeedbackClass(); pPolyFeed = (INewPolygonFeedback) m_pFeedback; pPolyFeed.Start(pPoint); break; } if (m_pFeedback != null) m_pFeedback.Display = pActiveView.ScreenDisplay; } else { if (m_pFeedback is INewMultiPointFeedback) { object obj = Missing.Value ; m_pPointCollection.AddPoint(pPoint,ref obj,ref obj); } else if (m_pFeedback is INewLineFeedback) { pLineFeed =(INewLineFeedback) m_pFeedback; pLineFeed.AddPoint(pPoint); } else if (m_pFeedback is INewPolygonFeedback) { pPolyFeed = (INewPolygonFeedback) m_pFeedback; pPolyFeed.AddPoint(pPoint); } } } catch(Exception e) { Console.WriteLine(e.Message.ToString()); } }
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { //If left hand mouse button if (e.button == 1) { //Create a point and grab hold of the IPoint interface IPoint point = new PointClass(); //Set point properties point.X = e.mapX; point.Y = e.mapY; //If this is the first point of a new line if (m_Polyline == null) { //Create the forms private polyline member and grab hold of the IPolyline interface m_Polyline = new PolylineClass(); } //QI for the IPointsCollection interface using the IPolyline interface object o = Type.Missing; //object o1 = m_PointCollection.PointCount-1; m_PointCollection = (IPointCollection) m_Polyline; m_PointCollection.AddPoint(point, ref o, ref o); //Refresh the foreground thereby removing any text annotation axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing,Type.Missing); } else { //If right or middle mouse button zoom to user defined rectangle //Create an envelope and grab hold of the IEnvelope interface IEnvelope envelope = axMapControl1.TrackRectangle(); //If user dragged a rectangle if (envelope != null) { //Set map controls extent property axMapControl1.Extent = envelope; } } }
/// <summary> /// ���ձ��� /// </summary> public void Recycle() { m_NewPolygonFeedback = null; m_ptCollection.RemovePoints(0, m_ptCollection.PointCount); m_ptCollection = null; m_TracePolygon = null;//20140218 lyf m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_hookHelper.ActiveView.Extent); }
private void createpolyline(IPointCollection ippoints) { ISegmentCollection ppath = new PathClass(); IGeometryCollection ppolyline = new PolylineClass(); if (ippoints.PointCount >= 2) { int i; for (i = 0; i < ippoints.PointCount - 1; i++) { ILine pline = new LineClass(); pline.PutCoords(ippoints.get_Point(i), ippoints.get_Point(i + 1)); ISegment psegment = pline as ISegment; object o = Type.Missing; ppath.AddSegment(psegment, ref o, ref o); ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o); } ipPolyResult = ppolyline as IPolyline; } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 2) { return; } IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pt = GIS.GraphicEdit.SnapSetting.getSnapPoint(pt); IGraphicsContainer g = m_hookHelper.ActiveView.GraphicsContainer; IEnvelope pEnvBounds = null; //获取上一次轨迹线的范围,以便确定刷新范围 try { if (m_TraceLine != null) { m_TraceLine.QueryEnvelope(pEnvBounds); pEnvBounds.Expand(4, 4, true); //矩形框向四周扩大4倍(大于2倍就行),目的是为了保证有充足的刷新区域 } else { pEnvBounds = m_hookHelper.ActiveView.Extent; } } catch { pEnvBounds = m_hookHelper.ActiveView.Extent; } #region 启动画线 if (m_NewLineFeedback == null) { //移除element RemoveElements(); //刷新 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); Application.DoEvents(); m_NewLineFeedback = new NewLineFeedbackClass(); m_NewLineFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay; //必须先得到symbol,后设置symbol ISimpleLineSymbol simpleLineSymbol = m_NewLineFeedback.Symbol as ISimpleLineSymbol; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 2; simpleLineSymbol.Color = TransColorToAEColor(Color.Blue); m_NewLineFeedback.Start(pt); } else { m_NewLineFeedback.AddPoint(pt); } if (m_ptColl == null) { m_ptColl = new PolylineClass(); } //记录节点 object obj = Type.Missing; m_ptColl.AddPoint(pt, ref obj, ref obj); #endregion #region 绘制结点 try { IElement vertexElement = createElement_x(pt); // g = m_hookHelper.ActiveView as IGraphicsContainer; //g.AddElement(vertexElement, 0); //g.MoveElementToGroup(vertexElement, m_VertexElement); m_VertexElement.AddElement(vertexElement); //刷新 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, vertexElement, pEnvBounds); } catch { } #endregion try { if (m_ptColl.PointCount >= 2) { IPoint fromPt = m_ptColl.get_Point(m_ptColl.PointCount - 2); //倒数第二个点 IPoint toPt = m_ptColl.get_Point(m_ptColl.PointCount - 1); //最后第一个点 ILine line = new LineClass(); line.PutCoords(fromPt, toPt); #region 绘制轨迹线 try { object missing = Type.Missing; ISegmentCollection segColl = new PolylineClass(); segColl.AddSegment(line as ISegment, ref missing, ref missing); IElement traceElement = createElement_x(segColl as IPolyline); // g = m_hookHelper.ActiveView as IGraphicsContainer; //g.AddElement(traceElement, 0); //g.MoveElementToGroup(traceElement, m_TraceElement); m_TraceElement.AddElement(traceElement); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, traceElement, pEnvBounds); } catch { } #endregion #region 计算单线的长度,并将结果显示在单线中点偏上上面 try { double angle = line.Angle; if ((angle > (Math.PI / 2) && angle < (Math.PI)) || (angle > -Math.PI && angle < -(Math.PI / 2))) // 大于90度小于等于180 { angle += Math.PI; } //标注点Y值偏移量 double d_OffsetY = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints(9); //标注点 double d_CenterX = (fromPt.X + toPt.X) / 2; double d_CenterY = (fromPt.Y + toPt.Y) / 2 + d_OffsetY; //向上偏移 IPoint labelPt = new PointClass(); labelPt.PutCoords(d_CenterX, d_CenterY); IUnitConverter unitConverter = new UnitConverterClass(); double segmentLength = unitConverter.ConvertUnits(line.Length, _MsgInfo.inUnit.pUnit, _MsgInfo.outUnit.pUnit); ITextElement txtElement = CreateTextElement(segmentLength.ToString("0.00")); IElement labelelement = txtElement as IElement; labelelement.Geometry = labelPt; object oElement = (object)labelelement; //根据角度旋转 TransformByRotate(ref oElement, labelPt, angle); ////添加到GraphicsContainer //g.AddElement(labelelement, 0); ////移到m_LabelElement组中 //g.MoveElementToGroup(labelelement, m_LabelElement); //添加到组 m_LabelElement.AddElement(labelelement); //刷新 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, labelelement, pEnvBounds); } catch { } #endregion } } catch { } _MsgInfo.LineResultChange(); }
public static void CreateFCs(IWorkspace pWs, IMap pMap) { var FC1 = CreateFeatureClass(pWs, null, "Point", CreateFields(esriGeometryType.esriGeometryPoint)); var FC2 = CreateFeatureClass(pWs, null, "Line", CreateFields(esriGeometryType.esriGeometryPolyline)); var FC3 = CreateFeatureClass(pWs, null, "Polygon", CreateFields(esriGeometryType.esriGeometryPolygon)); //insert& show List <IGeometry> ptList = new List <IGeometry>(100); IPoint pt; for (int i = 0; i < 1000; i++) { pt = new PointClass(); pt.PutCoords(i * 0.01, i * 0.01); ptList.Add(pt); } List <IGeometry> lineList = new List <IGeometry>(100); IPolyline pLine; IPoint pt1, pt2; for (int i = 0; i < 1000; i++) { pLine = new PolylineClass(); pt1 = new PointClass(); pt1.PutCoords(i * 0.01, (i + 1) * 0.01); pt2 = new PointClass(); pt2.PutCoords(i * 0.01, (i + 11) * 0.01); pLine.FromPoint = pt1; pLine.ToPoint = pt2; lineList.Add(pLine); } List <IGeometry> polygonList = new List <IGeometry>(100); IPolygon pPolygon; IPoint pt3, pt4; for (int i = 0; i < 1000; i++) { pPolygon = new PolygonClass(); IPointCollection ptColl = pPolygon as IPointCollection; pt1 = new PointClass(); pt1.PutCoords(i * 0.01, (i - 2) * 0.01); pt2 = new PointClass(); pt2.PutCoords((i + 1) * 0.01, (i - 2) * 0.01); pt3 = new PointClass(); pt3.PutCoords((i + 1) * 0.01, (i - 3) * 0.01); pt4 = new PointClass(); pt4.PutCoords(i * 0.01, (i - 3) * 0.01); ptColl.AddPoint(pt1); ptColl.AddPoint(pt2); ptColl.AddPoint(pt3); ptColl.AddPoint(pt4); pPolygon.Close(); polygonList.Add(pPolygon); } InsertFeaturesUsingCursor(FC1, ptList); InsertFeaturesUsingCursor(FC2, lineList); InsertFeaturesUsingCursor(FC3, polygonList); IFeatureLayer pFeaturelayer = new FeatureLayerClass(); pFeaturelayer.Name = "pt"; pFeaturelayer.FeatureClass = FC1; pMap.AddLayer(pFeaturelayer); pFeaturelayer = new FeatureLayerClass(); pFeaturelayer.Name = "line"; pFeaturelayer.FeatureClass = FC2; pMap.AddLayer(pFeaturelayer); pFeaturelayer = new FeatureLayerClass(); pFeaturelayer.Name = "polygon"; pFeaturelayer.FeatureClass = FC3; pMap.AddLayer(pFeaturelayer); }
public static double Length(IPointCollection pts) { double len = 0; IMapPoint p1, p2; for (int i = 0; i < pts.Count - 1; ++i) { p1 = pts[i]; p2 = pts[i + 1]; len += Distance(p1, p2); } return len; }
public static void Reverse(IPointCollection pts) { IEnumerable<IMapPoint> reversedPts = pts.Reverse(); IPointCollection newPts = Runtime.geometryEngine.newPointCollection(); foreach (IMapPoint pt in reversedPts) newPts.Add(pt); pts = Runtime.geometryEngine.newPointCollection(); foreach (IMapPoint pt in newPts) pts.Add(pt); }
/// <summary> /// 配准 后面两个参数是保存的文件和类型 /// </summary> /// <param name="pFromPoint"></param> /// <param name="pTPoint"></param> /// <param name="pRasterLayer"></param> /// <param name="pSaveFile"></param> /// <param name="pType"></param> public bool GeoReferencing(IPointCollection pFromPoint, IPointCollection pTPoint, IRasterLayer pRasterLayer, ISpatialReference pSr, string pSaveFile, string pType) { IGeoReference pGeoreference; pGeoreference = (IGeoReference)pRasterLayer; IRaster pRaster = pRasterLayer.Raster; //判断是否可以配准 if (pGeoreference.CanGeoRef == true) { IRasterGeometryProc pRasterGProc = new RasterGeometryProcClass(); pRasterGProc.Warp(pFromPoint, pTPoint, esriGeoTransTypeEnum.esriGeoTransPolyOrder2, pRaster); pRasterGProc.Register(pRaster); IRasterProps pRasterPro = pRaster as IRasterProps; pRasterPro.SpatialReference = pSr;//定义投影 if (File.Exists(pSaveFile)) { File.Delete(pSaveFile); } pRasterGProc.Rectify(pSaveFile, pType, pRaster);//路径和格式(String) return true; } else { return false; } }
// Create object with IPolygon interface // Note: Please refer to IS3Polygon constructor for more instructions. public IPolygon newPolygon(IPointCollection part) { return new IS3Polygon(part); }
// Create object with IPolyline interface // Note: Please refer to IS3Polyline constructor for more instructions. public IPolyline newPolyline(IPointCollection part) { return new IS3Polyline(part); }
private static IEnumerable <CutSubcurve> GetCutSubcurves( [NotNull] IGeometryCollection differences, int differencePathIndexToSplit, [NotNull] IGeometry cuttingGeometry, IDictionary <SubcurveNode, SubcurveNode> nodes, [NotNull] IPointCollection intersectionPoints, IPolyline target) { var curveToSplit = (IPath)differences.Geometry[differencePathIndexToSplit]; IGeometry highLevelCurveToSplit = GeometryUtils.GetHighLevelGeometry( curveToSplit, true); // Enlarge search tolerance to avoid missing points because the intersection points are // 'found' between the target vertex and the actual source-target intersection. // But when using minimum tolerance, make sure we're not searching with the normal tolerance // otherwise stitch points close to target vertices are missed and the result becomes unnecessarily // inaccurate by the two vertices being simplified (at data tolerance) into one intermediate. double searchToleranceFactor = 2 * Math.Sqrt(2); double stitchPointSearchTol = GeometryUtils.GetXyTolerance((IGeometry)differences) * searchToleranceFactor; if (intersectionPoints.PointCount == 0 || GeometryUtils.Disjoint(cuttingGeometry, highLevelCurveToSplit)) { _msg.VerboseDebugFormat( "GetCutSubcurves: No intersections / disjoint geometries"); yield return (CreateCutSubcurve(curveToSplit, null, nodes, null, target, stitchPointSearchTol)); } else { _msg.DebugFormat("GetCutSubcurves: Intersection Point Count: {0}.", intersectionPoints.PointCount); const bool projectPointsOntoPathToSplit = false; // NOTE: take tolerance from cutting geometry because the difference's spatial reference could // have been changed to minimum tolerance which sometimes results in missed points due to cutOffDistance being too small double cutOffDistance = GeometryUtils.GetXyTolerance(cuttingGeometry); // the original subdivision at start/end point is not needed any more: merge if it doesn't touch // any other difference part (to allow the other difference part to become a reshape candidate) IGeometryCollection subCurves = GeometryUtils.SplitPath( curveToSplit, intersectionPoints, projectPointsOntoPathToSplit, cutOffDistance, splittedCurves => UnlessTouchesOtherPart(splittedCurves, differences, differencePathIndexToSplit)); for (var i = 0; i < subCurves.GeometryCount; i++) { var subCurve = (IPath)subCurves.Geometry[i]; bool?curveTouchesDifferentParts = SubCurveTouchesDifferentParts( subCurve, cuttingGeometry); IPath subCurveClone = GeometryFactory.Clone(subCurve); yield return (CreateCutSubcurve(subCurveClone, intersectionPoints, nodes, curveTouchesDifferentParts, target, stitchPointSearchTol)); } Marshal.ReleaseComObject(subCurves); } }
//this method is called when the user clicks the "Compare Vertices" button at the bottom of the form private void cmdCompare_Click(object sender, EventArgs e) { try { if (cboLayer1.SelectedItem.ToString() == "" || cboLayer2.SelectedItem.ToString() == "" || txtOID1.Text == "" || txtOID2.Text == "") //the double pipe is an or operator that "short circuts", meaning that it will bail out early if the condition is true, whereas the single pipe evaluates all conditions { MessageBox.Show("Choose polygon layer, or specify OBJECTID.", "Verify Selections...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //show busy mouse System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; IFeatureLayer pFeatureLayer1 = null; IFeatureLayer pFeatureLayer2 = null; IPointCollection pPtnCollMissingVertices = new MultipointClass(); //point collection for missing vertices and used for graphics layer IPoint pPointMissing = new PointClass(); //used for graphics layer //get access to polygon layer 1 for (int i = 0; i < pMap.LayerCount; i++) { if (pMap.get_Layer(i) is IFeatureLayer) { if (pMap.get_Layer(i).Name.ToString() == cboLayer1.SelectedItem.ToString()) { pFeatureLayer1 = pMap.get_Layer(i) as IFeatureLayer; break; } } } //get access to polygon layer 2 for (int i = 0; i < pMap.LayerCount; i++) { if (pMap.get_Layer(i) is IFeatureLayer) { if (pMap.get_Layer(i).Name.ToString() == cboLayer2.SelectedItem.ToString()) { pFeatureLayer2 = pMap.get_Layer(i) as IFeatureLayer; break; } } } //clear the x,y report list box lstMissingVertices.Items.Clear(); //get vertices for feature 1 //set up query filter for feature 1 IQueryFilter pQueryFilter = new QueryFilter(); pQueryFilter.WhereClause = "OBJECTID = " + txtOID1.Text; //set up feature cursor for feature 1 IFeatureCursor pFeatureCursor = pFeatureLayer1.Search(pQueryFilter, false); //get feature 1 IFeature pFeature1 = pFeatureCursor.NextFeature(); //if no objectid is found if (pFeature1 == null) { MessageBox.Show("The provided OBJECTID was not found for layer: " + cboLayer1.SelectedItem, "ObjectID Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //get feature 1 as a polygon IPolygon pPolygon1 = pFeature1.Shape as IPolygon; //get the point collection for feature 1 IPointCollection pPointColl1 = pPolygon1 as IPointCollection; //get vertices for feature 2 //set up query filter for feature 2 pQueryFilter = new QueryFilter(); pQueryFilter.WhereClause = "OBJECTID = " + txtOID2.Text; //set up feature cursor for feature 2 pFeatureCursor = null; //reuse the feature cursor from above pFeatureCursor = pFeatureLayer2.Search(pQueryFilter, false); //get feature 2 IFeature pFeature2 = pFeatureCursor.NextFeature(); //if no objectid is found if (pFeature2 == null) { MessageBox.Show("The provided OBJECTID was not found for layer: " + cboLayer1.SelectedItem, "ObjectID Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //get feature 1 as a polygon IPolygon pPolygon2 = pFeature2.Shape as IPolygon; //get the point collection for feature 1 IPointCollection pPointColl2 = pPolygon2 as IPointCollection; //loop through point collection and check for missing vertices IPoint pPoint1; IPoint pPoint2; Boolean blnFound; //loop through each point in the first collection and check for missing for (int i = 0; i < pPointColl1.PointCount; i++) { pPoint1 = pPointColl1.get_Point(i); //loop through all the points in the second collection and check for the point from the above collection blnFound = false; for (int j = 0; j < pPointColl2.PointCount; j++) { pPoint2 = pPointColl2.get_Point(j); //check for overlapping points if (pPoint1.X == pPoint2.X && pPoint1.Y == pPoint2.Y) { blnFound = true; } } //if no overlapping points were found, report the missing x,y location to the listbox if (blnFound == false) { lstMissingVertices.Items.Add(pPoint1.X + " " + pPoint1.Y + " " + " Feet" + " (missing from polygon 2)"); //add the missing point to a new collection for display on map pPtnCollMissingVertices.AddPoint(pPoint1); } } //loop through each point in the first collection and check for missing for (int i = 0; i < pPointColl2.PointCount; i++) { pPoint2 = pPointColl2.get_Point(i); //loop through all the points in the second collection and check for the point from the above collection blnFound = false; for (int j = 0; j < pPointColl1.PointCount; j++) { pPoint1 = pPointColl1.get_Point(j); //check for overlapping points if (pPoint2.X == pPoint1.X && pPoint2.Y == pPoint1.Y) { blnFound = true; } } //if no overlapping points were found, report the missing x,y location to the listbox if (blnFound == false) { lstMissingVertices.Items.Add(pPoint2.X + " " + pPoint2.Y + " " + " Feet" + " (missing from polygon 1)"); //add the missing point to a new collection for display on map pPtnCollMissingVertices.AddPoint(pPoint2); } } //if no missing vertices were found, inform the user if (lstMissingVertices.Items.Count < 1) { lstMissingVertices.Items.Add("No Missing Vertices Found"); } //display vertices if checkbox is checked if (chkDisplayVertices.Checked == true) { //show busy mouse System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; //set up the graphics layer for the display of vertices ICompositeGraphicsLayer2 pCompositeGraphicLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer2; ICompositeLayer pCompositeLayer = pCompositeGraphicLayer as ICompositeLayer; ILayer pLayer; IGraphicsLayer pGraphicsLayer; IGraphicsContainer pGraphicsContainer; //loop through the graphics layer and check for the missing vertices layer. if found, delete it for (int i = 0; i < pCompositeLayer.Count; i++) { pLayer = pCompositeLayer.Layer[i]; if (pLayer.Name == "MissingVertices") { pCompositeGraphicLayer.DeleteLayer("MissingVertices"); break; } } //set up a new 'missing vertices' graphics layer pGraphicsLayer = pCompositeGraphicLayer.AddLayer("MissingVertices", null); pMap.ActiveGraphicsLayer = pGraphicsLayer as ILayer; pGraphicsContainer = pCompositeGraphicLayer.FindLayer("MissingVertices") as IGraphicsContainer; //define the color ESRI.ArcGIS.Display.IRgbColor rgbColorCls = new ESRI.ArcGIS.Display.RgbColorClass(); rgbColorCls.Red = 250; rgbColorCls.Green = 0; rgbColorCls.Blue = 0; //define the font stdole.IFontDisp stdFontCls = new stdole.StdFontClass() as stdole.IFontDisp; stdFontCls.Name = "ESRI Surveyor Marker"; //this one has a thin-line hollow circle stdFontCls.Name = "ESRI Surveyor"; //this one has a bold-line hollow circle stdFontCls.Size = 16; //set the character marker symbol's properties ESRI.ArcGIS.Display.ICharacterMarkerSymbol charMarkerSymb = new ESRI.ArcGIS.Display.CharacterMarkerSymbolClass(); charMarkerSymb.Angle = 0; charMarkerSymb.CharacterIndex = 47; charMarkerSymb.Color = rgbColorCls; charMarkerSymb.Font = stdFontCls; charMarkerSymb.Size = 16; charMarkerSymb.XOffset = 0; charMarkerSymb.YOffset = 0; //place the graphics on the map for (int i = 0; i < pPtnCollMissingVertices.PointCount; i++) { pPointMissing = pPtnCollMissingVertices.Point[i]; IElement pElement = new MarkerElement(); pElement.Geometry = pPointMissing; IMarkerElement pMarkerElement = pElement as IMarkerElement; pMarkerElement.Symbol = charMarkerSymb; pGraphicsContainer.AddElement(pElement, 0); } //refresh the map, in order to see the newly added graphics pActiveView.Refresh(); } } catch (Exception ex) { MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine + "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine + "Error Location:" + Environment.NewLine + ex.StackTrace, "AGRC Custom Tools ArcMap Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//////////////////////////////////////////////////////// // private void LoadAddedNetworkPoint(string strNetworkName, IPointCollection pPointCol) { //IFeatureClass pFeatClass = new FeatureClassClass; //IFeatureBuffer pFeatBuffer = pFeatClass.CreateFeatureBuffer(); //IFeatureCursor pFeatCursor = pFeatClass.Insert(true); //IFeature pFeat = pFeatBuffer as IFeature; //for (int i = 0; i <= pPointCol.PointCount - 1; i++) //{ // IPoint pPoint = pPointCol.get_Point(i); // pFeat.Shape = pPoint; // object q = pFeatCursor.InsertFeature(pFeatBuffer); //} //pFeatCursor.Flush(); }
public void Draw(IDisplay disp, IFeature feature) { if (!(_symbol is ISymbol)) { return; } string expr = _expression; foreach (FieldValue fv in feature.Fields) { if (fv.Name == _fieldname && !_useExpression) { _symbol.Text = fv.Value.ToString(); } if (fv.Name == _symbolRotation.RotationFieldName) { try { _symbol.Rotation = (float)_symbolRotation.Convert2DEGAritmetic(Convert.ToDouble(fv.Value)); } catch { } } if (_useExpression) { expr = expr.Replace("[" + fv.Name + "]", fv.Value.ToString()); } } if (_useExpression) { _symbol.Text = expr; } if (String.IsNullOrEmpty(_symbol.Text)) { return; } if (_howManyLabels == howManyLabels.one_per_name) { if (_labelStrings.Contains(_symbol.Text.Trim())) { return; } } if (feature.Shape is IPoint) { if (disp.LabelEngine.TryAppend(disp, _symbol, feature.Shape, _labelPriority != labelPriority.always) == LabelAppendResult.Succeeded) { if (_howManyLabels == howManyLabels.one_per_name) { _labelStrings.Add(_symbol.Text.Trim()); } } } else if (feature.Shape is IPolyline) { IPoint point1 = null, point2 = null; double maxLenght = 0; IEnvelope dispEnv = _clipEnvelope; //disp.Envelope; //if (disp.GeometricTransformer != null) //{ // object e = disp.GeometricTransformer.InvTransform2D(disp.Envelope); // if (e is IGeometry) dispEnv = ((IGeometry)e).Envelope; //} IPolyline pLine = (IPolyline)gView.Framework.SpatialAlgorithms.Clip.PerformClip(dispEnv, feature.Shape); if (pLine == null) { return; } if (_lineLabelling == CartographicLineLabeling.CurvedText) { #region Text On Path IDisplayCharacterRanges ranges = _symbol.MeasureCharacterWidth(disp); if (ranges == null) { return; } float textWidth = ranges.Width; for (int iPath = 0; iPath < pLine.PathCount; iPath++) { IPath path = pLine[iPath]; if (path == null) { continue; } IPointCollection pathPoints = path; if (disp.GeometricTransformer != null) { pathPoints = (IPointCollection)disp.GeometricTransformer.Transform2D(pathPoints); } Geometry.DisplayPath displayPath = new Geometry.DisplayPath(); for (int iPoint = 0; iPoint < pathPoints.PointCount; iPoint++) { double x = pathPoints[iPoint].X, y = pathPoints[iPoint].Y; disp.World2Image(ref x, ref y); displayPath.AddPoint(new System.Drawing.PointF((float)x, (float)y)); } float pathLenght = displayPath.Length; if (pathLenght == 0.0 || textWidth > pathLenght) { continue; } displayPath.Chainage = pathLenght / 2f - textWidth / 2f; float nextChainage = pathLenght / 10f; bool found = false; while (!found) { if (disp.LabelEngine.TryAppend(disp, _symbol, displayPath, _labelPriority != labelPriority.always) == LabelAppendResult.Succeeded) { found = true; if (_howManyLabels == howManyLabels.one_per_name) { _labelStrings.Add(_symbol.Text.Trim()); } if (_howManyLabels != howManyLabels.one_per_part) { break; } } if (!found) { displayPath.Chainage = nextChainage; nextChainage += pathLenght / 10f; } if (displayPath.Chainage + textWidth > pathLenght) { break; } } } #endregion } else if (_lineLabelling == CartographicLineLabeling.Horizontal || _lineLabelling == CartographicLineLabeling.Perpendicular) { #region Horizontal for (int iPath = 0; iPath < pLine.PathCount; iPath++) { IPath path = pLine[iPath]; for (int iPoint = 0; iPoint < path.PointCount - 1; iPoint++) { IPoint p1 = path[iPoint]; IPoint p2 = path[iPoint + 1]; if (dispEnv.minx <= p1.X && dispEnv.maxx >= p1.X && dispEnv.miny <= p1.Y && dispEnv.maxy >= p1.Y && dispEnv.minx <= p2.X && dispEnv.maxx >= p2.X && dispEnv.miny <= p2.Y && dispEnv.maxy >= p2.Y) { double len = Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y)); if (len > maxLenght) { maxLenght = len; //alpha = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)); point1 = p1; point2 = p2; } } } } if (point1 != null && point2 != null) { Point p = new Point(point1.X * 0.5 + point2.X * 0.5, point1.Y * 0.5 + point2.Y * 0.5); if (_lineLabelling == CartographicLineLabeling.Perpendicular) { double angle = Math.Atan2(point2.X - point1.X, point2.Y - point1.Y) * 180.0 / Math.PI; if (angle < 0) { angle += 360; } if (angle > 90 && angle < 270) { angle -= 180; } _symbol.Angle = (float)angle; } if (disp.LabelEngine.TryAppend(disp, _symbol, p, _labelPriority != labelPriority.always) == LabelAppendResult.Succeeded) { if (_howManyLabels == howManyLabels.one_per_name) { _labelStrings.Add(_symbol.Text.Trim()); } } } #endregion } else { #region Parallel Labelling for (int iPath = 0; iPath < pLine.PathCount; iPath++) { IPath path = pLine[iPath]; for (int iPoint = 0; iPoint < path.PointCount - 1; iPoint++) { IPoint p1 = path[iPoint]; IPoint p2 = path[iPoint + 1]; if (dispEnv.minx <= p1.X && dispEnv.maxx >= p1.X && dispEnv.miny <= p1.Y && dispEnv.maxy >= p1.Y && dispEnv.minx <= p2.X && dispEnv.maxx >= p2.X && dispEnv.miny <= p2.Y && dispEnv.maxy >= p2.Y) { double len = Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y)); if (len > maxLenght) { maxLenght = len; //alpha = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)); point1 = p1; point2 = p2; } } } } if (point1 != null && point2 != null) { pLine = new Polyline(); pLine.AddPath(new Path()); pLine[0].AddPoint(point1); pLine[0].AddPoint(point2); if (disp.LabelEngine.TryAppend(disp, _symbol, pLine, _labelPriority != labelPriority.always) == LabelAppendResult.Succeeded) { if (_howManyLabels == howManyLabels.one_per_name) { _labelStrings.Add(_symbol.Text.Trim()); } } } #endregion } } else if (feature.Shape is IPolygon) { LabelPolygon(disp, (IPolygon)feature.Shape); } }
public void frmDbClick(ref INewLineFeedback m_FeedbackLine,ref IGeometry m_Geometry) { if (tbtnLine.Checked == true) { if (m_FeedbackLine != null) { pGeometry = m_FeedbackLine.Stop(); m_Geometry = pGeometry; m_FeedbackLine = null; } IPolyline pPolyLine = (IPolyline)pGeometry; SegLength = LastSeg; TotalLength = CntUnit.ConvertUnits(pPolyLine.Length, inUnit.pUnit, outUnit.pUnit); SegLength = CntUnit.ConvertUnits(SegLength, inUnit.pUnit, outUnit.pUnit); m_SegLen.value = SegLength; m_SegLen.units = outUnit.pUnit; m_TotLen.value = TotalLength; m_TotLen.units = outUnit.pUnit; SegLength = Math.Round(SegLength, 6); TotalLength = Math.Round(TotalLength, 6); SumLengths += TotalLength; UnitSumLen = SumLengths; txtMessage.Clear(); txtMessage.Text = "测量线"+"\r\n线段的长度是:" + SegLength+outUnit.UnitName + "\r\n总长度是:" + TotalLength+outUnit.UnitName; if(tbtnSum.Checked==true) txtMessage.Text+="\r\n"+"\r\n线段长度之和是:"+ SumLengths+outUnit.UnitName; } //重新初始化 TotalLength = 0.0; SegLength = 0.0; TotalAreaLength = 0.0; SegAreaLength = 0.0; myArea = 0.0; Perimeter = 0.0; pCollection = new MultipointClass(); pGeometry = null; }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { if (findpath.Checked) { IPoint ipNew; if (ippoints == null) ippoints = new MultipointClass(); ipNew = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; ippoints.AddPoint(ipNew, ref o, ref o); cls.StopPoints = ippoints; drawpoints(ippoints); } if (findpath2.Checked) { IPoint ipNew; if (ippoints == null) ippoints = new MultipointClass(); ipNew = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; ippoints.AddPoint(ipNew, ref o, ref o); cls.StopPoints = ippoints; drawpoints(ippoints); } if (distanceprocess.Checked) { IPoint ipNew; if (ippoints == null) ippoints = new MultipointClass(); ipNew = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; ippoints.AddPoint(ipNew, ref o, ref o); createpolyline(ippoints); if (ipPolyResult != null) drawpathline(ipPolyResult); drawpoints(ippoints); } if (areaprocess.Checked) { IGraphicsContainer pgraghicscontainer = axMapControl1.Map as IGraphicsContainer; IActiveView pactiveview = pgraghicscontainer as ESRI.ArcGIS.Carto.IActiveView; IPoint ipNew; if (ippoints == null) ippoints = new MultipointClass(); ipNew = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; ippoints.AddPoint(ipNew, ref o, ref o); createpolyline(ippoints); if (ipPolyResult != null) { drawpathline(ipPolyResult); } drawpoints(ippoints); } if (identify.Checked) { int m_px = e.x; int m_py = e.y; selectfeature(m_px, m_py); } if (select.Checked) { int m_px = e.x; int m_py = e.y; selectfeature(m_px, m_py); } }
public void frmDbClick(ref INewPolygonFeedback m_FeedbackPolygon, ref IGeometry m_Geometry) { if (tbtnArea.Checked == true) { if (m_FeedbackPolygon != null) { pGeometry = m_FeedbackPolygon.Stop(); m_Geometry = pGeometry; m_FeedbackPolygon = null; } IPolygon pPloygon = (IPolygon)pGeometry; Perimeter = pPloygon.Length; Perimeter = CntUnit.ConvertUnits(Perimeter, inUnit.pUnit, outUnit.pUnit); m_TotLen.value = Perimeter; m_TotLen.units = outUnit.pUnit; SegAreaLength = LastSegArea; double CntSegAreaLength = CntUnit.ConvertUnits(SegAreaLength, inUnit.pUnit, outUnit.pUnit); m_SegLen.value = CntSegAreaLength; m_SegLen.units = outUnit.pUnit; pArea = (IArea)pPloygon; myArea =Math.Abs( pArea.Area); double CntmyArea = myArea; CntmyArea=ConvertToArea( CntmyArea, inAreaUnit.UnitName, outAreaUnit.UnitName); m_Area.value = CntmyArea; m_Area.units = outAreaUnit.pUnit; string AreaUnitMess; if (outAreaUnit.UnitName == "Unkown Units") AreaUnitMess = outAreaUnit.UnitName; else AreaUnitMess = "Square " + outAreaUnit.UnitName; Perimeter = Math.Round(Perimeter, 6); SumPerimeters += Perimeter; CntSegAreaLength = Math.Round(CntSegAreaLength, 6); CntmyArea = Math.Round(CntmyArea, 6); SumAreas += CntmyArea; UnitSumArea = SumAreas; UnitSumPeri = SumPerimeters; txtMessage.Text = "测量面"+"\r\n线段长是" + CntSegAreaLength + outUnit.UnitName + "\r\n周长是:" + Perimeter + outUnit.UnitName + "\r\n面积是:" + CntmyArea + AreaUnitMess; if(tbtnSum.Checked==true) txtMessage.Text+="\r\n"+"\r\n周长长度之和是:"+ SumPerimeters+outUnit.UnitName +"\r\n面积之和是:"+SumAreas+AreaUnitMess ; } TotalLength = 0.0; SegLength = 0.0; TotalAreaLength = 0.0; SegAreaLength = 0.0; myArea = 0.0; Perimeter = 0.0; pCollection = new MultipointClass(); pGeometry = null; }
private void findpath_Click(object sender, EventArgs e) { zoomin.Checked = false; zoomout.Checked = false; pan.Checked = false; select.Checked = false; distanceprocess.Checked = false; startcalculating.Enabled = true; axMapControl1.CurrentTool = null; this.checkBox1.Enabled = false; this.checkBox2.Enabled = false; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; if (checkBox1.Checked) { if (ippoints == null) ippoints = new MultipointClass(); IPoint ipoint = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(579, 390); object o = Type.Missing; ippoints.AddPoint(ipoint,ref o,ref o); } }
void m_editEvents_OnChangeFeature(IObject obj) { // check if feature contains more than 2000 nodes/vertices // applies to lines and polygons // notify the user and offer a split // check if feature geometry is multi-part // applies to lines and polygons // notify the user and offer a conversion to relation IFeatureClass currentObjectFeatureClass = obj.Class as IFeatureClass; if ((currentObjectFeatureClass == null) || (currentObjectFeatureClass.EXTCLSID == null)) { return; } // check if the current feature class being edited is acutally an OpenStreetMap feature class // all other feature class should not be touched by this extension UID osmEditorExtensionCLSID = currentObjectFeatureClass.EXTCLSID; if (osmEditorExtensionCLSID.Value.ToString().Equals("{65CA4847-8661-45eb-8E1E-B2985CA17C78}", StringComparison.InvariantCultureIgnoreCase) == false) { return; } IFeature currentFeature = obj as IFeature; if (currentFeature == null) { return; } IPointCollection pointCollection = currentFeature.Shape as IPointCollection; if (pointCollection == null) { return; } // block changing features that are supporting features for multi-part geometries (relations) if (currentFeature.Shape is IPolygon || currentFeature.Shape is IPolyline) { if (((IFeatureChanges)currentFeature).ShapeChanged == true) { int memberOFFieldIndex = currentFeature.Fields.FindField("osmMemberOf"); int membersFieldIndex = currentFeature.Fields.FindField("osmMembers"); int osmIDFieldIndex = currentFeature.Fields.FindField("OSMID"); long osmID = 0; if (osmIDFieldIndex > -1) { object osmIDValue = currentFeature.get_Value(osmIDFieldIndex); if (osmIDValue != DBNull.Value) { osmID = Convert.ToInt64(osmIDValue); } } if (membersFieldIndex > -1) { ESRI.ArcGIS.OSM.OSMClassExtension.member[] relationMembers = _osmUtility.retrieveMembers(currentFeature, membersFieldIndex); if (relationMembers != null) { if (relationMembers.Length > 0) { string abortMessage = String.Format(resourceManager.GetString("OSMEditor_FeatureInspector_multipartchangeparentconflictmessage"), osmID); MessageBox.Show(abortMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OK, MessageBoxIcon.Stop); m_editor3.AbortOperation(); } } } if (memberOFFieldIndex > -1) { List <string> isMemberOfList = _osmUtility.retrieveIsMemberOf(currentFeature, memberOFFieldIndex); Dictionary <string, string> dictofParentsAndTypes = _osmUtility.parseIsMemberOfList(isMemberOfList); StringBuilder typeAndIDString = new StringBuilder(); foreach (var item in dictofParentsAndTypes) { switch (item.Value) { case "rel": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_relationidtext") + item.Key + ","); break; case "ply": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_polygonidtext") + item.Key + ","); break; case "ln": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_polylineidtext") + item.Key + ","); break; case "pt": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_pointidtext") + item.Key + ","); break; default: break; } } if (typeAndIDString.Length > 0) { string parentsString = typeAndIDString.ToString(0, typeAndIDString.Length - 1); string abortMessage = String.Format(resourceManager.GetString("OSMEditor_FeatureInspector_multipartchangeconflictmessage"), osmID, parentsString); MessageBox.Show(abortMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OK, MessageBoxIcon.Stop); m_editor3.AbortOperation(); } } } } ISegmentCollection segmentCollection = currentFeature.Shape as ISegmentCollection; bool densifyRequired = false; for (int segmentIndex = 0; segmentIndex < segmentCollection.SegmentCount; segmentIndex++) { ISegment segment = segmentCollection.get_Segment(segmentIndex); if (!(segment is Line)) { densifyRequired = true; break; } } if (densifyRequired) { IGeometryEnvironment4 geometryEnvironment = new GeometryEnvironmentClass() as IGeometryEnvironment4; double densifyTolerance = geometryEnvironment.AutoDensifyTolerance; double deviationTolerance = geometryEnvironment.DeviationAutoDensifyTolerance; IPolycurve polycurve = currentFeature.Shape as IPolycurve; polycurve.Densify(densifyTolerance, deviationTolerance); currentFeature.Shape = polycurve; obj.Store(); } }
private void buildPolyline(IPointCollection pGonColl, double x, double y) { m_workPts[0].PutCoords(x - 500, y - 500); m_workPts[1].PutCoords(x + 500, y - 500); m_workPts[2].PutCoords(x + 500, y + 500); m_workPts[3].PutCoords(x - 500, y + 500); m_workPts[4].PutCoords(x, y); try { bool add = (pGonColl.PointCount == 0); object missingVal = System.Reflection.Missing.Value; for (int i = 0; i< m_workPts.Length; i++) { ((IZAware)m_workPts[i]).ZAware = m_bZ; ((IMAware)m_workPts[i]).MAware = m_bM; if (m_bM) m_workPts[i].M = i; if (m_bZ) m_workPts[i].Z = i * 100; //add it point by point - .Net IDL limitation to do batch update? if (add) //pGonColl.AddPoints(5, ref m_workPts[0]);//strange error of type mismatch pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal); //The Add method only accepts either a before index or an after index. else pGonColl.UpdatePoint(i, m_workPts[i]); } //Can I user replace point collection or addPointcollection? } catch (Exception Ex) {System.Diagnostics.Debug.WriteLine(Ex.Message);} //Attempted to store an element of the incorrect type into the array. }
private void SetPINValue() { //The Theory. //Select polygons that intersect the sketch. //Construct one polyline from the boundaries and intersect with sketch. //Sort resulting intersection locations (multipoint) by distance of the intersect // from the start of the sketch and create new ordered multipoint. //Loop through new ordered multipoint, select underlying parcel and calc pin. IFeatureLayer featLayer = m_editLayers.CurrentLayer; m_curve = m_edSketch.Geometry as IPolyline; //Search parcel polys by graphic to get feature cursor ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = m_curve; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; IFeatureCursor featCursor = featLayer.Search(spatialFilter, true); IFeature feature = featCursor.NextFeature(); //If we have no intersects then exit if (feature == null) { return; } //Make a GeomBag of the polygons boundaries (polylines) IGeometryCollection geomBag = new GeometryBagClass(); object missing = Type.Missing; while (feature != null) { ITopologicalOperator poly = feature.Shape as ITopologicalOperator; geomBag.AddGeometry(poly.Boundary, ref missing, ref missing); feature = featCursor.NextFeature(); } //Make one polyline from the boundaries IPolyline polyLineU = new PolylineClass(); ITopologicalOperator topoOp = polyLineU as ITopologicalOperator; topoOp.ConstructUnion(geomBag as IEnumGeometry); //Get the intersections of the boundaries and the curve IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; //The point collection is not ordered by distance along the curve so //need to create a new collection with this info int[] pointOrder = new int[pointCol.PointCount]; double dac = 0, dfc = 0; bool bRS = false; for (int i = 0; i < pointCol.PointCount; i++) { IPoint queryPoint = new PointClass(); pointCol.QueryPoint(i, queryPoint); m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null, ref dac, ref dfc, ref bRS); pointOrder[i] = (int)dac; } //use built in bubble sort System.Array.Sort(pointOrder); //Loop through the sorted array and calc midpoint between parcel boundaries IPointCollection midPoints = new MultipointClass(); for (int i = 0; i < pointOrder.Length - 1; i++) { //Get the midpoint distance double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2; //create a point at the distance and store in point collection IPoint queryPoint = new PointClass(); m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint); midPoints.AddPoint(queryPoint, ref missing, ref missing); } //If ends of sketch are included then add them as points if (chkEnds.Checked) { object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing); midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing); } m_editor.StartOperation(); //Loop through calculated midpoints, select polygon and calc pin for (int i = 0; i < midPoints.PointCount; i++) { IPoint midPoint = midPoints.get_Point(i); spatialFilter = new SpatialFilter(); spatialFilter.Geometry = midPoint; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; featCursor = featLayer.Search(spatialFilter, false); while ((feature = featCursor.NextFeature()) != null) { feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum); feature.Store(); m_lotNum += int.Parse(txtlotinc.Text); } } m_editor.StopOperation("ViperPIN"); txtlot.Text = m_lotNum.ToString(); }
// Adds Directions points to point collection private void AddPointsToPolyline(ISMDirections objDirections, ref IPointCollection objPoints) { Point objPoint = new PointClass(); // copy points from DD to line int nItemsCount = objDirections.Count; for (int i = 0; i < nItemsCount; i++) { // get shape from Direction ISMDirItem objItem = null; objItem = objDirections.get_Item(i) as ISMDirItem; ISMPointsCollection objShape = null; objShape = objItem.Shape; // Add point from Direction to received collection int nPointsCount = objShape.Count - 1; for (int j = 0; j <= nPointsCount; j++) { // get point from route SMRouterPoint objRouterPoint = objShape.get_Item(j); // Optimization: Not add point if last added point has similar coords bool bAddPoint = false; if (objPoint.IsEmpty) bAddPoint = true; else if ((objPoint.X != objRouterPoint.X) & (objPoint.Y != objRouterPoint.Y)) bAddPoint = true; if (bAddPoint) { // Add point if need objPoint.X = objRouterPoint.X; objPoint.Y = objRouterPoint.Y; objPoint.SpatialReference = m_objSpatialReference; object missing = System.Reflection.Missing.Value; objPoints.AddPoint(objPoint, ref missing, ref missing); } } } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { #region 主窗体右键 /////地图视窗鼠标事件 IToolbarMenu mapPopMenu = null; mapPopMenu = new ToolbarMenu(); if (e.button == 2) { /* IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh();*/ //地图视窗右键菜单功能 mapPopMenu.AddItem(new ControlsSelectTool(), -1, 0, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapPanTool(), -1, 1, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapFullExtentCommand(), -1, 2, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapIdentifyTool(), -1, 3, false, esriCommandStyles.esriCommandStyleIconAndText);//识别工具 mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 4, false, esriCommandStyles.esriCommandStyleIconAndText);// mapPopMenu.AddItem(new ControlsMapZoomInFixedCommand(), -1, 5, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsSelectFeaturesTool(), -1, 6, false, esriCommandStyles.esriCommandStyleIconAndText);//选择要素工具 mapPopMenu.AddItem(new ControlsClearSelectionCommand(), -1, 7, false, esriCommandStyles.esriCommandStyleIconAndText);//缩放所选要素 mapPopMenu.AddItem(new ControlsZoomToSelectedCommand(), -1, 8, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapZoomToLastExtentBackCommand(), -1, 9, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.AddItem(new ControlsMapZoomToLastExtentForwardCommand(), -1, 10, false, esriCommandStyles.esriCommandStyleIconAndText); mapPopMenu.SetHook(axMapControl1);//// 得到地图视窗右键菜单 mapPopMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);//弹出显示菜单 } /* if (e.button == 1)//左键因为右键要取消 { IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh(); } * */ //此事件不会触发 if (e.button == 3)//如果鼠标中间改为ControlsMapPanTool会更好 { IMap pMap = axMapControl1.Map; IActiveView pActiveView = pMap as IActiveView; IEnvelope pEnv = axMapControl1.TrackRectangle(); pActiveView.Extent = pEnv; pActiveView.Refresh(); } #endregion //if (e.button == 2) //{ // IMap pMap = axMapControl1.Map; // IActiveView pActiveView = pMap as IActiveView; // IEnvelope pEnv = axMapControl1.TrackRectangle(); // pActiveView.Extent = pEnv; // pActiveView.Refresh(); //} //网络分析 if (clicked != true) return; IPoint ipNew; if (m_ipPoints == null) { m_ipPoints = new MultipointClass(); } ipNew = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; m_ipPoints.AddPoint(ipNew, ref o, ref o); IElement element; ITextElement textelement = new TextElementClass(); element = textelement as IElement; clickedcount++; textelement.Text = clickedcount.ToString(); element.Geometry = m_ipActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); pGC.AddElement(element, 0); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private int method_3(IPolyline polyline, IPoint point) { int num; int num1 = -1; IPointCollection pointCollection = (IPointCollection)polyline; if (pointCollection.PointCount != 2) { ISegmentCollection segmentCollection = (ISegmentCollection)polyline; int pointCount = pointCollection.PointCount; bool[] flagArray = new bool[pointCount]; bool[] flagArray1 = new bool[2]; for (int i = 0; i < pointCount; i++) { IPoint point1 = pointCollection.get_Point(i); if (point.X < point1.X) { flagArray[i] = false; } else if ((point.X != point1.X ? false : point.Y == point1.Y)) { num = i; return(num); } else { flagArray[i] = true; } } for (int j = 0; j < pointCount - 1; j++) { if (flagArray[j] != flagArray[j + 1]) { IPoint point2 = pointCollection.get_Point(j); IPoint point3 = pointCollection.get_Point(j + 1); if (point.Y < point2.Y) { flagArray1[0] = false; } else if ((point.Y != point2.Y ? false : point.Y == point3.Y)) { num = j; return(num); } else { flagArray1[0] = true; } if (point.Y >= point3.Y) { flagArray1[1] = true; } else { flagArray1[1] = false; } if (flagArray1[0] != flagArray1[1] && Math.Abs(((IProximityOperator)segmentCollection.get_Segment(j)).ReturnDistance(point)) < 0.001) { num = j; return(num); } } } if (num1 < 0) { for (int k = 0; k < pointCount - 1; k++) { if (flagArray[k] == flagArray[k + 1]) { IPoint point4 = pointCollection.get_Point(k); IPoint point5 = pointCollection.get_Point(k + 1); if ((point.X != point4.X ? false : point.X == point5.X)) { num = k; return(num); } } } } num = num1; } else { num = 0; } return(num); }
private void AddVertexNode(IPoint pPnt) { try { IFeatureLayer pFeaturelayer = m_EngineEditLayers.TargetLayer; IActiveView pActiveView = m_activeView; IPoint pPoint = pPnt; if (pFeaturelayer.FeatureClass == null) { return; } //如果不是面状地物则退出 if (pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryEnvelope && pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryLine && pFeaturelayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline) { return; } IGeometry pGeo = null; IFeature pSelFeature = null; pSelFeature = EditVertexClass.GetSelectedFeature(pFeaturelayer); //是否有选中的几何体 if (pSelFeature == null) { return; } //解决不带Z值的要素的编辑和Z值为空的要素的编辑问题 IZAware pZAware = pPoint as IZAware; pZAware.ZAware = true; pPoint.Z = 0; bool pInLine = false; ITopologicalOperator pTopoOpt = default(ITopologicalOperator); IPolyline pBoundaryLine = default(IPolyline); //最小的距离 double pMindis = 0; IProximityOperator pProxOpt = default(IProximityOperator); //得到多边形的边界 if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon || pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryEnvelope) { //获取边界线 pBoundaryLine = EditVertexClass.GetBoundary(pFeaturelayer); } else if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline || pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine) { pBoundaryLine = pSelFeature.ShapeCopy as IPolyline; } pTopoOpt = pPoint as ITopologicalOperator; IRelationalOperator pRelationalOperator = default(IRelationalOperator); pRelationalOperator = pPoint as IRelationalOperator; //判断点是否在边界上 pInLine = pRelationalOperator.Within(pBoundaryLine); //如果不在边界上,判断是否小于容忍距离,如果大于容忍距离则退出程序 if (pInLine == false) { pProxOpt = pPoint as IProximityOperator; pMindis = pProxOpt.ReturnDistance(pBoundaryLine); if (pMindis > THE_POINT_TO_POINT_TOLERANCE) { return; } } //判断是否增加的点刚好为节点 IPointCollection pPolylinePointCol = pBoundaryLine as IPointCollection; IHitTest pHitTest = default(IHitTest); double pHitDis = 0; int pSegIndex = 0; int pVerIndex = 0; IPoint pHitPoint = null; bool bRightSide = true; pHitTest = pBoundaryLine as IHitTest; //增加的点为已有的节点则退出程序 if (pHitTest.HitTest(pPoint, THE_POINT_TO_POINT_TOLERANCE * 10, esriGeometryHitPartType.esriGeometryPartVertex, pHitPoint, ref pHitDis, ref pSegIndex, ref pVerIndex, ref bRightSide) == true) { if (pHitDis < THE_POINT_TO_POINT_TOLERANCE) { return; } } EditVertexClass.pHitPnt = pHitPoint; //为多边形增加节点 ISegmentCollection pSegmentCollection = pBoundaryLine as ISegmentCollection; IPolyline pSegPolyline = null; int pPointIndex = 0; ILine pLine = default(ILine); double pDis1 = 0; double pDis2 = 0; IPoint pVerTex = default(IPoint); pMindis = 100; pProxOpt = pPoint as IProximityOperator; for (int i = 0; i <= pSegmentCollection.SegmentCount - 1; i++) { //判断选中点是否在这个Segment上 pLine = pSegmentCollection.get_Segment(i) as ILine; pDis1 = pProxOpt.ReturnDistance(pLine.FromPoint); pDis2 = pProxOpt.ReturnDistance(pLine.ToPoint); if (Math.Abs(pDis1 + pDis2 - pLine.Length) <= pMindis) { pMindis = Math.Abs(pDis1 + pDis2 - pLine.Length); pVerTex = pLine.ToPoint; } } //获取选中的几何特征 pGeo = pSelFeature.Shape; //得到索引 pPointIndex = EditVertexClass.GetVertexIndex(pVerTex, pGeo); //如果是首点,则设置为最后一个点 if (pPointIndex == 0) { pPointIndex = pSegmentCollection.SegmentCount; } IPointCollection pPolygonPointCol = null; pPolygonPointCol = pSelFeature.ShapeCopy as IPointCollection; pPolygonPointCol.InsertPoints(pPointIndex, 1, ref pPoint); m_EngineEditor.StartOperation(); //拓扑操作 IPolygon pPolygon = null; IPolyline pPlyline = null; if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon || pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryEnvelope) { pPolygon = pPolygonPointCol as IPolygon; pPolygon.Close(); pTopoOpt = pPolygon as ITopologicalOperator; pTopoOpt.Simplify(); pSelFeature.Shape = pPolygon; pSelFeature.Store(); } else if (pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline || pFeaturelayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryLine) { pPlyline = pPolygonPointCol as IPolyline; pTopoOpt = pPlyline as ITopologicalOperator; pTopoOpt.Simplify(); pSelFeature.Shape = pPlyline; pSelFeature.Store(); } //停止编辑 m_EngineEditor.StopOperation("AddVertexTool"); //显示顶点 EditVertexClass.ShowAllVertex(pFeaturelayer); } catch (Exception ex) { } }
public static IPolygon GetPolyGonFromFile(string path) { IPolygon pGon = null; if (path.EndsWith(".mdb")) { string errmsg = ""; IWorkspaceFactory pwf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass(); IWorkspace pworkspace = pwf.OpenFromFile(path, 0); IEnumDataset pEnumdataset = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureClass); pEnumdataset.Reset(); IDataset pDataset = pEnumdataset.Next(); while (pDataset != null) { IFeatureClass pFeatureclass = pDataset as IFeatureClass; if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline) { pDataset = pEnumdataset.Next(); continue; } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { pGon = pFeature.Shape as IPolygon; break; } else { pDataset = pEnumdataset.Next(); continue; } } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { IPolyline pPolyline = pFeature.Shape as IPolyline; pGon = GetPolygonFormLine(pPolyline); if (pGon.IsClosed == false) { errmsg = "选择的要素不能构成封闭多边形!"; pGon = null; pDataset = pEnumdataset.Next(); continue; } else { break; } } } } if (pGon == null) { IEnumDataset pEnumdataset1 = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset); pEnumdataset1.Reset(); pDataset = pEnumdataset1.Next(); while (pDataset != null) { IFeatureDataset pFeatureDataset = pDataset as IFeatureDataset; IEnumDataset pEnumDataset2 = pFeatureDataset.Subsets; pEnumDataset2.Reset(); IDataset pDataset1 = pEnumDataset2.Next(); while (pDataset1 != null) { if (pDataset1 is IFeatureClass) { IFeatureClass pFeatureclass = pDataset1 as IFeatureClass; if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline) { pDataset1 = pEnumDataset2.Next(); continue; } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { pGon = pFeature.Shape as IPolygon; break; } else { pDataset1 = pEnumDataset2.Next(); continue; } } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { IPolyline pPolyline = pFeature.Shape as IPolyline; pGon = GetPolygonFormLine(pPolyline); if (pGon.IsClosed == false) { errmsg = "选择的要素不能构成封闭多边形!"; pGon = null; pDataset1 = pEnumDataset2.Next(); continue; } else { break; } } } } } if (pGon != null) { break; } pDataset = pEnumdataset1.Next(); } } if (pGon == null) { if (errmsg != "") { System.Windows.Forms.MessageBox.Show(errmsg, "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } else { System.Windows.Forms.MessageBox.Show("请选择一个包含面要素和线要素的文件", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } return(pGon); } } else if (path.EndsWith(".shp")) { IWorkspaceFactory pwf = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass(); string filepath = System.IO.Path.GetDirectoryName(path); string filename = path.Substring(path.LastIndexOf("\\") + 1); IFeatureWorkspace pFeatureworkspace = (IFeatureWorkspace)pwf.OpenFromFile(filepath, 0); IFeatureClass pFeatureclass = pFeatureworkspace.OpenFeatureClass(filename); if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { pGon = pFeature.Shape as IPolygon; } } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { IPolyline pPolyline = pFeature.Shape as IPolyline; pGon = GetPolygonFormLine(pPolyline); if (pGon.IsClosed == false) { System.Windows.Forms.MessageBox.Show("选择的线要素不能构成封闭多边形!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); return(null); } } } else { System.Windows.Forms.MessageBox.Show("请选择一个面或者线要素文件!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); return(null); } } else if (path.EndsWith(".txt")) { string txtpath = path; System.IO.StreamReader smRead = new System.IO.StreamReader(txtpath, System.Text.Encoding.Default); //设置路径 string line; IPointCollection pc = pGon as IPointCollection; double x, y; while ((line = smRead.ReadLine()) != null) { if (line.IndexOf(",") > 0) { try { x = double.Parse(line.Substring(0, line.IndexOf(","))); y = double.Parse(line.Substring(line.IndexOf(",") + 1)); } catch { System.Windows.Forms.MessageBox.Show("文本文件格式不正确!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); smRead.Close(); return(null); } IPoint tmpPoint = new ESRI.ArcGIS.Geometry.Point(); tmpPoint.X = x; tmpPoint.Y = y; object ep = System.Reflection.Missing.Value; pc.AddPoint(tmpPoint, ref ep, ref ep); } } smRead.Close(); ICurve pCurve = pGon as ICurve; if (pCurve.IsClosed == false) { System.Windows.Forms.MessageBox.Show("导入点坐标不能构成封闭多边形!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); return(null); } } else if (path.EndsWith("gdb")) { string errmsg = ""; IWorkspaceFactory pwf = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass(); IWorkspace pworkspace = pwf.OpenFromFile(path.Substring(0, path.LastIndexOf("\\")), 0); IEnumDataset pEnumdataset = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureClass); pEnumdataset.Reset(); IDataset pDataset = pEnumdataset.Next(); while (pDataset != null) { IFeatureClass pFeatureclass = pDataset as IFeatureClass; if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline) { pDataset = pEnumdataset.Next(); continue; } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { pGon = pFeature.Shape as IPolygon; break; } else { pDataset = pEnumdataset.Next(); continue; } } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { IPolyline pPolyline = pFeature.Shape as IPolyline; pGon = GetPolygonFormLine(pPolyline); if (pGon.IsClosed == false) { errmsg = "选择的要素不能构成封闭多边形!"; pGon = null; pDataset = pEnumdataset.Next(); continue; } else { break; } } } } if (pGon == null) { IEnumDataset pEnumdataset1 = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset); pEnumdataset1.Reset(); pDataset = pEnumdataset1.Next(); while (pDataset != null) { IFeatureDataset pFeatureDataset = pDataset as IFeatureDataset; IEnumDataset pEnumDataset2 = pFeatureDataset.Subsets; pEnumDataset2.Reset(); IDataset pDataset1 = pEnumDataset2.Next(); while (pDataset1 != null) { if (pDataset1 is IFeatureClass) { IFeatureClass pFeatureclass = pDataset1 as IFeatureClass; if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline) { pDataset1 = pEnumDataset2.Next(); continue; } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { pGon = pFeature.Shape as IPolygon; break; } else { pDataset1 = pEnumDataset2.Next(); continue; } } else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline) { IFeatureCursor pCursor = pFeatureclass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); if (pFeature != null) { IPolyline pPolyline = pFeature.Shape as IPolyline; pGon = GetPolygonFormLine(pPolyline); if (pGon.IsClosed == false) { errmsg = "选择的要素不能构成封闭多边形!"; pGon = null; pDataset1 = pEnumDataset2.Next(); continue; } else { break; } } } } } if (pGon != null) { break; } pDataset = pEnumdataset1.Next(); } } if (pGon == null) { if (errmsg != "") { System.Windows.Forms.MessageBox.Show(errmsg, "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } else { System.Windows.Forms.MessageBox.Show("请选择一个包含面要素和线要素的文件", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } return(pGon); } } return(pGon); }
/// <summary> /// 获得缓冲区域内的点集合 /// </summary> /// <param name="pBuff">缓冲区域</param> /// <returns>缓冲区域内的点集合(IPointCollection)</returns> private IPointCollection pntColl(IGeometry pBuff) { //============================================================= string pFld = m_Parameters[1].ToString().Trim(); object o = Type.Missing; IPointCollection pPointColl = new MultipointClass(); ISpatialFilter pFilter = new SpatialFilterClass(); //============================================================= ILayer pLyr = m_Parameters[0] as ILayer; IFeatureLayer pFLyr = pLyr as IFeatureLayer; if (pFLyr == null) { return(null); } IFeatureClass pFCls = pFLyr.FeatureClass; //============================================================= pFilter.Geometry = pBuff; pFilter.GeometryField = pFCls.ShapeFieldName; pFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; IFeatureCursor pOutFeatureCursor = pFCls.Search(pFilter, false); IFeature pFeature = pOutFeatureCursor.NextFeature(); while (pFeature != null) { IGeometry pGeometry = pFeature.Shape; if (pGeometry != null) { if (pFld == "Z") { #region 中'Z'字段 if (pGeometry is IPoint) { IPoint pPnt = pGeometry as IPoint; if (pPnt.Z > -999) { pPointColl.AddPoint(pPnt, ref o, ref o); } } else { IPointCollection pPnts = pGeometry as IPointCollection; for (int i = 0; i < pPnts.PointCount; i++) { IPoint pPnt = pPnts.get_Point(i); if (pPnt.Z <= -999) { //MessageBox.Show("无法读取该点数据!","提示"); continue; } else { pPointColl.AddPoint(pPnt, ref o, ref o); } } } #endregion } else { #region 中其他字段 if (pGeometry is IPoint) { IPoint pPnt = pGeometry as IPoint; pPnt.Z = Convert.ToDouble(pFeature.get_Value(pFCls.Fields.FindField(pFld)).ToString().Trim()); if (pPnt.Z != -999) { pPointColl.AddPoint(pPnt, ref o, ref o); } } else { IPointCollection pPnts = pGeometry as IPointCollection; for (int i = 0; i < pPnts.PointCount; i++) { IPoint pPnt = pPnts.get_Point(i); pPnt.Z = Convert.ToDouble(pFeature.get_Value(pFCls.Fields.FindField(pFld)).ToString().Trim()); if (pPnt.Z != -999) { pPointColl.AddPoint(pPnt, ref o, ref o); } } } #endregion } } pFeature = pOutFeatureCursor.NextFeature(); } //0919 try { System.Runtime.InteropServices.Marshal.ReleaseComObject(pOutFeatureCursor); } catch (Exception ex) { } //0919 return(pPointColl); }
private IGeometryCollection CalculateDifferences( [NotNull] IPolyline preprocessedSourcePolyline, [NotNull] IPolyline targetPolyline, [CanBeNull] ITrackCancel trackCancel, out IPointCollection intersectionPoints) { double originalToleranceSource = GeometryUtils.GetXyTolerance(preprocessedSourcePolyline); double originalToleranceTarget = GeometryUtils.GetXyTolerance(targetPolyline); IGeometryCollection differences; intersectionPoints = null; try { if (UseMinimumTolerance) { GeometryUtils.SetMinimumXyTolerance(preprocessedSourcePolyline); GeometryUtils.SetMinimumXyTolerance(targetPolyline); } differences = GetReshapableAlongGeometries(preprocessedSourcePolyline, targetPolyline, originalToleranceSource); if (trackCancel != null && !trackCancel.Continue()) { return(null); } if (differences == null) { return(null); } // TODO: Consider using intersection point calculator from cracker in minimum-tolerance mode and / or // use the target segments (GetTargetSegmentsAlong) also in non-minimum tolerance mode. // This could possibly improve the situation from unit test CanReshapeAlongWithSmallIntersectionAngle const bool assumeIntersecting = true; intersectionPoints = (IPointCollection)IntersectionUtils.GetIntersectionPoints( (IPolyline)differences, preprocessedSourcePolyline, assumeIntersecting); } finally { if (UseMinimumTolerance) { // The Reshape Curves are sometimes not correct if not using the normal tolerance when splitting // (see unit test CanReshapeAlongEnsureCorrectTargetVerticesLocationWithMinimalTolerance) GeometryUtils.SetXyTolerance(preprocessedSourcePolyline, originalToleranceSource); GeometryUtils.SetXyTolerance(targetPolyline, originalToleranceTarget); if (intersectionPoints != null) { GeometryUtils.SetXyTolerance((IGeometry)intersectionPoints, originalToleranceSource); } // NOTE: difference will be cracked into reshape paths. However, if two points are closer than the tolerance // the point (too) close to the intersection is eliminated by polycurve.SplitAtPoint resulting in // a slightly changed reshape path -> keep the minimum tolerance for the difference to be more accurate. } } return(differences); }
/// <summary> /// 通过地表内插计算点的高程值 /// </summary> /// <param name="pPnt"></param> /// <returns>点的高程值</returns> private double Calculate_Z(IPoint pPnt) { double pZ = 0; //================================================ double dRad = double.Parse("15".Trim()) / 2.0; //搜索半径一半 double dBufferRad = 0.0; ITopologicalOperator pTopo = pPnt as ITopologicalOperator; IGeometry pBuffer = pTopo.Buffer(dRad); IPointCollection pPC = pntColl(pBuffer);//this.Get_PntColl(); if (pPC == null) { return(-1); } //================================================ int pTag = 1; //如果点数小于2,则增大搜索半径,重新搜索 while (pPC.PointCount < 2) { if (pTag > 4)//若重新搜索4次还没有点,则退出 { break; } pTag++; dBufferRad = dRad * pTag; pBuffer = pTopo.Buffer(dBufferRad); pPC = pntColl(pBuffer); } //================================================ if (pPC.PointCount > 1) { double pTolZ = 0; double pLength = 0; double iP = 0; double pToliP = 0;//权系数 // MessageBox.Show("搜索点数为"+pPC.PointCount.ToString()); for (int i = 0; i < pPC.PointCount; i++) { IPoint pPt = pPC.get_Point(i); if (pPt.Z >= 0 || pPt.Z < 0) { pLength = Get_Len_2piont(pPnt, pPt); if (pLength > 0) { iP = 1 / Math.Pow(pLength, 2); pToliP = pToliP + iP; pTolZ = pTolZ + iP * pPt.Z; } }//if (pPt.Z != double.NaN) } if (pToliP != 0) { pZ = pTolZ / pToliP; } //pToliP = 0使用初始化值0作为pZ结果 else //大于两个点均与查询点重合 { pZ = 0; } } else//点数小于两个 { pZ = 0; m_tempPoitArray.Add(pPnt); } return(pZ); }
private static CutSubcurve CreateCutSubcurve( [NotNull] IPath path, [CanBeNull] IPointCollection intersectionPoints, [NotNull] IDictionary <SubcurveNode, SubcurveNode> allNodes, bool?touchingDifferentParts, IPolyline targetPolyline, double stitchPointSearchTol) { var touchAtFromPoint = false; var touchAtToPoint = false; if (intersectionPoints != null) { touchAtFromPoint = GeometryUtils.Intersects( path.FromPoint, (IGeometry)intersectionPoints); touchAtToPoint = GeometryUtils.Intersects( path.ToPoint, (IGeometry)intersectionPoints); } var fromNode = new SubcurveNode(path.FromPoint.X, path.FromPoint.Y); if (allNodes.ContainsKey(fromNode)) { fromNode = allNodes[fromNode]; } else { allNodes.Add(fromNode, fromNode); } var toNode = new SubcurveNode(path.ToPoint.X, path.ToPoint.Y); if (allNodes.ContainsKey(toNode)) { toNode = allNodes[toNode]; } else { allNodes.Add(toNode, toNode); } var cutSubcurve = new CutSubcurve(path, touchAtFromPoint, touchAtToPoint, fromNode, toNode, touchingDifferentParts); // Identify stitch points, i.e. points that do not exist in the target and should not end up in the // reshaped geometry if several adjacent cutsubcurves are applied together. if (touchAtFromPoint) { IPoint point = cutSubcurve.Path.FromPoint; ISegment targetSegment; cutSubcurve.FromPointIsStitchPoint = IsNoTargetVertex( point, targetPolyline, stitchPointSearchTol, out targetSegment); cutSubcurve.TargetSegmentAtFromPoint = targetSegment; } if (touchAtToPoint) { IPoint point = cutSubcurve.Path.ToPoint; ISegment targetSegment; cutSubcurve.ToPointIsStitchPoint = IsNoTargetVertex( point, targetPolyline, stitchPointSearchTol, out targetSegment); cutSubcurve.TargetSegmentAtToPoint = targetSegment; } fromNode.ConnectedSubcurves.Add(cutSubcurve); toNode.ConnectedSubcurves.Add(cutSubcurve); return(cutSubcurve); }
/// <summary> /// 通过鼠标点击获取观察点与被观察点同时进行两点间通视分析 /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_frm3DLineOfSight.m_Layer == null || m_frm3DLineOfSight.m_Surface == null) { MessageBox.Show("请设置有效的表面数据", "提示!"); return; } if (m_frm3DLineOfSight.txtObsOffset.Text == "" || m_frm3DLineOfSight.txtTarOffset.Text == "") { MessageBox.Show("观察点高度和被观察点高度不能为空", "提示!"); return; } m_frm3DLineOfSight.TopMost = true; ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph; m_pNewLineFeedback = new NewLineFeedbackClass(); IPolyline pPolyline = m_pNewLineFeedback.Stop(); //用于判断是否已经获取两点 ISceneControl pSceneControl = m_sceneHookHelper.Hook as ISceneControl; Cls3DModulsefun pCls3DModulsefun = new Cls3DModulsefun(); //用于绘制通视分析结果的方法 object pOwner; object pObject; ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.PointClass(); pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pPoint, out pOwner, out pObject);//获取鼠标点击的位置并转化为地理坐标 if (pPoint == null) { return; } ESRI.ArcGIS.Geometry.IPoint pFlashPoint = new ESRI.ArcGIS.Geometry.PointClass(); IClone pClone = pPoint as IClone; pFlashPoint = pClone.Clone() as ESRI.ArcGIS.Geometry.IPoint; pFlashPoint.Z = pFlashPoint.Z / pSceneGraph.VerticalExaggeration; pFlashPoint.SpatialReference = pSceneGraph.Scene.SpatialReference; IDisplay3D pDisplay = pSceneGraph as IDisplay3D; pDisplay.FlashLocation(pFlashPoint);//闪烁显示被点击的位置 IGeometry pGeometry = null; if (m_pScenePoints == null) { m_pScenePoints = new PolylineClass(); pGeometry = m_pScenePoints as IGeometry; pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference; } object before = Type.Missing; object after = Type.Missing; m_pScenePoints.AddPoint(pPoint, ref before, ref after);//添加获取的点到点集合中 if (m_pScenePoints.PointCount == 2) { pClone = m_pScenePoints as IClone; pPolyline = pClone.Clone() as ESRI.ArcGIS.Geometry.IPolyline;//当点集合中点数达到两个时生成一条线用于判断观察点与被观察点是否确定 m_pScenePoints = null; } if (pPolyline != null) { m_pScenePoints = null; ISurface pSurface = m_SurFace; ESRI.ArcGIS.Geometry.IPoint fPoint = pPolyline.FromPoint; //获取观察点 fPoint.Z = pSurface.GetElevation(fPoint); //获取观察点的高程 ESRI.ArcGIS.Geometry.IPoint tPoint = pPolyline.ToPoint; tPoint.Z = pSurface.GetElevation(tPoint); if (pSurface.IsVoidZ(fPoint.Z) || pSurface.IsVoidZ(tPoint.Z)) { return; } fPoint.Z = fPoint.Z + Convert.ToDouble(m_frm3DLineOfSight.txtObsOffset.Text);//观察者的高度加上观察者所在的高程才是观察点实际的高程 tPoint.Z = tPoint.Z + Convert.ToDouble(m_frm3DLineOfSight.txtTarOffset.Text); ESRI.ArcGIS.Geometry.IPoint pObstruct; IPolyline pVisPolyline; IPolyline pInVisPolyline; bool bIsVis; object pRefractionFactor = Type.Missing; //进行两点间的通视分析 pSurface.GetLineOfSight(fPoint, tPoint, out pObstruct, out pVisPolyline, out pInVisPolyline, out bIsVis, m_frm3DLineOfSight.checkBoxCurv.Checked, m_frm3DLineOfSight.checkBoxCurv.Checked, ref pRefractionFactor); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; //绘制可视与不可视的沿地表线要素 if (pVisPolyline != null) { pSimpleLineSymbol.Color = Cls3DMarkDraw.getRGB(0, 255, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pVisPolyline as IGeometry, pSimpleLineSymbol as ISymbol); } if (pInVisPolyline != null) { pSimpleLineSymbol.Color = Cls3DMarkDraw.getRGB(255, 0, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pInVisPolyline as IGeometry, pSimpleLineSymbol as ISymbol); } IGeometryCollection pVisPatch = new MultiPatchClass();//用于存储可视域的要素 pGeometry = pVisPatch as IGeometry; pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference; double dTargetHeightForVis = 0; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); IGeometryCollection pInVisPatch = new MultiPatchClass();//存储不可视域的要素 pGeometry = pInVisPatch as IGeometry; pGeometry.SpatialReference = pSceneGraph.Scene.SpatialReference; IGeometryCollection pPathGeo = pInVisPolyline as IGeometryCollection; if (pPathGeo != null) { //下面的作用是将不可视域线每段path生成线要素进行绘制 张琪 20110623 for (int i = 0; i < pPathGeo.GeometryCount; i++) { IGeometryCollection pInPolyline = new PolylineClass(); IPath path = pPathGeo.get_Geometry(i) as IPath; pInPolyline.AddGeometry(path as IGeometry, ref before, ref after); pCls3DModulsefun.CreateVerticalLOSPatches(bIsVis, fPoint, tPoint, pVisPolyline, pInPolyline as IPolyline, pVisPatch, pInVisPatch, dTargetHeightForVis); } } else//当不可视域为空时,直接分析生成可视域与不可视域 { pCls3DModulsefun.CreateVerticalLOSPatches(bIsVis, fPoint, tPoint, pVisPolyline, pInVisPolyline, pVisPatch, pInVisPatch, dTargetHeightForVis); } // // 对可视域与不可视域要素在场景中绘制出来 if (pInVisPatch != null) { pSimpleFillSymbol.Color = Cls3DMarkDraw.getRGB(255, 0, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pInVisPatch as IGeometry, pSimpleFillSymbol as ISymbol); } if (pVisPatch != null) { pSimpleFillSymbol.Color = Cls3DMarkDraw.getRGB(0, 255, 0); pCls3DModulsefun.AddGraphic(pSceneControl, pVisPatch as IGeometry, pSimpleFillSymbol as ISymbol); } } }
public void OtherRule(string idname, string checkname, string IN_RuleType, string TABLENAME, string SUPTABLE, string inputtext, IHookHelper m_hookHelper) { CommonClass common = new CommonClass(); IFeatureClass IN_FeatureClass = common.GetLayerByName(TABLENAME).FeatureClass; IGeoDataset pGeoDataset = IN_FeatureClass as IGeoDataset; ISpatialReference spatialReference = pGeoDataset.SpatialReference; IFeatureClass IN_Sup_FeatureClass = null; if (SUPTABLE != null) { IN_Sup_FeatureClass = common.GetLayerByName(SUPTABLE).FeatureClass; } string ErrorFilePath = this.topoDir + "\\" + checkname + idname + ".shp"; if (IN_RuleType == "面多部件检查") { try { common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname); List <ErrorEntity> list = new List <ErrorEntity>(); IFeatureCursor cursor = IN_FeatureClass.Search(null, false); int tempCount = 0; IFeature pFeature = cursor.NextFeature(); while (pFeature != null) { IGeometry pGeo = pFeature.ShapeCopy; ITopologicalOperator pTopoOperator = pGeo as ITopologicalOperator; int iCount = 0; if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { iCount = (pGeo as IPolygon).ExteriorRingCount; } else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { iCount = ((pGeo as IPolyline) as IGeometryCollection).GeometryCount; } else if (IN_FeatureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) { iCount = ((pGeo as IMultipoint) as IPointCollection).PointCount; } if (iCount > 1) { tempCount++; common.GenerateSHPFile(pFeature.ShapeCopy, ErrorFilePath); } pFeature = cursor.NextFeature(); } //new ErrorTable().AddErr(list, ErrType.MultiPart, idname); if (!DicTopoError.ContainsKey(idname)) { DicTopoError.Add(idname, tempCount); } else { DicTopoError[idname] = tempCount; } Marshal.ReleaseComObject(cursor); if (tempCount == 0) { string shpFolder = System.IO.Path.GetDirectoryName(ErrorFilePath); IWorkspaceFactory pWorkspaceFac = new ShapefileWorkspaceFactoryClass(); IWorkspace pWorkSpace = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0); IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace; if (System.IO.File.Exists(ErrorFilePath)) { IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath); if (pFCChecker != null) { IDataset pds = pFCChecker as IDataset; pds.Delete(); } } } } catch (Exception ex) { LogHelper.WriteLog(typeof(TopoChecker), ex); } } else if (IN_RuleType == "面自相交检查") { int errorCount = 0; try { common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPoint, checkname + idname); IFeatureLayer pLayer = new FeatureLayer(); pLayer.FeatureClass = IN_FeatureClass; TopoClassChecker topo = new TopoClassChecker(); IFeatureCursor cursor; IQueryFilter filter = new QueryFilterClass(); filter.SubFields = pLayer.FeatureClass.OIDFieldName + "," + pLayer.FeatureClass.ShapeFieldName; cursor = pLayer.FeatureClass.Search(filter, true); IFeature feature = null; object missing = Type.Missing; while ((feature = cursor.NextFeature()) != null) { IPoint tempPoint = null; StringBuilder builder = new StringBuilder(); IGeometryCollection shape = feature.Shape as IGeometryCollection; for (int i = 0; i < shape.GeometryCount; i++) { esriNonSimpleReasonEnum enum2; IPointCollection newPoints = shape.get_Geometry(i) as IPointCollection; IRing ring = newPoints as IRing; int num2 = 0; if (ring.IsClosed) { num2 = 1; } PolylineClass o = new PolylineClass(); o.AddPointCollection(newPoints); o.SpatialReference = spatialReference; ITopologicalOperator3 @operator = o; @operator.IsKnownSimple_2 = false; if ([email protected]_IsSimpleEx(out enum2) && (enum2 == esriNonSimpleReasonEnum.esriNonSimpleSelfIntersections)) { List <string> list2 = new List <string>(); List <string> list3 = new List <string>(); for (int j = num2; j < newPoints.PointCount; j++) { IPoint point = newPoints.get_Point(j); tempPoint = point; string item = point.X.ToString() + "," + point.Y.ToString(); if (list2.Contains(item)) { if (!list3.Contains(item)) { builder.Append(";"); builder.Append(item); list3.Add(item); } } else { list2.Add(item); } } } Marshal.ReleaseComObject(o); o = null; } if (builder.Length > 0) { errorCount++; string[] strArray = builder.ToString().Substring(1).Split(new char[] { ';' }); ESRI.ArcGIS.Geometry.IPointCollection pPointCollection1 = new ESRI.ArcGIS.Geometry.MultipointClass(); foreach (string str in strArray) { if (!string.IsNullOrEmpty(str)) { string[] strArray2 = str.Split(new char[] { ',' }); double pX = double.Parse(strArray2[0]); double pY = double.Parse(strArray2[1]); ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.X = pX; point.Y = pY; common.GenerateSHPFile(point, ErrorFilePath); } } } } Marshal.ReleaseComObject(cursor); if (errorCount == 0) { string shpFolder = System.IO.Path.GetDirectoryName(ErrorFilePath); IWorkspaceFactory pWorkspaceFac = new ShapefileWorkspaceFactoryClass(); IWorkspace pWorkSpace = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0); IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace; if (System.IO.File.Exists(ErrorFilePath)) { IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath); if (pFCChecker != null) { IDataset pds = pFCChecker as IDataset; pds.Delete(); } } } } catch (Exception ex) { LogHelper.WriteLog(typeof(TopoChecker), ex); } if (!DicTopoError.ContainsKey(idname)) { DicTopoError.Add(idname, errorCount); } else { DicTopoError[idname] = errorCount; } } else if (IN_RuleType == "缝隙检查") { int errorCount = 0; try { common.CreatShpFile(this.topoDir, spatialReference, esriGeometryType.esriGeometryPolygon, checkname + idname); this.m_hookHelper = m_hookHelper; IFeatureClass pFClass = IN_FeatureClass; //获取空间参考 IGeometry geometryBag = new GeometryBagClass(); IGeoDataset geoDataset = pFClass as IGeoDataset; geometryBag.SpatialReference = geoDataset.SpatialReference; ////属性过滤 IFeatureCursor featureCursor = pFClass.Search(null, false); // 遍历游标 IFeature currentFeature = featureCursor.NextFeature(); IGeometryCollection geometryCollection = geometryBag as IGeometryCollection; object missing = Type.Missing; while (currentFeature != null) { geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing); currentFeature = featureCursor.NextFeature(); } // 合并要素 ITopologicalOperator unionedPolygon = null; unionedPolygon = new Polygon() as ITopologicalOperator; unionedPolygon.ConstructUnion(geometryCollection as IEnumGeometry); Marshal.ReleaseComObject(featureCursor); IPolygon4 pMergerPolygon = unionedPolygon as IPolygon4; IGeometryBag pOutGeometryBag = pMergerPolygon.ExteriorRingBag; //获取外部环 IGeometryCollection pOutGmtyCollection = pOutGeometryBag as IGeometryCollection; for (int i = 0; i < pOutGmtyCollection.GeometryCount; i++) //对外部环遍历 { IGeometry pOutRing = pOutGmtyCollection.get_Geometry(i); //外部环 //【此处可以对外部环进行操作】 IPointCollection pOutRingCollection = pOutRing as IPointCollection; for (int j = 0; j < pOutRingCollection.PointCount; j++) { IPoint pOutRingPoint = pOutRingCollection.get_Point(j);//获取外环上的点 } IGeometryBag pInteriotGeometryBag = pMergerPolygon.get_InteriorRingBag(pOutRing as IRing); //获取内部环 IGeometryCollection pInteriorGeometryCollection = pInteriotGeometryBag as IGeometryCollection; for (int j = 0; j < pInteriorGeometryCollection.GeometryCount; j++) { ISegmentCollection SegCol = pInteriorGeometryCollection.get_Geometry(j) as ISegmentCollection; IPolygon PPolygon = new PolygonClass(); ISegmentCollection newSegCol = PPolygon as ISegmentCollection; newSegCol.AddSegmentCollection(SegCol); //pInteriorGeometry即为多边形的内部环 IGeometry inRing = PPolygon as IGeometry; inRing.SpatialReference = geometryBag.SpatialReference; IArea area = inRing as IArea; Double getarea = System.Math.Abs(Convert.ToDouble(area.Area)); if (inputtext == null || inputtext == "" || getarea < Convert.ToDouble(inputtext)) { Boolean flag = true; ISpatialFilter filter = new SpatialFilterClass(); filter.Geometry = inRing; filter.SubFields = pFClass.OIDFieldName + "," + pFClass.ShapeFieldName; filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor o = pFClass.Search(filter, true); IFeature feature = o.NextFeature(); while (feature != null && flag) { IPolygon4 pPolygon = feature.Shape as IPolygon4; IGeometryBag iOutGeometryBag = pPolygon.ExteriorRingBag; //获取外部环 IGeometryCollection iOutGmtyCollection = iOutGeometryBag as IGeometryCollection; for (int m = 0; m < iOutGmtyCollection.GeometryCount && flag; m++) //对外部环遍历 { IGeometry outGeo = iOutGmtyCollection.get_Geometry(m); IGeometryCollection polyGonGeo = new PolygonClass(); polyGonGeo.AddGeometry(outGeo); IPolygon iPolygon = polyGonGeo as IPolygon; iPolygon.SimplifyPreserveFromTo(); IRelationalOperator2 pRelationalOperator2 = iPolygon as IRelationalOperator2; if (!pRelationalOperator2.Contains(inRing)) { errorCount++; common.GenerateSHPFile(inRing, ErrorFilePath); flag = false; } } feature = o.NextFeature(); } Marshal.ReleaseComObject(o); } } if (errorCount == 0) { string shpFolder = System.IO.Path.GetDirectoryName(ErrorFilePath); IWorkspaceFactory pWorkspaceFac = new ShapefileWorkspaceFactoryClass(); IWorkspace pWorkSpace = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0); IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace; if (System.IO.File.Exists(ErrorFilePath)) { IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath); if (pFCChecker != null) { IDataset pds = pFCChecker as IDataset; pds.Delete(); } } } } } catch (Exception ex) { LogHelper.WriteLog(typeof(TopoChecker), ex); } if (!DicTopoError.ContainsKey(idname)) { DicTopoError.Add(idname, errorCount); } else { DicTopoError[idname] = errorCount; } } else if (IN_RuleType == "面重叠检查") { IFeatureClass outIFC = null; this.m_hookHelper = m_hookHelper; ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); string outString = this.topoDir + "\\" + checkname + idname + ".shp"; intersect.in_features = common.GetPathByName(TABLENAME); intersect.out_feature_class = outString; Geoprocessor geoProcessor = new Geoprocessor(); geoProcessor.OverwriteOutput = true; try { if (this.gp == null) { this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); } IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null); if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { Console.WriteLine("gp工具执行错误"); } else { outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass; } } catch (Exception ex) { LogHelper.WriteLog(typeof(TopoChecker), ex); Console.WriteLine(ex.Message); } if (outIFC.FeatureCount(null) == 0) { string shpFolder = System.IO.Path.GetDirectoryName(ErrorFilePath); IWorkspaceFactory pWorkspaceFac = new ShapefileWorkspaceFactoryClass(); IWorkspace pWorkSpace = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0); IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace; if (System.IO.File.Exists(ErrorFilePath)) { IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath); if (pFCChecker != null) { IDataset pds = pFCChecker as IDataset; pds.Delete(); } } } if (!DicTopoError.ContainsKey(idname)) { DicTopoError.Add(idname, outIFC.FeatureCount(null)); } else { DicTopoError[idname] = outIFC.FeatureCount(null); } } else if (IN_RuleType == "面重叠检查(与其他图层)") { IFeatureClass outIFC = null; this.m_hookHelper = m_hookHelper; ESRI.ArcGIS.AnalysisTools.Intersect intersect = new ESRI.ArcGIS.AnalysisTools.Intersect(); string outString = this.topoDir + "\\" + checkname + idname + ".shp"; intersect.in_features = @common.GetPathByName(TABLENAME) + ";" + @common.GetPathByName(SUPTABLE); intersect.out_feature_class = outString; Geoprocessor geoProcessor = new Geoprocessor(); geoProcessor.OverwriteOutput = true; try { if (this.gp == null) { this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); } IGeoProcessorResult result = (IGeoProcessorResult)this.gp.Execute(intersect, null); if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { Console.WriteLine("gp工具执行错误"); } else { outIFC = this.gp.Open(result.ReturnValue) as IFeatureClass; } } catch (Exception ex) { Console.WriteLine(ex.Message); LogHelper.WriteLog(typeof(TopoChecker), ex); } if (outIFC.FeatureCount(null) == 0) { string shpFolder = System.IO.Path.GetDirectoryName(ErrorFilePath); IWorkspaceFactory pWorkspaceFac = new ShapefileWorkspaceFactoryClass(); IWorkspace pWorkSpace = pWorkspaceFac.OpenFromFile(ErrorFilePath, 0); IFeatureWorkspace pFeatureWorkSpace = pWorkSpace as IFeatureWorkspace; if (System.IO.File.Exists(ErrorFilePath)) { IFeatureClass pFCChecker = pFeatureWorkSpace.OpenFeatureClass(ErrorFilePath); if (pFCChecker != null) { IDataset pds = pFCChecker as IDataset; pds.Delete(); } } } if (!DicTopoError.ContainsKey(idname)) { DicTopoError.Add(idname, outIFC.FeatureCount(null)); } else { DicTopoError[idname] = outIFC.FeatureCount(null); } } Marshal.ReleaseComObject(IN_FeatureClass); if (SUPTABLE != null) { Marshal.ReleaseComObject(IN_Sup_FeatureClass); } }
private static void CoordinatesToPointCollection(XmlNode coordinates, IPointCollection pColl, ISpatialReference sRef) { CoordinatesToPointCollection(coordinates, pColl, ' ', ',', sRef); }
/// <summary> ///鼠标点击操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapcontrol_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { Dwnpoint = new PointClass(); Dwnpoint = this.axMapcontrol.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button != 1) { return; } #region 地图操作 switch (pMouseOperate) { case "区域导出": //删除绘制的图片 this.axMapcontrol.ActiveView.GraphicsContainer.DeleteAllElements(); this.axMapcontrol.ActiveView.Refresh(); IPolygon polygon = DrawPolygon(this.axMapcontrol); if (polygon == null) { return; } ExportMap.AddElement(polygon, this.axMapcontrol.ActiveView); if (polygon == null) { return; } if (exportmapFrm == null || exportmapFrm.IsDisposed) { exportmapFrm = new ExportMapFrm(this.axMapcontrol); exportmapFrm.IsRgion = true; exportmapFrm.GetGeometry = polygon as IGeometry; exportmapFrm.Show(); } exportmapFrm.GetGeometry = polygon; exportmapFrm.IsRgion = true; //获取当前控件焦点 exportmapFrm.Activate(); break; case "MeasureLength": if (m_newline == null) { m_newline = new NewLineFeedbackClass(); m_newline.Display = this.axMapcontrol.ActiveView.ScreenDisplay; m_newline.Start(Dwnpoint); TotalLength = 0; } else { TotalLength += SegmentLength; m_newline.AddPoint(Dwnpoint); } break; case "MeasureArea": if (m_newpolygon == null || Area_Pocoll == null) { m_newpolygon = new NewPolygonFeedbackClass(); Area_Pocoll = new PolygonClass(); m_newpolygon.Display = this.axMapcontrol.ActiveView.ScreenDisplay; m_newpolygon.Start(Dwnpoint); Area_Pocoll.AddPoint(Dwnpoint); TotalLength = 0; } else { m_newpolygon.AddPoint(Dwnpoint); Area_Pocoll.AddPoint(Dwnpoint); TotalLength += SegmentLength; } break; } #endregion }
private static void PosListToPointCollection(XmlNode posList, IPointCollection pColl, ISpatialReference sRef) { PosListToPointCollection(posList, pColl, ' ', sRef); }
public void OnMouseDown(int button, int shift, int x, int y) { try { IPoint pPt = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (m_EngineEditor == null) { return; } if (m_EngineEditor.EditState != esriEngineEditState.esriEngineStateEditing) { return; } if (m_EngineEditLayers == null) { return; } IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } //解决编辑要素的Z值问题 IZAware pZAware = pPt as IZAware; pZAware.ZAware = true; pPt.Z = 0; object missing = Type.Missing; m_Map.ClearSelection(); switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPoint: //当为点层时,直接创建要素 CreateFeature(pPt as IGeometry); break; case esriGeometryType.esriGeometryMultipoint: //点集的处理方式 if (m_pointCollection == null) { m_pointCollection = new MultipointClass(); } else { m_pointCollection.AddPoint(pPt, ref missing, ref missing); } if (m_newMultPtFeedBack == null) { m_newMultPtFeedBack = new NewMultiPointFeedbackClass(); m_newMultPtFeedBack.Display = m_activeView.ScreenDisplay; m_newMultPtFeedBack.Start(m_pointCollection, pPt); } break; case esriGeometryType.esriGeometryPolyline: //多义线处理方式 if (m_newLineFeedBack == null) { m_newLineFeedBack = new NewLineFeedbackClass(); m_newLineFeedBack.Display = m_activeView.ScreenDisplay; m_newLineFeedBack.Start(pPt); } else { m_newLineFeedBack.AddPoint(pPt); } break; case esriGeometryType.esriGeometryPolygon: //多边形处理方式 if (m_newPolyFeedBack == null) { m_newPolyFeedBack = new NewPolygonFeedbackClass(); m_newPolyFeedBack.Display = m_activeView.ScreenDisplay; m_newPolyFeedBack.Start(pPt); } else { m_newPolyFeedBack.AddPoint(pPt); } break; } } catch (Exception ex) { //SysLogHelper.WriteOperationLog("要素创建错误", ex.Source, "数据编辑"); } }
virtual protected IMultiPoint Grabbers(IDisplay display, bool transform) { MultiPoint coll = new MultiPoint(); if (display == null || display.GraphicsContainer == null) { return(coll); } if (display.GraphicsContainer.EditMode == GrabberMode.Pointer) { Envelope env = new Envelope(0, 0, 1, 1); coll.AddPoint(env.UpperLeft); coll.AddPoint(env.UpperRight); coll.AddPoint(env.LowerRight); coll.AddPoint(env.LowerLeft); coll.AddPoint(new Point(env.UpperLeft.X + env.Width / 2, env.UpperLeft.Y)); coll.AddPoint(new Point(env.UpperRight.X, env.LowerRight.Y + env.Height / 2)); coll.AddPoint(new Point(env.LowerLeft.X + env.Width / 2, env.LowerLeft.Y)); coll.AddPoint(new Point(env.LowerLeft.X, env.LowerLeft.Y + env.Width / 2)); double tol = 25.0 * display.mapScale / (96 / 0.0254); // [m] if (display.SpatialReference != null && display.SpatialReference.SpatialParameters.IsGeographic) { tol = 180.0 * tol / Math.PI / 6370000.0; } if (_scaleY > 0) { coll.AddPoint(new Point(env.UpperLeft.X + env.Width / 2, env.UpperLeft.Y + tol / _scaleY)); } else { coll.AddPoint(new Point(env.LowerLeft.X + env.Width / 2, env.LowerLeft.Y + tol / _scaleY)); } } else if (display.GraphicsContainer.EditMode == GrabberMode.Vertex && this is IConstructable && ((IConstructable)this).hasVertices) { IPointCollection pColl = Vertices(_template.Clone() as IGeometry, -1); if (pColl != null) { for (int i = 0; i < pColl.PointCount; i++) { coll.AddPoint(pColl[i]); } } } if (transform) { ScaleGeometry(coll, _scaleX, _scaleY); RotateGeometry(coll, Math.Cos(_angle), Math.Sin(_angle)); TranslateGeometry(coll, _xOffset, _yOffset); } return(coll); }
//private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) //{ // IPoint ipNew = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); // this.ribbonBar1.Text = "当前在地图上的坐标为 X:" + Convert.ToString(e.x) + " Y:" + Convert.ToString(e.y); //} private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e) { if (areaprocess.Checked) { IGraphicsContainer pgraghicscontainer = axMapControl1.Map as IGraphicsContainer; IActiveView pactiveview = pgraghicscontainer as ESRI.ArcGIS.Carto.IActiveView; IPoint ipNew; if (ippoints == null) ippoints = new MultipointClass(); ipNew = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); object o = Type.Missing; ippoints.AddPoint(ipNew, ref o, ref o); createpolygon(ippoints); if (ipPolyResult != null) { drawpolygon(ipPolyResult); } drawpoints(ippoints); } }
/// <summary> /// 获得查询结果信息 /// </summary> /// <params name="pGeometry">点</params> /// <params name="hdids">巷道ID</params> /// <params name="kind">表示巷道掘进还是回采掘进</params> /// <returns></returns> public Dictionary <string, List <GeoStruct> > GetStructsInfosNew(IPoint pGeometry, List <int> hdids = null, int kind = 1) { #region /* * 根据工作面中点坐标,查询对应的掘进面或者回采面的信息 */ List <IPoint> pgeompts = CalculateCirclePnts(pGeometry as IPoint, 1); IPolygon pgeom = Global.commonclss.CreatePolygonFromPnts(pgeompts, Global.spatialref); IFeatureCursor feahds = null; IFeature feahd = null; if (kind == 1) { feahds = SpatialSearch(pgeom, "1=1", Global.hdfdfulllyr, esriSpatialRelEnum.esriSpatialRelIntersects);//查询巷道分段 feahd = feahds.NextFeature(); } else { feahds = SpatialSearch(pgeom, "1=1", Global.hcqlyr, esriSpatialRelEnum.esriSpatialRelIntersects);//查询回采工作面 feahd = feahds.NextFeature(); } IGeometry geomsearch = feahd.Shape; IHitTest hitest = geomsearch as IHitTest; ESRI.ArcGIS.Geometry.IPoint hitPoint = new ESRI.ArcGIS.Geometry.PointClass(); System.Double hitDistance = 0; System.Int32 hitPartIndex = 0; System.Int32 hitSegmentIndex = 0; System.Boolean rightSide = false; bool findgeom = hitest.HitTest(pGeometry, 1, esriGeometryHitPartType.esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide); IPolyline plingeom = new PolylineClass(); if (findgeom == true) { IPolygon polygon = geomsearch as IPolygon; IPointCollection pnts = polygon as IPointCollection; IPoint pntstart = pnts.get_Point(hitSegmentIndex); IPoint pntend = pnts.get_Point(hitSegmentIndex + 1); plingeom.FromPoint = pntstart; plingeom.ToPoint = pntend; } #endregion Dictionary <string, List <GeoStruct> > results = new Dictionary <string, List <GeoStruct> >(); //峒室 1 List <GeoStruct> dss = BufferAnalyseNew(plingeom, Global.searchlen, Global.dslyr, geomsearch); results.Add("1", dss); //揭露断层 2 List <GeoStruct> jls = BufferAnalyseNew(plingeom, Global.searchlen, Global.jllyr, geomsearch); results.Add("2", jls); //推断断层 3 List <GeoStruct> tds = BufferAnalyseNew(plingeom, Global.searchlen, Global.tdlyr, geomsearch); results.Add("3", tds); //钻孔 4 List <GeoStruct> zks = BufferAnalyseNew(plingeom, Global.searchlen, Global.zklyr, geomsearch); results.Add("4", zks); //陷落柱 5 List <GeoStruct> xlzs = BufferAnalyseNew(plingeom, Global.searchlen, Global.xlzlyr, geomsearch); results.Add("5", xlzs); //陷落柱1 6 List <GeoStruct> xlz1s = BufferAnalyseNew(plingeom, Global.searchlen, Global.xlzlyr1, geomsearch); results.Add("6", xlz1s); //井筒 7 List <GeoStruct> jts = BufferAnalyseNew(plingeom, Global.searchlen, Global.jtlyr, geomsearch); results.Add("7", jts); //巷道层 8 //List<GeoStruct> hds = BufferAnalyseNew(plingeom, Global.searchlen, Global.hdfdfulllyr, geomsearch); //for (int i = 0; i < hds.Count; i++) //{ // GeoStruct geostruct = hds[i]; // if (hdids != null) // { // for (int j = 0; j < hdids.Count; j++) // { // if (geostruct.geoinfos[GIS_Const.FIELD_HdId].ToString() == hdids[j].ToString()) // { // hds.Remove(geostruct); // i--; // } // } // } //} //results.Add("8", hds); return(results); }
private void createpolygon(IPointCollection ippoints) { ISegmentCollection ppath = new PathClass(); IGeometryCollection ppolyline = new PolylineClass(); if (ippoints.PointCount >= 3) { int i; object o = Type.Missing; if (ippoints.PointCount >= 4) { ippoints.RemovePoints(ippoints.PointCount - 2, 1); } ippoints.AddPoint(ippoints.get_Point(0)); for (i = 0; i < ippoints.PointCount - 1; i++) { ILine pline = new LineClass(); pline.PutCoords(ippoints.get_Point(i), ippoints.get_Point(i + 1)); ISegment psegment = pline as ISegment; ppath.AddSegment(psegment, ref o, ref o); ppolyline.AddGeometry(ppath as IGeometry, ref o, ref o); } ipPolyResult = ppolyline as IPolyline; ISegmentCollection pRing = new RingClass(); IGeometryCollection pGeometryColl = new PolygonClass(); for (int j = 0; j < ppolyline.GeometryCount; j++) { pRing.AddSegmentCollection(ppolyline.get_Geometry(j) as ISegmentCollection); pGeometryColl.AddGeometry(pRing as IGeometry, ref o, ref o); } ipolygon = pGeometryColl as IPolygon; } }
public Dictionary <string, List <IPoint> > getCoordinates(IPolygon polygon, IPolyline plin1, IPolyline plin2, IPolyline plin3, double hdwid1, double hdwid2) { Dictionary <string, List <IPoint> > res = new Dictionary <string, List <IPoint> >(); IPointCollection pnts = polygon as IPointCollection; int index = 1; for (int i = 0; i < pnts.PointCount - 1; i++) { IPolyline plinnew = new PolylineClass(); plinnew.SpatialReference = Global.spatialref; plinnew.FromPoint = new PointClass() { X = pnts.get_Point(i).X, Y = pnts.get_Point(i).Y }; plinnew.ToPoint = new PointClass() { X = pnts.get_Point(i + 1).X, Y = pnts.get_Point(i + 1).Y }; ITopologicalOperator top1 = plin1 as ITopologicalOperator; IGeometry geom1 = top1.Buffer(hdwid1); IRelationalOperator relationOp1 = geom1 as IRelationalOperator; bool bres1 = relationOp1.Contains(plinnew); if (bres1) { continue; } ITopologicalOperator top2 = plin2 as ITopologicalOperator; IGeometry geom2 = top2.Buffer(hdwid2); IRelationalOperator relationOp2 = geom2 as IRelationalOperator; bool bres2 = relationOp2.Contains(plinnew); if (bres2) { continue; } List <IPoint> curpnts = new List <IPoint>(); curpnts.Add(pnts.get_Point(i)); curpnts.Add(pnts.get_Point(i + 1)); res.Add(index.ToString(), curpnts); index++; } //处理顺序 IPoint pntCenter = new PointClass() { X = (plin3.Envelope.XMax + plin3.Envelope.XMin) / 2, Y = (plin3.Envelope.YMax + plin3.Envelope.YMin) / 2 }; IPolyline plin0 = new PolylineClass(); plin0.SpatialReference = Global.spatialref; plin0.FromPoint = res["1"][0]; plin0.ToPoint = res["1"][1]; double dist0 = 0.0, dist1 = 0.0; bool isrightside = false; IPoint pntquery = null; plin0.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pntCenter, false, pntquery, ref dist0, ref dist1, ref isrightside); IPolyline plin00 = new PolylineClass(); plin00.SpatialReference = Global.spatialref; plin00.FromPoint = res["2"][0]; plin00.ToPoint = res["2"][1]; double dist00 = 0.0, dist10 = 0.0; bool isrightside0 = false; IPoint pntquery0 = null; plin00.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pntCenter, false, pntquery0, ref dist00, ref dist10, ref isrightside0); if (dist10 > dist1) { List <IPoint> tmppnts = res["2"]; res["2"] = res["1"]; res["1"] = tmppnts; } return(res); }
private void drawpoints(IPointCollection ippoints) { IGraphicsContainer pgraghicscontainer = axMapControl1.Map as IGraphicsContainer; IActiveView pactiveview = pgraghicscontainer as ESRI.ArcGIS.Carto.IActiveView; //设定路径颜色 IRgbColor pcolor = new RgbColorClass(); pcolor.Red = 255; pcolor.Green = 0; pcolor.Blue = 0; pcolor.Transparency = 100; //设置线格式 ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = pcolor; simpleMarkerSymbol.Size = 4; //绘出路径线 IScreenDisplay screenDisplay = pactiveview.ScreenDisplay; ISymbol symbol = (ISymbol)simpleMarkerSymbol; screenDisplay.StartDrawing(screenDisplay.hDC, System.Convert.ToInt16(esriScreenCache.esriNoScreenCache)); screenDisplay.SetSymbol(symbol); int i; for (i = 0; i < ippoints.PointCount; i++) { screenDisplay.DrawPoint(ippoints.get_Point(i)); } screenDisplay.FinishDrawing(); }
private void buttonX_ok_Click(object sender, EventArgs e) { //add all point List <IPoint> pointList = new List <IPoint>(); //add point type List <string> typeList = new List <string>(); //read excel file to creat Field string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxX1.Text + ";Extended Properties=Excel 8.0"; OleDbConnection conn = new OleDbConnection(strCon); string sql1 = "select * from [Sheet1$]"; conn.Open(); OleDbDataAdapter myCommand = new OleDbDataAdapter(sql1, strCon); DataSet ds = new DataSet(); myCommand.Fill(ds); conn.Close(); ISpatialReference pSpaReference = new UnknownCoordinateSystemClass(); pSpaReference.SetDomain(-8000000, 8000000, -800000, 8000000); IFeatureClass pFt = CreateShapeFile(ds, this.textBoxX2.Text, pSpaReference); int xindex = 18; int yindex = 19; int zindex = 20; if (ds.Tables[0].Columns[19].ColumnName.ToString().Contains("东坐标")) { xindex++; yindex++; zindex++; } if (pFt == null) { return; } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //get type string typeTemp = ds.Tables[0].Rows[i][3].ToString(); typeTemp = typeTemp.Split(new char[1] { ' ' })[0]; //根据XY坐标添加点,edit attribute IsNumberic isNum = new IsNumberic(); IPoint pPoint = new PointClass(); if (isNum.IsNumber(ds.Tables[0].Rows[i][xindex].ToString()) && isNum.IsNumber(ds.Tables[0].Rows[i][yindex].ToString())) { pPoint.X = System.Convert.ToDouble(ds.Tables[0].Rows[i][xindex].ToString()); pPoint.Y = System.Convert.ToDouble(ds.Tables[0].Rows[i][yindex].ToString()); pPoint.Z = System.Convert.ToDouble(ds.Tables[0].Rows[i][zindex].ToString()); IFeature pFeature = pFt.CreateFeature(); pFeature.Shape = pPoint; pFeature.Store(); for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { //pFeature.set_Value(pFeature.Fields.FindField(ds.Tables[0].Columns[j].ColumnName), ds.Tables[0].Rows[i][j]); pFeature.set_Value(j + 2, ds.Tables[0].Rows[i][j].ToString()); } pFeature.set_Value(pFeature.Fields.FindField("Type"), typeTemp); pFeature.Store(); pointList.Add(pPoint); } else { MessageBox.Show("the" + i + "rows x and y value is unvalid!"); } } } ClsGDBDataCommon processDataCommon = new ClsGDBDataCommon(); string strInputPath = System.IO.Path.GetDirectoryName(textBoxX2.Text); string strInputName = System.IO.Path.GetFileName(textBoxX2.Text); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFt; pFeatureLayer.Name = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileNameWithoutExtension(strInputName)) + "_point"; //create line shape file IPointCollection PointCollection = ReadPoint(pFeatureLayer); string lineName = strInputPath + "\\" + System.IO.Path.GetFileNameWithoutExtension(strInputName) + "_line.shp"; CreateLineShpFile(lineName, pSpaReference); //将所有的点连接成线 List <IPolyline> Polyline = CreatePolyline(PointCollection); List <double> lineLengthList = new List <double>(); //将连接成的线添加到线图层中 string pLineFile = lineName; string pFilePath = System.IO.Path.GetDirectoryName(pLineFile); string pFileName = System.IO.Path.GetFileName(pLineFile); //打开工作空间 IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0); //写入实体对象 IFeatureLayer plineLayer = new FeatureLayerClass(); plineLayer.FeatureClass = pWS.OpenFeatureClass(pFileName); AddFeature(plineLayer, Polyline, pointList, lineLengthList); plineLayer.Name = pFeatureLayer.Name + "_line"; m_pMapCtl.AddLayer(plineLayer as ILayer, 0); m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0); m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); ImpSymbolFromFile(textBoxX3.Text, pFeatureLayer, plineLayer); //export doc file string TemplateFileName = ClsGDBDataCommon.GetParentPathofExe() + @"Resource\WordTemplate\内检测报告.doc"; exportDocFile(TemplateFileName, textBoxX4.Text, lineLengthList); //#region 读取SHP文件 //IWorkspace pWorkspace = processDataCommon.OpenFromShapefile(strInputPath); //IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; //IFeatureClass pInputFC = pFeatureWorkspace.OpenFeatureClass(strInputName); //#endregion //IFeatureLayer pFeatureLayer = new FeatureLayerClass(); //pFeatureLayer.FeatureClass = pInputFC; //pFeatureLayer.Name = strInputName; //m_pMapCtl.AddLayer(pFeatureLayer as ILayer, 0); //m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); this.Close(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 2) return; IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pt = GIS.GraphicEdit.SnapSetting.getSnapPoint(pt); IGraphicsContainer graphicContainer = m_hookHelper.ActiveView.GraphicsContainer; IEnvelope pEnvBounds = null; //��ȡ��һ�ι켣�ߵķ�Χ,�Ա�ȷ��ˢ�·�Χ try { if (m_TracePolygon != null) { m_TracePolygon.QueryEnvelope(pEnvBounds); pEnvBounds.Expand(4, 4, true); //���ο�����������4��(����2������),Ŀ����Ϊ�˱�֤�г����ˢ������ } else pEnvBounds = m_hookHelper.ActiveView.Extent; } catch { pEnvBounds = m_hookHelper.ActiveView.Extent; } #region ������� if (m_NewPolygonFeedback == null) { //�Ƴ�element RemoveElements(); //ˢ�� m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); Application.DoEvents(); m_NewPolygonFeedback = new NewPolygonFeedbackClass(); //�����ȵõ�symbol,������symbol ISimpleLineSymbol simpleLineSymbol = m_NewPolygonFeedback.Symbol as ISimpleLineSymbol; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 2; simpleLineSymbol.Color = TransColorToAEColor(Color.Blue); m_simpleFillSymbol.Outline = simpleLineSymbol; m_NewPolygonFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay; m_NewPolygonFeedback.Start(pt); } else { m_NewPolygonFeedback.AddPoint(pt); } if (m_ptCollection == null) { m_ptCollection = new PolylineClass(); } //��¼�ڵ� object obj = Type.Missing; m_ptCollection.AddPoint(pt, ref obj, ref obj); #endregion #region ���ƽ�� try { IElement vertexElement = createElement_x(pt); // graphicContainer = m_hookHelper.ActiveView as IGraphicsContainer; //g.AddElement(vertexElement, 0); //g.MoveElementToGroup(vertexElement, m_VertexElement); m_VertexElement.AddElement(vertexElement); //ˢ�� m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, vertexElement, pEnvBounds); } catch { } #endregion try { if (m_ptCollection.PointCount >= 2) { IPoint fromPt = m_ptCollection.get_Point(m_ptCollection.PointCount - 2); //�����ڶ����� IPoint toPt = m_ptCollection.get_Point(m_ptCollection.PointCount - 1); //����һ���� ILine line = new LineClass(); line.PutCoords(fromPt, toPt); #region ���ƹ켣�� try { object missing = Type.Missing; ISegmentCollection segColl = new PolylineClass(); segColl.AddSegment(line as ISegment, ref missing, ref missing); IPolyline polyline = new PolylineClass(); polyline = segColl as IPolyline; IElement traceElement = createElement_x(polyline); //graphicContainer = m_hookHelper.ActiveView as IGraphicsContainer; m_TraceElement.AddElement(traceElement); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, traceElement, pEnvBounds); } catch { } #endregion #region ���㵥�ߵij���,���������ʾ�ڵ����е�ƫ������ //try //{ // double angle = line.Angle; // if ((angle > (Math.PI / 2) && angle < (Math.PI)) || (angle > -Math.PI && angle < -(Math.PI / 2))) // ����90��С�ڵ���180 // angle += Math.PI; // //��ע��Yֵƫ���� // double d_OffsetY = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints(9); // //��ע�� // double d_CenterX = (fromPt.X + toPt.X) / 2; // double d_CenterY = (fromPt.Y + toPt.Y) / 2 + d_OffsetY; //����ƫ�� // IPoint labelPt = new PointClass(); // labelPt.PutCoords(d_CenterX, d_CenterY); // ITextElement txtElement = CreateTextElement(line.Length.ToString("0.00")); // IElement labelelement = txtElement as IElement; // labelelement.Geometry = labelPt; // object oElement = (object)labelelement; // //���ݽǶ���ת // TransformByRotate(ref oElement, labelPt, angle); // ////��ӵ�GraphicsContainer // //g.AddElement(labelelement, 0); // ////�Ƶ�m_LabelElement���� // //g.MoveElementToGroup(labelelement, m_LabelElement); // //��ӵ��� // m_LabelElement.AddElement(labelelement); // //ˢ�� // m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, labelelement, pEnvBounds); //} //catch //{ } #endregion } } catch { } m_frmMeasureResult.PolygonResultChange(); }
private void DrawSectionPart() { try { if (m_SectionLine == null) { return; } if (m_SurFace == null) { return; } IGeometry pGeometry = new PolylineClass(); object pObject = 1; m_SurFace.InterpolateShape(m_SectionLine, out pGeometry, ref pObject); IGroupElement pGroup = null; ////用于绘制三维效果 ClsMarkDraw.AddSimpleGraphic(pGeometry, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_pMapControlDefault.Map, pGroup); m_pMapControlDefault.Refresh(esriViewDrawPhase.esriViewBackground, null, null); double dblLength; object StepSize = Type.Missing;; m_SurFace.QuerySurfaceLength(pGeometry, out dblLength, ref StepSize); txtSurfaceLengh.Text = dblLength.ToString(); IPolyline pLine = pGeometry as IPolyline; txtPreject.Text = pLine.Length.ToString(); txtZmax.Text = pLine.Envelope.ZMax.ToString(); txtZmin.Text = pLine.Envelope.ZMin.ToString(); IPointCollection pPointCol = pLine as IPointCollection; IPolyline pPolyline2; IPointCollection pPointCol2 = new PolylineClass(); int lLOOP; double dblminY, dblPery, dblPerx, dblMaxY; dblminY = pLine.Envelope.ZMin; dblMaxY = pLine.Envelope.ZMax; if ((pLine.Envelope.ZMax - pLine.Envelope.ZMin) == 0) { return; } if (pLine.Length == 0) { return; } //重新绘制底图 Image pImage = new Bitmap(442, 230); Graphics m_mouse = Graphics.FromImage(pImage); //m_mouse.FillRectangle(Brushes.White,0,0,460,240); Pen pen1 = new Pen(Color.Black, 1); //绘制横坐标、纵坐标及其他两条边 m_mouse.DrawLine(pen1, new PointF(55, 210), new PointF(55, 6)); m_mouse.DrawLine(pen1, new PointF(55, 210), new PointF(431, 210)); m_mouse.DrawLine(pen1, new PointF(55, 6), new PointF(431, 6)); m_mouse.DrawLine(pen1, new PointF(431, 6), new PointF(431, 210)); //Brush pBrush = new HatchBrush(HatchStyle.Percent70, Color.WhiteSmoke); m_mouse.FillRectangle(Brushes.White, 56, 7, 375, 203); //填充区域及背景图 // dblPery = 200 / (pLine.Envelope.ZMax - pLine.Envelope.ZMin); //将纵坐标的高度分线段的高程差段 dblPerx = 368 / pLine.Length; //将横坐标的宽度分成线段长度份 double x, y, x1, y1; x = 0; y = 0; object before = Type.Missing; object after = Type.Missing; Pen pen3 = new Pen(Color.Red, 2); Font drawFont = new Font("宋体", 8.0f, FontStyle.Regular); StringFormat drawFormat = new StringFormat(); Brush drawBrush = new SolidBrush(Color.Black); drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl; //绘制横坐标刻度值 for (int i = 0; i <= 4; i++) { if (i == 0) { m_mouse.DrawString(i.ToString(), drawFont, Brushes.Black, new PointF(52, 214), drawFormat); } else { Single Lenvlae = Convert.ToSingle((pLine.Length / 4) * i); m_mouse.DrawLine(pen1, new PointF(55 + 92 * i, 210), new PointF(55 + 92 * i, 214)); m_mouse.DrawString(Lenvlae.ToString(), drawFont, drawBrush, new PointF(20 + 92 * i, 215), drawFormat); } } //绘制纵坐标刻度值 for (int i = 1; i <= 10; i++) { m_mouse.DrawLine(pen1, new PointF(55, 210 - 20 * i), new PointF(51, 210 - 20 * i)); Pen pen = new Pen(Color.Black, 1); pen.DashStyle = DashStyle.Dot; m_mouse.DrawLine(pen, new PointF(55, 210 - 20 * i), new PointF(431, 210 - 20 * i)); Single Lenvlae = Convert.ToSingle((((dblMaxY - dblminY) / 10) * i) + dblminY); m_mouse.DrawString(Lenvlae.ToString(), drawFont, Brushes.Black, new PointF(1, 210 - 21 * i), drawFormat); } for (lLOOP = 0; lLOOP < pPointCol.PointCount; lLOOP++) { pPointCol2.AddPoint(pPointCol.get_Point(lLOOP), ref before, ref after); pPolyline2 = pPointCol2 as IPolyline; x1 = pPolyline2.Length * dblPerx + 57; //37为坐标图在pictureBox1中离左边的距离 y1 = 210 - ((pPointCol.get_Point(lLOOP).Z - pLine.Envelope.ZMin) * dblPery); if (lLOOP == 0) //绘制起点 { SolidBrush pSolidBrush = new SolidBrush(Color.Blue); m_mouse.FillEllipse(pSolidBrush, Convert.ToSingle(x1 - 2), Convert.ToSingle(y1 - 2), 6, 6); } if (lLOOP > 0) { //绘制沿线高程变化线 m_mouse.DrawLine(pen3, new PointF(Convert.ToSingle(x), Convert.ToSingle(y)), new PointF(Convert.ToSingle(x1), Convert.ToSingle(y1))); } if (lLOOP == pPointCol.PointCount - 1)//绘制终点 { SolidBrush pSolidBrush = new SolidBrush(Color.Green); m_mouse.FillEllipse(pSolidBrush, Convert.ToSingle(x1 - 2), Convert.ToSingle(y1 - 2), 6, 6); } x = x1; y = y1; } pictureBox1.Image = pImage; m_mouse.Dispose(); drawFont.Dispose(); drawBrush.Dispose(); } catch { return; } }
private void buildPolygon(IPointCollection pGonColl, double x, double y) { m_workPts[0].PutCoords(x - 500, y - 500); m_workPts[1].PutCoords(x + 500, y - 500); m_workPts[2].PutCoords(x + 500, y + 500); m_workPts[3].PutCoords(x - 500, y + 500); m_workPts[4].PutCoords(x - 500, y - 500); try { bool add = (pGonColl.PointCount == 0); object missingVal = System.Reflection.Missing.Value; for (int i = 0; i< m_workPts.Length; i++) { ((IZAware)m_workPts[i]).ZAware = m_bZ; ((IMAware)m_workPts[i]).MAware = m_bM; if (m_bM) m_workPts[i].M = i % 4; if (m_bZ) m_workPts[i].Z = (i % 4) * 100; //match start and end points if (add) pGonColl.AddPoint(m_workPts[i], ref missingVal, ref missingVal); //The Add method only accepts either a before index or an after index. else pGonColl.UpdatePoint(i, m_workPts[i]); } } catch (Exception Ex) {System.Diagnostics.Debug.WriteLine(Ex.Message);} //Attempted to store an element of the incorrect type into the array. }
private void btOK_Click(object sender, EventArgs e) { if (cboBoxPointLayer.SelectedItem == null) { MessageBox.Show("请加载点图层!"); return; } if (txtLineFilePath.Text == "") { MessageBox.Show("请输入要输出线图层的路径及名称!"); return; } try { //从点图层中读取所有点 string pPointFileName = cboBoxPointLayer.SelectedItem.ToString(); ILayer pLayer = null; for (int i = 0; i < pMapcontrol.LayerCount; i++) { if (pPointFileName == pMapcontrol.get_Layer(i).Name) { pLayer = pMapcontrol.get_Layer(i); } } psf = ((IGeoDataset)pLayer).SpatialReference; IFeatureLayer pFeatureLayerPoint = pLayer as IFeatureLayer; IPointCollection PointCollection = ReadPoint(pFeatureLayerPoint); //判断需要生成的线文件是否存在,若不存在则创建文件,若存在则将新添加的线写入文件 if (File.Exists(txtLineFilePath.Text)) { //若已经存在则读取结尾点并加入到PointCollection string pLineFile = txtLineFilePath.Text; string pFilePath = System.IO.Path.GetDirectoryName(pLineFile); string pFileName = System.IO.Path.GetFileName(pLineFile); //打开工作空间 IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(pFilePath, 0); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pWS.OpenFeatureClass(pFileName); IField pField = null; if (pFeatureLayer.FeatureClass.Fields.FindField("FID") != -1) { pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("FID")); } else if (pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID") != -1) { pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID")); } //第一个属性字段名称 string FirstFieldName = pField.AliasName; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = FirstFieldName + ">=0"; int number = pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter); IFeature pFeature; if (FirstFieldName == "FID") { pFeature = pFeatureLayer.FeatureClass.GetFeature(number - 1); } else { pFeature = pFeatureLayer.FeatureClass.GetFeature(number); } IGeometry pGeometry = pFeature.Shape as IGeometry; IPolyline pPolyline = pGeometry as IPolyline; IPointCollection pPointCollection = new MultipointClass(); pPointCollection.AddPoint(pPolyline.ToPoint); PointCollection.InsertPointCollection(0, pPointCollection); } else { //不存在则创建新的线图层 CreateNewLineLayer(); } //将所有的点连接成线 IPolyline Polyline = CreatePolyline(PointCollection); //将连接成的线添加到线图层中 AddFeature(Polyline as IGeometry); this.Close(); } catch { MessageBox.Show(e.ToString()); } }
private static StringBuilder aoPolyToWtkHelper(IPointCollection points, bool isPolygon) { IEnumVertex vertices = points.EnumVertices; StringBuilder sbMain = new StringBuilder("("); IPoint p; IPoint firstInPart = new PointClass(); int pIdx; int vIdx; int pIdxCurr = 0; // The current part index. StringBuilder sbPart = new StringBuilder(); while ((p = nextPoint(vertices, out pIdx, out vIdx)) != null) { // Have we gotten a new part? // If so, close it out. if (pIdx != pIdxCurr) { // We need to close this ring if it's a polygon. if (isPolygon) { aoPolyToWktAddPoint(sbPart, firstInPart); replaceLastChar(sbPart, ')'); } aoPolyToWktAddPart(sbMain, sbPart); sbMain.Append(","); sbPart = new StringBuilder(); pIdxCurr = pIdx; } aoPolyToWktAddPoint(sbPart, p); // Save the first point in each part to later close polygons. if (vIdx == 0) firstInPart.PutCoords(p.X, p.Y); } // Close the last part of a polygon. if (isPolygon) aoPolyToWktAddPoint(sbPart, firstInPart); aoPolyToWktAddPart(sbMain, sbPart); sbMain.Append(")"); return sbMain; }
//功能描述:根据坐标串生成一个polygon //参数列表: sCoordinate (String) // pSpatialReference (ISpatialReference) public static IPolygon GetPolygonByCoordinate(string sCoordinate, ISpatialReference pSpatialReference) { string sRealCoordinate = null; int i = 0; string sValue = null; IPolygon pPolygon = default(IPolygon); IPointCollection pPntCol = default(IPointCollection); IPoint pPnt = default(IPoint); string x = null; string y = null; string[] sArray = null; string[] sCoordArray = null; ITopologicalOperator2 pTopoOperator = default(ITopologicalOperator2); if (pSpatialReference == null) { return(null); } pPolygon = null; try { if (!string.IsNullOrEmpty(Strings.Trim(sCoordinate))) { if (Strings.InStr(sCoordinate, "(", CompareMethod.Text) > 0 & Strings.InStr(sCoordinate, ")", CompareMethod.Text) > 0 & Strings.InStr(sCoordinate, ",", CompareMethod.Text) > 0) { //去掉坐标窜中的空格 sRealCoordinate = ""; for (i = 1; i <= Strings.Len(sCoordinate); i++) { sValue = Strings.Mid(sCoordinate, i, 1); if (!string.IsNullOrEmpty(Strings.Trim(sValue))) { if (string.IsNullOrEmpty(Strings.Trim(sRealCoordinate))) { sRealCoordinate = sValue; } else { sRealCoordinate = sRealCoordinate + sValue; } } } pPntCol = new Polygon(); //说明有多个坐标对 if (Strings.InStr(sRealCoordinate, "),", CompareMethod.Text) > 0) { //sArray = Strings.Split(sRealCoordinate, "),"); sArray = sRealCoordinate.Split(new char[] { ')' }); if (Information.UBound(sArray, 1) > 1) { for (i = 0; i <= Information.UBound(sArray, 1); i++) { sValue = sArray[i]; //分解后的坐标解析式:(x,y, 最后一项(x,y) if (Strings.InStr(sValue, "(", CompareMethod.Text) > 0 && Strings.InStr(sValue, ",", CompareMethod.Text) > 0) { //sCoordArray = Strings.Split(sValue, ","); sCoordArray = sValue.Split(new char[] { ',' }); if (Information.UBound(sCoordArray, 1) == 1) { pPnt = new Point(); pPnt.Project(pSpatialReference); x = sCoordArray[0]; x = Convert.ToString(Convert.ToDouble(Strings.Right(x, Strings.Len(x) - 1))); y = sCoordArray[1]; if (i == Information.UBound(sArray, 1)) { y = Strings.Left(y, Strings.Len(y) - 1); } pPnt.PutCoords(Convert.ToDouble(x), Convert.ToDouble(y)); object missing = Type.Missing; pPntCol.AddPoint(pPnt, ref missing, ref missing); //只要有一个点的坐标形式出错,就退出 } else { return(null); } } else { return(null); } } pTopoOperator = (ITopologicalOperator2)pPntCol; pTopoOperator.Simplify(); pPolygon = (IPolygon)pTopoOperator; pPolygon.Project(pSpatialReference); return(pPolygon); } } } } return(pPolygon); } catch { return(null); } }
/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { try { //是否为AEditor的编辑状态 if (TheReferenceInstances.TheAEditer.PrepareEditor() == false) return; //初始化IDisplayFeedback和pointColl //if (_geometryFeedback == null) //{ if (_subType == 1) { _geometryFeedback = new NewLineFeedbackClass(); _pointColl = new PolylineClass(); } else if(_subType == 2) { _geometryFeedback = new NewPolygonFeedbackClass(); _pointColl = new PolygonClass(); } //} //初始化对应关联值 TheReferenceInstances.TheAEditer.SketchEdit.DrawTool = this; TheReferenceInstances.TheAEditer.SketchEdit.PntColl = _pointColl; TheReferenceInstances.TheAEditer.StructSnapOption.IsHaveSnap = true; TheReferenceInstances.TheAEditer.StructSnapOption.Tolerance = 20; TheReferenceInstances.CurrentTool = this; TheReferenceInstances.TheAEditer.CurTask = _alterType; _startPoint = null; _endPoint = null; //设置当前工具为this if (myHook.Hook is IMapControl3) { (myHook.Hook as IMapControl3).CurrentTool = this; if (_subType == 1) (_geometryFeedback as INewLineFeedback).Display = myHook.ActiveView.ScreenDisplay; else if(_subType == 2) (_geometryFeedback as INewPolygonFeedback).Display = myHook.ActiveView.ScreenDisplay; } else if (myHook.Hook is IPageLayoutControl2) { (myHook.Hook as IPageLayoutControl2).CurrentTool = this; if (_subType == 1) (_geometryFeedback as INewLineFeedback).Display = (myHook.FocusMap as IActiveView).ScreenDisplay; else if(_subType == 2) (_geometryFeedback as INewPolygonFeedback).Display = (myHook.FocusMap as IActiveView).ScreenDisplay; } //右键菜单及Cursor this.m_cursor = Cursors.Cross; InitialRightMenu(); } catch (System.Exception e) { XtraMessageBox.Show(String.Format("初始化变更工具失败!\n{0}", e.Message), "警告", MessageBoxButtons.OK); } }
public void Analyse_Hit(IFeatureCursor pFeaCursor) { double num; double double0 = this.double_0 * 0.0005; double double1 = this.double_1 * 0.0005; ITopologicalOperator ipolyline1 = (ITopologicalOperator)this.baselineSimpleLine; IProximityOperator proximityOperator = (IProximityOperator)this.baselineSimpleLine; IPointCollection ipolyline0 = (IPointCollection)this.baselineShape; int qdgcIdx = -1; int qdmsIdx = -1; int zdgcIdx = -1; int zdmsIdx = -1; double z = ipolyline0.get_Point(0).Z; double num1 = z; for (int i = 1; i < ipolyline0.PointCount; i++) { double z1 = ipolyline0.get_Point(i).Z; if (z > z1) { z = z1; } if (num1 < z1) { num1 = z1; } } if (this.heightType == 0) { z = z - double0; num1 = num1 - double0; } else if (2 == this.heightType) { z = z + double0; num1 = num1 + double0; } IFeature feature = pFeaCursor.NextFeature(); if (feature == null) { return; } IBasicLayerInfo lineConfig = m_config.GetBasicLayerInfo(feature.Class.AliasName) as IBasicLayerInfo; int num2 = -1; int num3 = -1; int num4 = -1; if (feature != null) { num2 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ)); num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC)); num4 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ)); if (!IsMUsing) { qdgcIdx = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDGC)); qdmsIdx = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDMS)); zdgcIdx = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDGC)); zdmsIdx = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDMS)); } } if (num4 >= 0) { if ((num2 >= 0 ? true : num3 >= 0)) { //!+ 要判断lineConfigHeightFlag 和 enumPipelineHeightType的对应关系 int lineConfigHeightFlag = (int)lineConfig.HeightType; //this.m_app.PipeConfig.getLineConfig_HeightFlag(CommonUtils.GetSmpClassName(feature.Class.AliasName)); while (feature != null) { IPolyline shape = feature.Shape as IPolyline; IPolyline polyline = this.SimplifyPolyline(shape); double num5 = 0; double num6 = this.GetPipeGJ(feature, num2, num3, out num5); if (num6 < 10) { num6 = 10; } num6 = num6 * 0.0005; if (num5 < 10) { num5 = 10; } num5 = num5 * 0.0005; IPoint point = null; IGeometry geometry = ipolyline1.Intersect(polyline, (esriGeometryDimension)1); if (geometry != null) { if (geometry is IPoint) { point = (IPoint)geometry; } else if (geometry is IMultipoint) { IPointCollection pointCollection = (IPointCollection)geometry; if (pointCollection.PointCount > 0) { point = pointCollection.get_Point(0); } } } if (point == null) { CHitAnalyse.CItem cItem = new CHitAnalyse.CItem(); string str = feature.get_Value(num4).ToString(); cItem._OID = feature.OID; cItem._sKind = str; cItem._pClass = (IFeatureClass)feature.Class; num = proximityOperator.ReturnDistance(polyline); num = num - double1 - num6; if (num >= 0.001) { cItem._dHorDistance = num; cItem._dHorBase = 0; IPointCollection pointCollection1 = (IPointCollection)shape; double z2; if (IsMUsing) { z2 = pointCollection1.get_Point(0).Z - pointCollection1.get_Point(0).M; } else { double pHeight = 0; z2 = GetDoubleValue(feature, qdgcIdx, out pHeight) - GetDoubleValue(feature, qdmsIdx, out pHeight); } double num7 = z2; if (IsMUsing) { for (int j = 1; j < pointCollection1.PointCount; j++) { double z3 = pointCollection1.get_Point(j).Z - pointCollection1.get_Point(j).M; if (z2 > z3) { z2 = z3; } if (num7 < z3) { num7 = z3; } } } else { double pHeight = 0; double z3 = GetDoubleValue(feature, zdgcIdx, out pHeight) - GetDoubleValue(feature, zdmsIdx, out pHeight); if (z2 > z3) { z2 = z3; } if (num7 < z3) { num7 = z3; } } if (lineConfigHeightFlag == 0) { z2 = z2 - num5; num7 = num7 - num5; } else if (2 == lineConfigHeightFlag) { z2 = z2 + num5; num7 = num7 + num5; } if (z > num7) { num = z - num7; num = num - double0 - num5; if (num < 0.001) { num = 0; } } else if (z2 <= num1) { num = 0; } else { num = z2 - num1; num = num - double0 - num5; if (num < 0.001) { num = 0; } } cItem._dVerDistance = num; cItem._dVerBase = 0; cItem._dHorBase = (double) CommonUtils.GetPipeLineAlarmHrzDistByFeatureClassName2(m_config, CommonUtils.GetSmpClassName(this.baselineFC.AliasName), CommonUtils.GetSmpClassName(feature.Class.AliasName), this.baseFeature, feature); string str1 = this.GetPipeMSFS(feature); string str2 = this.GetPipeMSFS(this.baseFeature); cItem._dVerBase = (double) CommonUtils.GetPipeLineAlarmVerDistByFeatureClassName(m_config, CommonUtils.GetSmpClassName(this.baselineFC.AliasName), CommonUtils.GetSmpClassName(feature.Class.AliasName), str2, str1); this.list_0.Add(cItem); } else { feature = pFeaCursor.NextFeature(); continue; } } else { int num8 = this.method_3(this.baselineSimpleLine, point); double num9 = 0; if (IsMUsing) { num9 = this.CalculateZ(this.baselineShape, point, num8); } else { num9 = this.CalculateZ(this.baselineShape, point, num8, feature, qdgcIdx, zdgcIdx); } if (this.heightType == 0) { num9 = num9 - double0; } else if (2 == this.heightType) { num9 = num9 + double0; } int num10 = this.method_3(polyline, point); double num11 = 0; if (IsMUsing) { num11 = this.CalculateZAlongLine(shape, point, num10); } else { num11 = this.CalculateZAlongLine(shape, point, num10, feature, qdgcIdx, qdmsIdx, zdgcIdx, zdmsIdx); } if (lineConfigHeightFlag == 0) { num11 = num11 - num5; } else if (2 == lineConfigHeightFlag) { num11 = num11 + num5; } num = Math.Abs(num9 - num11); if (num >= 0.001) { string str3 = feature.get_Value(num4).ToString(); CHitAnalyse.CItem pipeLineAlarmHrzDistByFeatureClassName2 = new CHitAnalyse.CItem() { _OID = feature.OID, _sKind = str3, _dVerDistance = num, _dVerBase = 0, _dHorDistance = 0, _dHorBase = 0, _pClass = (IFeatureClass)feature.Class }; pipeLineAlarmHrzDistByFeatureClassName2._dHorBase = (double) CommonUtils.GetPipeLineAlarmHrzDistByFeatureClassName2(m_config, CommonUtils.GetSmpClassName(this.baselineFC.AliasName), CommonUtils.GetSmpClassName(feature.Class.AliasName), this.baseFeature, feature); string str4 = this.GetPipeMSFS(feature); string str5 = this.GetPipeMSFS(this.baseFeature); pipeLineAlarmHrzDistByFeatureClassName2._dVerBase = (double) CommonUtils.GetPipeLineAlarmVerDistByFeatureClassName(m_config, CommonUtils.GetSmpClassName(this.baselineFC.AliasName), CommonUtils.GetSmpClassName(feature.Class.AliasName), str5, str4); this.list_0.Add(pipeLineAlarmHrzDistByFeatureClassName2); } else { feature = pFeaCursor.NextFeature(); continue; } } feature = pFeaCursor.NextFeature(); } } } }
private void CloseWorkspace() { m_ipGeometricNetwork = null; m_ipPoints = null; m_ipPointToEID = null; m_ipEnumNetEID_Junctions = null; m_ipEnumNetEID_Edges = null; m_ipPolyline = null; }
public void Analyse_Vertical(IFeatureCursor pFeaCursor) { double double0 = this.double_0 * 0.0005; ITopologicalOperator ipolyline1 = (ITopologicalOperator)this.baselineSimpleLine; IFeature feature = pFeaCursor.NextFeature(); if (feature == null) { return; } int num = -1; int num1 = -1; int num2 = -1; IBasicLayerInfo lineConfig = m_config.GetBasicLayerInfo(feature.Class.AliasName) as IBasicLayerInfo; IPipelineLayer pipelineLayer = m_config.GetPipelineLayer(feature.Class as IFeatureClass); IPipelineLayer pipelineLayer0 = m_config.GetPipelineLayer(baselineFC); if (feature != null) { num = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ)); num1 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC)); num2 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ)); } if (num2 >= 0) { if ((num >= 0 ? true : num1 >= 0)) { int lineConfigHeightFlag = (int)lineConfig.HeightType; // this.m_app.PipeConfig.getLineConfig_HeightFlag(CommonUtils.GetSmpClassName(feature.Class.AliasName)); while (feature != null) { IPolyline shape = feature.Shape as IPolyline; IPolyline polyline = this.SimplifyPolyline(shape); double num3 = 0; this.GetPipeGJ(feature, num, num1, out num3); if (num3 < 10) { num3 = 10; } num3 = num3 * 0.0005; IGeometry geometry = ipolyline1.Intersect(polyline, (esriGeometryDimension)1); if (geometry != null) { IPoint point = null; if (geometry is IPoint) { point = (IPoint)geometry; } else if (geometry is IMultipoint) { IPointCollection pointCollection = (IPointCollection)geometry; if (pointCollection.PointCount > 0) { point = pointCollection.get_Point(0); } } if (point != null) { int num4 = this.method_3(this.baselineSimpleLine, point); double num5 = this.CalculateZAlongLine(this.baselineShape, point, num4); if (this.heightType == 0) { num5 = num5 - double0; } else if (2 == this.heightType) { num5 = num5 + double0; } int num6 = this.method_3(polyline, point); double num7 = this.CalculateZAlongLine(shape, point, num6); if (lineConfigHeightFlag == 0) { num7 = num7 - num3; } else if (2 == lineConfigHeightFlag) { num7 = num7 + num3; } double num8 = Math.Abs(num5 - num7); if (num8 >= 0.001) { string str = feature.get_Value(num2).ToString(); CHitAnalyse.CItem cItem = new CHitAnalyse.CItem() { _OID = feature.OID, _sKind = str, _dVerDistance = num8, _dVerBase = 0, _pClass = (IFeatureClass)feature.Class }; string str1 = this.GetPipeMSFS(feature); string str2 = this.GetPipeMSFS(this.baseFeature); cItem._dVerBase = (double) CommonUtils.GetPipeLineAlarmVerDistByFeatureClassName(m_config, pipelineLayer0.ClassCode, pipelineLayer.ClassCode, str2, str1); this.list_0.Add(cItem); } else { feature = pFeaCursor.NextFeature(); continue; } } } feature = pFeaCursor.NextFeature(); } } } }