Exemplo n.º 1
0
        private void DrawCircleByCenterAndRadius(ILayer pLayer, ICircularArc pCircularArc, IScreenDisplay pScreenDisplay)
        {
            object o = Type.Missing;

            if (pLayer != null)
            {
                ISegmentCollection pSegmentCollection = null;
                pSegmentCollection = new PathClass();
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {
                        ISegment pSegment = pCircularArc as ISegment;
                        pSegmentCollection.AddSegment(pSegment, ref o, ref o);
                        IGeometryCollection pPolyline = new PolylineClass();
                        //通过IGeometryCollection为Polyline对象添加Path对象
                        pPolyline.AddGeometry(pSegmentCollection as IGeometry, ref o, ref o);
                        IFeature pCircleFeature = pFeatureClass.CreateFeature();
                        pCircleFeature.Shape = pPolyline as PolylineClass;
                        pCircleFeature.Store();

                        //局部刷新
                        IInvalidArea pInvalidArea = new InvalidAreaClass();
                        pInvalidArea.Add(pCircularArc);
                        pInvalidArea.Display = pScreenDisplay;
                        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);

                        //20140410 lyf
                        m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private IPolyline assemblePolyLine(List <LineSeg> segs)
        {
            IPolyline ln  = new PolylineClass();
            double    dsq = m_dtol * m_dtol;

            ISegmentCollection path = new PathClass();

//			List<LineSeg> sorted = new List<LineSeg>();;
//			for (int i = 0; i < segs.Count; i++) {
//				LineSeg prior = (i > 0 ? sorted[i-1] : null);
//				LineSeg next = (i < segs.Count-1 ? segs[i+1] : null);
//				sorted.Add(appropriatelySwapped(dsq,prior,segs[i],next));
//			}
//

            for (int i = 0; i < /*sorted*/ segs.Count; i++)
            {
                LineSeg l     = /*sorted*/ segs[i];
                ILine   part  = new LineClass();
                IPoint  fromp = new PointClass();
                fromp.X = l.Start.X;
                fromp.Y = l.Start.Y;
                IPoint top = new PointClass();
                top.X          = l.End.X;
                top.Y          = l.End.Y;
                part.FromPoint = fromp;
                part.ToPoint   = top;
                object ignored = System.Reflection.Missing.Value;
                path.AddSegment((ISegment)part, ref __missing, ref __missing);
            }
            (ln as IGeometryCollection).AddGeometry((IGeometry)path, ref __missing, ref __missing);
            ln.SpatialReference = m_spref;
            return(ln);
        }
Exemplo n.º 3
0
        public void PutCoords(IPoint[] controlPoints)
        {
            if (controlPoints.Length < 2)
            {
                throw new ArgumentException("传入的标绘元素控制点个数与元素最小控制点数不匹配");
            }
            //GetControlPoints()
            this.ControlPoints = controlPoints;
            //GetShape()
            object             objBefore = Type.Missing;
            object             objAfter  = Type.Missing;
            ISegmentCollection segment   = new PathClass();

            for (int i = 0; i < controlPoints.Length - 1; i++)
            {
                ILine line = new LineClass {
                    FromPoint = controlPoints[i], ToPoint = controlPoints[i + 1]
                };
                segment.AddSegment((ISegment)line, objBefore, objAfter);
            }
            IPath path = (IPath)segment;
            IGeometryCollection polyline = new PolylineClass();

            polyline.AddGeometry(path, ref objBefore, ref objAfter);
            IGeometry geometry = (IGeometry)polyline;

            //            ITopologicalOperator topo = polyline as ITopologicalOperator;
            //            topo.Simplify();
            this.Shape = geometry;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 通过起点和终点创建线段(IPolyline对象)
        /// </summary>
        /// <param name="pt1">起点</param>
        /// <param name="pt2">终点</param>
        /// <returns></returns>
        public static IPolyline CreatePolyline(IPoint pt1, IPoint pt2)
        {
            //a. 创建Line对象(也可是其他Segment对象),
            //b. QI到Segment对象
            //c. 创建Path对象,通过Path的addSegment,将最初的Line添加进Path中
            //d. 创建GeometryCollection对象,通过AddGeometry,将path添加进GeometryCollection中
            //e. 将GeometryCollection QI到 IPolyline


            ILine line = new LineClass();                  // 创建一个Line对象

            line.PutCoords(pt1, pt2);                      // 设置LIne对象的起始终止点
            ISegment           segment = line as ISegment; // QI到ISegment
            ISegmentCollection path    = new PathClass();  // 创建一个Path对象

            object o = Type.Missing;

            path.AddSegment(segment, ref o, ref o);// 通过Isegmentcoletcion接口为Path对象添加Segment对象

            // 创建一个Polyline对象
            IGeometryCollection polyline = new PolylineClass();

            polyline.AddGeometry(path as IGeometry, ref o, ref o);

            IPolyline resultPolyline = polyline as IPolyline;

            return(resultPolyline);
        }
Exemplo n.º 5
0
        /// <summary>
        /// ���ݵ㼯���������Ҫ��
        /// </summary>
        /// <params name="featureLayer"></params>
        /// <params name="lstPoint"></params>
        public void CreateLine(IFeatureLayer featureLayer, List<IPoint> lstPoint, int ID)
        {
            //try
            //{
            IFeatureClass featureClass = featureLayer.FeatureClass;
            if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                IPointCollection multipoint = new MultipointClass();
                if (lstPoint.Count < 2)
                {
                    MessageBox.Show(@"��ѡ���������������ϵ�����", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                ISegmentCollection pPath = new PathClass();
                ILine pLine;
                ISegment pSegment;
                object o = Type.Missing;
                for (int i = 0; i < lstPoint.Count - 1; i++)
                {
                    pLine = new LineClass();
                    pLine.PutCoords(lstPoint[i], lstPoint[i + 1]);
                    pSegment = pLine as ISegment;
                    pPath.AddSegment(pSegment, ref o, ref o);
                }
                IGeometryCollection pPolyline = new PolylineClass();
                pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                IDataset dataset = (IDataset)featureClass;
                IWorkspace workspace = dataset.Workspace;
                IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();

                IFeature feature = featureClass.CreateFeature();

                IGeometry geometry = pPolyline as IGeometry;
                DrawCommon.HandleZMValue(feature, geometry);//����ͼ��Zֵ����

                feature.Shape = pPolyline as PolylineClass;
                int iFieldID = feature.Fields.FindField(GIS_Const.FIELD_BID);
                feature.Value[iFieldID] = ID.ToString();
                feature.Store();
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(false);

                IEnvelope envelop = feature.Shape.Envelope;
                DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop;
                DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
            }
            else
            {
                MessageBox.Show(@"��ѡ����ͼ�㡣", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //}
            //catch
            //{
            //    return;
            //}
        }
Exemplo n.º 6
0
        private void CreateDongShi(IPoint P0, IPoint P1, IPoint P2, IPoint P3, string hdid, string bid)
        {
            ISegmentCollection pPath = new PathClass();
            //第一条线段
            ILine pLine = new LineClass();

            pLine.PutCoords(P0, P1);
            //QI到ISegment
            ISegment pSegment = pLine as ISegment;

            //创建一个Path对象
            System.Object o = Type.Missing;
            //通过ISegmentCollection接口为Path对象添加Segment对象
            pPath.AddSegment(pSegment, ref o, ref o);
            //第二条线段
            ILine pLine2 = new LineClass();

            pLine2.PutCoords(P1, P2);
            ISegment pSegment2 = pLine2 as ISegment;

            //创建一个Path对象
            //通过ISegmentCollection接口为Path对象添加Segment对象
            pPath.AddSegment(pSegment2, ref o, ref o);
            //第三条线段
            ILine pLine3 = new LineClass();

            pLine3.PutCoords(P2, P3);
            ISegment pSegment3 = pLine3 as ISegment;

            //创建一个Path对象
            //通过ISegmentCollection接口为Path对象添加Segment对象
            pPath.AddSegment(pSegment3, ref o, ref o);

            IGeometryCollection pPolyline = new PolylineClass();

            //通过IGeometryCollection为Polyline对象添加Path对象
            pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

            if (m_pDongshiFeatureLayer != null)
            {
                System.Collections.Generic.List <ziduan> list = new System.Collections.Generic.List <ziduan>();
                list.Add(new ziduan(GIS_Const.FIELD_HDID, hdid));
                list.Add(new ziduan(GIS_Const.FIELD_BID, bid));
                DataEditCommon.CreateNewFeature(m_pDongshiFeatureLayer, pPolyline as IGeometry, list);
                m_hookHelper.ActiveView.Refresh();
            }
        }
Exemplo n.º 7
0
        private void route_Search_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.start_time.EditValue == "" || this.end_time.EditValue == "")
            {
                MessageBox.Show("请选择起止日期");
                return;
            }
            SqlHelper           help = new SqlHelper();
            String              sql  = "select * from route where tm between '" + this.start_time.EditValue + "' and '" + this.end_time.EditValue + "'";
            DataTable           dt   = help.getMySqlRead(sql);
            ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();

            simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
            IColor color = GisClass.GetRgbColor(0, 255, 0);

            simpleMarkerSymbol.Color = color;
            ILineElement       lineElement = new LineElementClass();
            IElement           ele1        = lineElement as IElement;
            ISegment           pSegment;
            ILine              pLine = null;
            object             o     = Type.Missing;
            ISegmentCollection pPath = new PathClass();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                IMarkerElement markerEle = new MarkerElementClass();
                IElement       ele       = markerEle as IElement;
                IPoint         point     = new PointClass();
                markerEle.Symbol = simpleMarkerSymbol;
                point.PutCoords(Double.Parse(dt.Rows[i]["x"].ToString()), Double.Parse(dt.Rows[i]["y"].ToString()));
                ele.Geometry = point;
                pGraphicsContainer.AddElement(ele, 0);
                //逐段添加线
                if (i > 0 && i < dt.Rows.Count)
                {
                    IPoint point1 = new PointClass();
                    point1.PutCoords(Double.Parse(dt.Rows[i - 1]["x"].ToString()), Double.Parse(dt.Rows[i - 1]["y"].ToString()));
                    pLine = new LineClass();
                    pLine.PutCoords(point1, point);
                    pSegment = pLine as ISegment;
                    pPath.AddSegment(pSegment, ref o, ref o);
                }


                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
            }
            IGeometryCollection pPolyline = new PolylineClass();

            pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);
            IPolyline polyline = pPolyline as IPolyline;
            //获取范围
            IEnvelope ev = polyline.Envelope;

            this.axMapControl1.ActiveView.Extent = ev;
            ele1.Geometry = pPolyline as IPolyline;
            pGraphicsContainer.AddElement(ele1, 0);
        }
Exemplo n.º 8
0
        public static IGeometryCollection ConstructSector(IPoint[] pointArray, double circRadius, double angle)
        {
            // 边
            ILine pLine = new LineClass();

            pLine.PutCoords(pointArray[0], pointArray[1]);

            // 弧
            //ESRI.ArcGIS.Geometry.ICircularArc cir = new CircularArcClass();
            //ESRI.ArcGIS.Geometry.IConstructCircularArc con = new CircularArcClass();
            //cir = con as ICircularArc;
            //cir.PutCoordsByAngle(pointArray[0], angle * Math.PI / 180, 40 * Math.PI / 180, circRadius);

            // 边
            ILine pLine1 = new LineClass();

            pLine.PutCoords(pointArray[2], pointArray[0]);

            //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象
            object             o = Type.Missing;
            ISegmentCollection pSegCollection = new PathClass();

            // 添加进pSegCollection
            pSegCollection.AddSegment(pLine as ISegment, ref o, ref o);
            //pSegCollection.AddSegment(cir as ISegment, ref o, ref o);
            pSegCollection.AddSegment(pLine1 as ISegment, ref o, ref o);

            // QI到IRing接口封闭Ring对象,使其有效
            //IPath pRing = pSegCollection as IPath;
            //pRing.Close();

            // 使用Ring对象构建Polygon对象
            IGeometryCollection pGeometryColl = new PolylineClass();

            pGeometryColl.AddGeometry(pSegCollection as IGeometry, ref o, ref o);

            return(pGeometryColl);
        }
Exemplo n.º 9
0
        public static IPolyline CreatePolyline(TuLine t)
        {
            ISegment           pSegment;
            ILine              pLine;
            object             o     = Type.Missing;
            ISegmentCollection pPath = new PathClass();

            pLine = new LineClass();
            pLine.PutCoords(t.Begin, t.End);
            pSegment = pLine as ISegment;
            pPath.AddSegment(pSegment, ref o, ref o);
            IGeometryCollection pPolyline = new PolylineClass();

            pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);
            return(pPolyline as IPolyline);
        }
Exemplo n.º 10
0
        static public IPolyline CreatePly(List <IPoint> ptList)
        {
            ISegmentCollection sc = new PathClass();

            for (int i = 0; i < ptList.Count - 1; i++)
            {
                ILine newline = new LineClass();
                newline.PutCoords(ptList[i], ptList[i + 1]);
                sc.AddSegment(newline as ISegment, Type.Missing, Type.Missing);
            }
            IPolyline           pline     = new PolylineClass();
            IGeometryCollection gPolyline = pline as IGeometryCollection;

            gPolyline.AddGeometry(sc as IGeometry, Type.Missing, Type.Missing);
            pline = gPolyline as IPolyline;
            return(pline);
        }
Exemplo n.º 11
0
        private IGeometry WKTCoordinateInfo2PolyLine(string WKTCoor, out string message)
        {
            string[] split = WKTCoor.Split(',');
            if (split.Length < 2)
            {
                message = "坐标点太少." + WKTCoor;
                return(null);
            }
            ISegmentCollection path = new PathClass();
            int len = xys.Length - 1;

            for (int i = 0; i < len; i += 2)
            {
                _fromStr = xys[i].Split(' ');
                _toStr   = xys[i + 1].Split(' ');
                if (_fromStr.Length != 2 || _toStr.Length != 2)
                {
                    message = "坐标点不能正确分割." + WKTCoor;
                    return(null);
                }
                if (!double.TryParse(_fromStr[0], out _x) || !double.TryParse(_fromStr[1], out _y))
                {
                    message = "坐标点不能转换为double." + WKTCoor;
                    return(null);
                }
                _fromPoint.X = _x;
                _fromPoint.Y = _y;
                if (!double.TryParse(_toStr[0], out _x) || !double.TryParse(_toStr[1], out _y))
                {
                    message = "坐标点不能转换为double." + WKTCoor;
                    return(null);
                }
                _toPoint.X = _x;
                _toPoint.Y = _y;
                _line.PutCoords(from, to);
                path.AddSegment((ISegment)_line, missing, missing);
            }
            IGeometryCollection polyLine = new PolylineClass();

            polyLine.AddGeometry((IGeometry)path, missing, missing);
            message = "";
            IGeometry geometry = polyLine as IGeometry;;

            return(geometry);
        }
Exemplo n.º 12
0
        // 2019.5.31 地形
        public static IGeometryCollection ConstructMultiPath(List <IPoint> pointArray)
        {
            // 通过ISegmentCollection接口向其中添加Segment对象
            object             o = Type.Missing;
            ISegmentCollection pSegCollection = new PathClass();

            for (int i = 0, j = pointArray.Count - 1; i < pointArray.Count; j = i, i++)
            {
                ILine pLine = new LineClass();
                pLine.PutCoords(pointArray[j], pointArray[i]);

                // 添加进pSegCollection
                pSegCollection.AddSegment(pLine as ISegment, ref o, ref o);
            }

            IGeometryCollection pGeometryColl = new PolylineClass();

            pGeometryColl.AddGeometry(pSegCollection as IGeometry, ref o, ref o);

            return(pGeometryColl);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 坐标串转换为多段线
        /// </summary>
        /// <param name="xyString"></param>
        /// <returns></returns>
        public static IPolyline ToPolyline2(string xyString)
        {
            string[]         xyStr = xyString.Split(';');
            IPoint           pPoint = new PointClass();
            IPointCollection pPointCollection = new PolygonClass();
            object           _missing = Type.Missing;
            double           Lat, Lon;

            for (int i = 0; i < xyStr.Length; i++)
            {
                if (string.IsNullOrEmpty(xyStr[i]))
                {
                    continue;
                }
                Lon      = Convert.ToDouble(xyStr[i].Split(',')[1]);
                Lat      = Convert.ToDouble(xyStr[i].Split(',')[0]);
                pPoint   = new PointClass();
                pPoint.X = Lon;
                pPoint.Y = Lat;
                pPoint.PutCoords(Lon, Lat);
                pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
            }
            ILine              pLine;
            object             o = Type.Missing;
            ISegmentCollection pPath = new PathClass();

            for (int j = 0; j < pPointCollection.PointCount - 1; j++)
            {
                pLine = new LineClass();
                pLine.PutCoords(pPointCollection.Point[j], pPointCollection.Point[j + 1]);
                pPath.AddSegment((ISegment)pLine, ref o, ref o);
            }
            IGeometryCollection pPolyline = new PolylineClass();

            pPolyline.AddGeometry((IGeometry)pPath, ref o, ref o);
            return(pPolyline as IPolyline);
        }
        public void FlashGeometry(IGeometry Geom, IScreenDisplay Display, IColor Color, int Size, int Interval)
        {
            if (Geom == null)
            return;
              short Cache = Display.ActiveCache;
              Display.ActiveCache = (short)esriScreenCache.esriNoScreenCache;
              Display.StartDrawing(0, Cache);

              if (Geom.GeometryType == esriGeometryType.esriGeometryLine || Geom.GeometryType == esriGeometryType.esriGeometryCircularArc)
              {
            ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleLineSymbol;
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //erase itself when drawn twice
            pSimpleLineSymbol.Width = Size;
            pSimpleLineSymbol.Color = Color;
            Display.SetSymbol((ISymbol)pSimpleLineSymbol);
            ISegmentCollection pPath = new PathClass();
            pPath.AddSegment((ISegment)Geom);
            IGeometryCollection pPolyL = new PolylineClass();
            pPolyL.AddGeometry((IGeometry)pPath);
            Display.DrawPolyline((IGeometry)pPolyL);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPolyline((IGeometry)pPolyL);
               }
              else if (Geom.GeometryType == esriGeometryType.esriGeometryPolyline)
              {
            ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleLineSymbol; //'QI
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //erase itself when drawn twice
            pSimpleLineSymbol.Width = Size;
            pSimpleLineSymbol.Color = Color;
            Display.SetSymbol((ISymbol)pSimpleLineSymbol);
            Display.DrawPolyline(Geom);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPolyline(Geom);
              }
              else if (Geom.GeometryType == esriGeometryType.esriGeometryPolygon)
              {
            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleFillSymbol;
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //erase itself when drawn twice
            pSimpleFillSymbol.Color = Color;
            Display.SetSymbol((ISymbol)pSimpleFillSymbol);
            Display.DrawPolygon(Geom);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPolygon(Geom);
              }
              else if (Geom.GeometryType == esriGeometryType.esriGeometryPoint)
              {
            ISimpleMarkerSymbol pSimpleMarkersymbol = new SimpleMarkerSymbolClass();
            ISymbol pSymbol = (ISymbol)pSimpleMarkersymbol;
            pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen;
            pSimpleMarkersymbol.Color = Color;
            pSimpleMarkersymbol.Size = Size;
            Display.SetSymbol((ISymbol)pSimpleMarkersymbol);
            Display.DrawPoint(Geom);
            System.Threading.Thread.Sleep(Interval);
            Display.DrawPoint(Geom);
              }
              Display.FinishDrawing();
              //reset the cache
              Display.ActiveCache = Cache;
        }
Exemplo n.º 15
0
        private void DrawCircleByCenterAndRadius(ILayer pLayer, IBezierCurveGEN pCircularArc, IScreenDisplay pScreenDisplay)
        {
            object o = Type.Missing;
            if (pLayer != null)
            {
                ISegmentCollection pSegmentCollection = null;
                pSegmentCollection = new PathClass();
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {

                        ISegment pSegment = pCircularArc as ISegment;
                        pSegmentCollection.AddSegment(pSegment, ref o, ref o);
                        IGeometryCollection pPolyline = new PolylineClass();
                        //ͨ��IGeometryCollectionΪPolyline�������Path����
                        pPolyline.AddGeometry(pSegmentCollection as IGeometry, ref o, ref o);

                        m_pMap.ClearSelection();

                        IFeature pCircleFeature = pFeatureClass.CreateFeature();
                        pCircleFeature.Shape = pPolyline as PolylineClass;
                        pCircleFeature.Store();

                        m_pMap.SelectFeature(m_pCurrentLayer, pCircleFeature);

                        IActiveView pActiveView = (IActiveView)m_pMap;
                        m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                        //�ֲ�ˢ��
                        IInvalidArea pInvalidArea = new InvalidAreaClass();
                        pInvalidArea.Add(pPolyline);

                        pInvalidArea.Display = m_hookHelper.ActiveView.ScreenDisplay;
                        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);
                    }
                }
            }
        }
        ///方法1:根据点要素直接生产线要素,《参考绘制巷道》
        /// <summary>
        /// 根据点集坐标绘制线要素
        /// </summary>
        /// <params name="featureLayer"></params>
        /// <params name="lstPoint"></params>
        public static void CreateLine(IFeatureLayer featureLayer, List<IPoint> lstPoint, string ID)
        {
            try
            {
                IFeatureClass featureClass = featureLayer.FeatureClass;
                if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IPointCollection multipoint = new MultipointClass();
                    if (lstPoint.Count < 2)
                    {
                        MessageBox.Show(@"请选择两个及两个以上点数。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    ISegmentCollection pPath = new PathClass();
                    ILine pLine;
                    ISegment pSegment;
                    object o = Type.Missing;
                    for (int i = 0; i < lstPoint.Count - 1; i++)
                    {
                        pLine = new LineClass();
                        pLine.PutCoords(lstPoint[i], lstPoint[i + 1]);
                        pSegment = pLine as ISegment;
                        pPath.AddSegment(pSegment, ref o, ref o);
                    }
                    IGeometryCollection pPolyline = new PolylineClass();
                    pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                    IDataset dataset = (IDataset)featureClass;
                    IWorkspace workspace = dataset.Workspace;
                    IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
                    workspaceEdit.StartEditing(false);
                    workspaceEdit.StartEditOperation();

                    IFeature feature = featureClass.CreateFeature();

                    IGeometry geometry = pPolyline as IGeometry;
                    DrawCommon.HandleZMValue(feature, geometry);//几何图形Z值处理

                    feature.Shape = pPolyline as PolylineClass;
                    int iFieldID = feature.Fields.FindField("BID");
                    feature.Value[iFieldID] = ID.ToString();
                    feature.Store();
                    workspaceEdit.StopEditOperation();
                    workspaceEdit.StopEditing(true);
                    IEnvelope envelop = feature.Shape.Envelope;
                    DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop;
                    GIS.Common.DataEditCommon.g_pMyMapCtrl.ActiveView.Extent.Expand(1.5, 1.5, true);
                    GIS.Common.DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(featureLayer, feature);
                    GIS.Common.DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);

                    //DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
                }
                else
                {
                    MessageBox.Show(@"请选择线图层。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 绘制曲线部分
        /// </summary>
        /// <params name="lyr">推断断层</params>
        /// <params name="newplines">延长点构造的线</params>
        /// <params name="originlines">原始点构造的线</params>
        private void AddCurveToMap(IFeatureLayer lyr, List<IPolyline> newplines, List<IPolyline> originlines)
        {
            IFeatureClass Featureclass = lyr.FeatureClass;
            IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
            workspace.StartEditing(true);
            workspace.StartEditOperation();
            object missing = Type.Missing;
            //揭露断层上的曲线对象
            IGeometry geom = new PolylineClass();
            geom.SpatialReference = Global.spatialref;
            IGeometryCollection outgeomcols = geom as IGeometryCollection;
            IFeature fea = Featureclass.CreateFeature();
            ISegmentCollection newpath = new PathClass();
            int kindpos = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_TYPE);
            int bidpos = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_BID);
            for (int i = 0; i < newplines.Count; i++)
            {
                ILine lin = new LineClass();
                lin.SpatialReference = Global.spatialref;
                //直线段
                IPath path = new PathClass();
                if (i == 0)
                {
                    lin.FromPoint = newplines[i].FromPoint;
                    lin.ToPoint = originlines[i].ToPoint;
                }
                else if (i == originlines.Count - 1)
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint = newplines[i].ToPoint;
                }
                else
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint = originlines[i].ToPoint;
                }
                newpath.AddSegment(lin as ISegment, ref missing, ref missing);
                //曲线段
                if (i < newplines.Count - 1)
                {
                    IBezierCurveGEN bezier = new BezierCurveClass();
                    IPoint[] pntcontrols = new IPoint[4];
                    pntcontrols[0] = originlines[i].ToPoint;
                    pntcontrols[1] = newplines[i].ToPoint;
                    pntcontrols[2] = newplines[i + 1].FromPoint;
                    pntcontrols[3] = originlines[i + 1].FromPoint;
                    bezier.PutCoords(ref pntcontrols);

                    newpath.AddSegment(bezier as ISegment, ref missing, ref missing);
                }
            }
            outgeomcols.AddGeometry(newpath as IGeometry, ref missing, ref missing);
            int index = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
            IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;
            if (geometryDef.HasZ)
            {
                IZAware pZAware = (IZAware)outgeomcols;
                pZAware.ZAware = true;
            }
            fea.Shape = outgeomcols as IPolyline;
            fea.set_Value(kindpos, 1);
            fea.set_Value(bidpos, BID);
            fea.Store();
            //外围曲线绘制
            ITopologicalOperator2 top = outgeomcols as ITopologicalOperator2;
            if (!top.IsSimple)
                top.Simplify();
            IConstructCurve curve = new PolylineClass();
            curve.ConstructOffset(outgeomcols as IPolyline, -3, ref missing, ref missing);
            IPolyline plinnew = curve as IPolyline;
            plinnew.SpatialReference = Global.spatialref;
            plinnew.FromPoint = newplines[0].FromPoint;
            plinnew.ToPoint = newplines[newplines.Count - 1].ToPoint;

            IFeature outcurve = Featureclass.CreateFeature();
            outcurve.set_Value(kindpos, 2);
            outcurve.set_Value(bidpos, BID);
            outcurve.Shape = plinnew;
            outcurve.Store();
            //结束编辑
            workspace.StopEditOperation();
            workspace.StopEditing(true);
            //定位跳转
            Global.commonclss.JumpToGeometry(plinnew);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 图上画点或线
        /// </summary>
        /// <param name="lgstr">经度</param>
        /// <param name="lastr">纬度</param>
        /// <param name="pEle">IElement</param>
        /// <param name="isSelected">是否选中</param>
        /// <param name="pGra">IGraphicsContainer</param>
        private void DrawPointOrLine(string lgstr, string lastr, IGraphicsContainer pGra, bool isSelected)
        {
            /*
             * 经纬度范围
             */
            double   Xmin = this.axMapControl.Extent.XMin;
            double   Xmax = this.axMapControl.Extent.XMax;
            IElement pEle = null;

            /*
             * 经纬度完整
             * 画点
             */
            if (lgstr != string.Empty && lastr != string.Empty)
            {
                ESRI.ArcGIS.Geometry.IPoint pt = new PointClass()
                {
                    X = double.Parse(lgstr), Y = double.Parse(lastr)
                };

                IMarkerElement pMakEle = new MarkerElementClass();
                pEle = pMakEle as IElement;
                IMarkerSymbol pMakSym = new SimpleMarkerSymbolClass();
                pMakSym.Size = 5;


                pMakSym.Color  = isSelected ? ColorToIColor(Color.Turquoise) : ColorToIColor(Color.Blue);
                pMakEle.Symbol = pMakSym;
                pEle.Geometry  = pt;
                pGra.AddElement(pEle, 0);
            }

            /*
             * 只有纬度的情况
             * 画纬线
             */
            if ((lgstr == string.Empty || lgstr == "0") && lastr != string.Empty)
            {
                ISegmentCollection pPath = new PathClass();
                object             o     = Type.Missing;

                ESRI.ArcGIS.Geometry.IPoint FromPt = new PointClass()
                {
                    X = Xmin, Y = double.Parse(lastr)
                };
                ESRI.ArcGIS.Geometry.IPoint ToPt = new PointClass()
                {
                    X = Xmax, Y = double.Parse(lastr)
                };

                ILine2 line = new LineClass();
                line.FromPoint = FromPt;
                line.ToPoint   = ToPt;

                pPath.AddSegment(line as ISegment, ref o, ref o);

                IGeometryCollection pPolyline = new PolylineClass();
                pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
                IColor            pColor     = new RgbColorClass();

                lineSymbol.Color = ColorToIColor(Color.Green);      //颜色
                lineSymbol.Style = esriSimpleLineStyle.esriSLSDash; //样式
                lineSymbol.Width = 1;

                ILineElement pLineElement = new LineElementClass();
                pLineElement.Symbol = lineSymbol;

                IElement pElement = pLineElement as IElement;
                pElement.Geometry = pPolyline as IGeometry;

                pGra.AddElement(pElement, 0);
            }
        }
 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;
     }
 }
        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;
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 纠正按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex < 0)
                {
                    return;
                }
                string ptname = this.dataGridView.Rows[e.RowIndex].Cells["ptname"].Value.ToString();
                string ptlg   = this.dataGridView.Rows[e.RowIndex].Cells["lg"].Value.ToString();
                string ptla   = this.dataGridView.Rows[e.RowIndex].Cells["la"].Value.ToString();
                string dist   = this.dataGridView.Rows[e.RowIndex].Cells["dist"].Value.ToString();

                if (e.ColumnIndex != -1)
                {
                    if (this.dataGridView.Columns[e.ColumnIndex].Name == "correct")//纠正按钮事件
                    {
                        this.axMapControl.CurrentTool  = null;
                        this.axMapControl.MousePointer = esriControlsMousePointer.esriPointerPencil;

                        this.EditPoint.ptname = ptname;
                        double.TryParse(ptlg, out this.EditPoint.ptlg);
                        double.TryParse(ptla, out this.EditPoint.ptla);
                        double.TryParse(dist, out this.EditPoint.dist);
                        this.EditPoint.rIndex = e.RowIndex;
                    }
                }
                else
                {
                    double Xmin = this.axMapControl.Extent.XMin;
                    double Xmax = this.axMapControl.Extent.XMax;

                    /*
                     * 经纬度完整
                     * 画点
                     */
                    if ((ptlg != string.Empty && ptlg != "0") && (ptla != string.Empty && ptla != "0"))
                    {
                        IElement pEle = null;

                        ESRI.ArcGIS.Geometry.IPoint pt = new PointClass()
                        {
                            X = double.Parse(ptlg), Y = double.Parse(ptla)
                        };

                        IMarkerElement pMakEle = new MarkerElementClass();
                        pEle = pMakEle as IElement;
                        IMarkerSymbol pMakSym = new SimpleMarkerSymbolClass();
                        pMakSym.Size = 5;


                        pMakSym.Color  = ColorToIColor(Color.Turquoise);
                        pMakEle.Symbol = pMakSym;
                        pEle.Geometry  = pt;

                        AddSelectedElementByGraphicsSubLayer("selectedEleLayer", pEle);
                        axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }

                    /*
                     * 只有纬度的情况
                     * 画纬线
                     */
                    if ((ptlg == string.Empty || ptlg == "0") && ptla != string.Empty)
                    {
                        ISegmentCollection pPath = new PathClass();
                        object             o     = Type.Missing;

                        ESRI.ArcGIS.Geometry.IPoint FromPt = new PointClass()
                        {
                            X = Xmin, Y = double.Parse(ptla)
                        };
                        ESRI.ArcGIS.Geometry.IPoint ToPt = new PointClass()
                        {
                            X = Xmax, Y = double.Parse(ptla)
                        };

                        ILine2 line = new LineClass();
                        line.FromPoint = FromPt;
                        line.ToPoint   = ToPt;

                        pPath.AddSegment(line as ISegment, ref o, ref o);

                        IGeometryCollection pPolyline = new PolylineClass();
                        pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                        ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
                        IColor            pColor     = new RgbColorClass();

                        lineSymbol.Color = ColorToIColor(Color.Red);        //颜色
                        lineSymbol.Style = esriSimpleLineStyle.esriSLSDash; //样式
                        lineSymbol.Width = 1;

                        ILineElement pLineElement = new LineElementClass();
                        pLineElement.Symbol = lineSymbol;

                        IElement pElement = pLineElement as IElement;
                        pElement.Geometry = pPolyline as IGeometry;

                        AddSelectedElementByGraphicsSubLayer("selectedEleLayer", pElement);
                        axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 22
0
        private void CreateDongShi(IPoint P0, IPoint P1, IPoint P2, IPoint P3, string hdid, string bid)
        {
            ISegmentCollection pPath = new PathClass();
            //��һ���߶�
            ILine pLine = new LineClass();
            pLine.PutCoords(P0, P1);
            //QI��ISegment
            ISegment pSegment = pLine as ISegment;
            //����һ��Path����
            System.Object o = Type.Missing;
            //ͨ��ISegmentCollection�ӿ�ΪPath�������Segment����
            pPath.AddSegment(pSegment, ref o, ref o);
            //�ڶ����߶�
            ILine pLine2 = new LineClass();
            pLine2.PutCoords(P1, P2);
            ISegment pSegment2 = pLine2 as ISegment;
            //����һ��Path����
            //ͨ��ISegmentCollection�ӿ�ΪPath�������Segment����
            pPath.AddSegment(pSegment2, ref o, ref o);
            //�������߶�
            ILine pLine3 = new LineClass();
            pLine3.PutCoords(P2, P3);
            ISegment pSegment3 = pLine3 as ISegment;
            //����һ��Path����
            //ͨ��ISegmentCollection�ӿ�ΪPath�������Segment����
            pPath.AddSegment(pSegment3, ref o, ref o);

            IGeometryCollection pPolyline = new PolylineClass();
            //ͨ��IGeometryCollectionΪPolyline�������Path����
            pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

            if (m_pDongshiFeatureLayer != null)
            {
                System.Collections.Generic.List<ziduan> list = new System.Collections.Generic.List<ziduan>();
                list.Add(new ziduan(GIS_Const.FIELD_HDID, hdid));
                list.Add(new ziduan(GIS_Const.FIELD_BID, bid));
                DataEditCommon.CreateNewFeature(m_pDongshiFeatureLayer, pPolyline as IGeometry,list);
                m_hookHelper.ActiveView.Refresh();
            }
        }
Exemplo n.º 23
0
        public bool HasParallelCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
      double AngleToleranceTangentCompareInDegrees, double OrthogonalSearchDistance,
       out int outFoundLinesCount, out int outFoundParallelCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundLinesCount = 0;
              outFoundParallelCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pNormalLine = new Line(); //new
              for (int i = -1; i < 2; i = i + 2)
              {
            double dOffset = OrthogonalSearchDistance * i;

            inPolycurve.QueryNormal(esriSegmentExtension.esriNoExtension, 0.5, true, dOffset, pNormalLine);
            ILine pThisLine = new Line();

            pThisLine.PutCoords(pNormalLine.FromPoint, pNormalLine.ToPoint);
            pGeomColl.AddGeometry(pThisLine);

            //Although each line is connected to the other, create a new path for each line
            //this allows for future changes in case the input needs to be altered to separate paths.

            ISegmentCollection newPath = new PathClass();
            object obj = Type.Missing;
            newPath.AddSegment((ISegment)pThisLine, ref obj, ref obj);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref obj, ref obj);
              }

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = pGeomBag;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }

              IFeature pFeat = pFeatCursLines.NextFeature();
              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            if (dRadius == 0)
            {//null or zero radius so skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            val = pFeat.get_Value(idxCenterPointID);
            if (val == DBNull.Value)
            {//null centrpointID so skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            ITopologicalOperator6 pTopoOp6 = (ITopologicalOperator6)MultiPartPolyLine;
            IGeometry pResultGeom = pTopoOp6.IntersectEx(pFoundLineGeom, false, esriGeometryDimension.esriGeometry0Dimension);
            if (pResultGeom == null)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }
            if (pResultGeom.IsEmpty)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            bool bHasCurves = false;
            pFoundLineGeomSegs.HasNonLinearSegments(ref bHasCurves);
            if (!bHasCurves)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            IPointCollection5 PtColl = (IPointCollection5)pResultGeom;

            if (PtColl.PointCount > 1)
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }
            IPolycurve pPolyCurve4Tangent = pFoundLineGeom as IPolycurve;

            for (int j = 0; j < PtColl.PointCount; j++)
            {
              IPoint p = PtColl.get_Point(j);
              IPoint outPoint = new Point();
              double dDistanceAlong = 0;
              double dDistanceFromCurve = 0;
              bool bOffsetRight = true;

              //work out if the point is to the left or right of the original
              inPolycurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
            ref dDistanceAlong, ref dDistanceFromCurve, ref bOffsetRight);

              ILine pTangent = new Line();
              dDistanceAlong = 0;
              dDistanceFromCurve = 0;
              bool bOnRight = true;

              pPolyCurve4Tangent.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, p, false, outPoint,
            ref dDistanceAlong, ref dDistanceFromCurve, ref bOnRight);
              pPolyCurve4Tangent.QueryTangent(esriSegmentExtension.esriNoExtension, dDistanceAlong, false, 100, pTangent);

              //compare the tangent bearing with the normal to check for orthogonality
              IVector3D vecTangent = new Vector3DClass();
              vecTangent.PolarSet(pTangent.Angle, 0, 1);

              IVector3D vecNormal = new Vector3DClass();
              vecNormal.PolarSet(pNormalLine.Angle, 0, 1);

              ILine pHitDistanceForRadiusDifference = new Line();
              pHitDistanceForRadiusDifference.PutCoords(pNormalLine.FromPoint, outPoint);
              double dRadiusDiff = pHitDistanceForRadiusDifference.Length;

              double dDotProd = vecTangent.DotProduct(vecNormal);
              double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
              dAngleCheck = Math.Abs(dAngleCheck - 90);

              if (dAngleCheck < AngleToleranceTangentCompareInDegrees)
              {
            //work out concavity orientation with respect to the original line using the radius sign and dot product
            dDotProd = vecOriginalSelected.DotProduct(vecTangent);
            double dTangentCheck = Math.Acos(dDotProd) * 180 / Math.PI; // in degrees
            //dTangentCheck at this point should be close to 0 or 180 degrees.
            outFoundLinesCount++;

            bool bIsConvex = ((dTangentCheck < 90 && dRadius < 0 && !bOffsetRight) ||
                              (dTangentCheck > 90 && dRadius > 0 && !bOffsetRight) ||
                              (dTangentCheck < 90 && dRadius > 0 && bOffsetRight) ||
                              (dTangentCheck > 90 && dRadius < 0 && bOffsetRight));

            double dUnitSignChange = 1;

            if (!bIsConvex)
              dUnitSignChange = -1;

            double dDerivedRadius = (Math.Abs(dRadius)) + dRadiusDiff * dUnitSignChange;

            dUnitSignChange = 1;
            //now compute inferred left/right for candidate
            if (bIsConvex && !bOffsetRight)
              dUnitSignChange = -1;

            if (!bIsConvex && bOffsetRight)
              dUnitSignChange = -1;

            dDerivedRadius = dDerivedRadius * dUnitSignChange;

            string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
              iCtrPoint.ToString() + "," + dRadiusDiff.ToString("#.000");
            CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);
              }
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              bool bHasParallelCurveFeaturesNearby = (outFoundLinesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }
Exemplo n.º 24
0
        /// <summary>
        /// 根据点集坐标绘制线要素
        /// </summary>
        /// <params name="featureLayer"></params>
        /// <params name="lstPoint"></params>
        public void CreateLine(IFeatureLayer featureLayer, List <IPoint> lstPoint, int ID)
        {
            //try
            //{
            IFeatureClass featureClass = featureLayer.FeatureClass;

            if (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                IPointCollection multipoint = new MultipointClass();
                if (lstPoint.Count < 2)
                {
                    MessageBox.Show(@"请选择两个及两个以上点数。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                ISegmentCollection pPath = new PathClass();
                ILine    pLine;
                ISegment pSegment;
                object   o = Type.Missing;
                for (int i = 0; i < lstPoint.Count - 1; i++)
                {
                    pLine = new LineClass();
                    pLine.PutCoords(lstPoint[i], lstPoint[i + 1]);
                    pSegment = pLine as ISegment;
                    pPath.AddSegment(pSegment, ref o, ref o);
                }
                IGeometryCollection pPolyline = new PolylineClass();
                pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);

                IDataset       dataset       = (IDataset)featureClass;
                IWorkspace     workspace     = dataset.Workspace;
                IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();

                IFeature feature = featureClass.CreateFeature();

                IGeometry geometry = pPolyline as IGeometry;
                DrawCommon.HandleZMValue(feature, geometry);//几何图形Z值处理

                feature.Shape = pPolyline as PolylineClass;
                int iFieldID = feature.Fields.FindField(GIS_Const.FIELD_BID);
                feature.Value[iFieldID] = ID.ToString();
                feature.Store();
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(false);

                IEnvelope envelop = feature.Shape.Envelope;
                DataEditCommon.g_pMyMapCtrl.ActiveView.Extent = envelop;
                DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
            }
            else
            {
                MessageBox.Show(@"请选择线图层。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //}
            //catch
            //{
            //    return;
            //}
        }
Exemplo n.º 25
0
        /// <summary>
        /// 绘制曲线部分
        /// </summary>
        /// <params name="lyr">推断断层</params>
        /// <params name="newplines">延长点构造的线</params>
        /// <params name="originlines">原始点构造的线</params>
        private void AddCurveToMap(IFeatureLayer lyr, List <IPolyline> newplines, List <IPolyline> originlines)
        {
            IFeatureClass  Featureclass = lyr.FeatureClass;
            IWorkspaceEdit workspace    = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;

            workspace.StartEditing(true);
            workspace.StartEditOperation();
            object missing = Type.Missing;
            //揭露断层上的曲线对象
            IGeometry geom = new PolylineClass();

            geom.SpatialReference = Global.spatialref;
            IGeometryCollection outgeomcols = geom as IGeometryCollection;
            IFeature            fea         = Featureclass.CreateFeature();
            ISegmentCollection  newpath     = new PathClass();
            int kindpos = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_TYPE);
            int bidpos  = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_BID);

            for (int i = 0; i < newplines.Count; i++)
            {
                ILine lin = new LineClass();
                lin.SpatialReference = Global.spatialref;
                //直线段
                IPath path = new PathClass();
                if (i == 0)
                {
                    lin.FromPoint = newplines[i].FromPoint;
                    lin.ToPoint   = originlines[i].ToPoint;
                }
                else if (i == originlines.Count - 1)
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint   = newplines[i].ToPoint;
                }
                else
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint   = originlines[i].ToPoint;
                }
                newpath.AddSegment(lin as ISegment, ref missing, ref missing);
                //曲线段
                if (i < newplines.Count - 1)
                {
                    IBezierCurveGEN bezier      = new BezierCurveClass();
                    IPoint[]        pntcontrols = new IPoint[4];
                    pntcontrols[0] = originlines[i].ToPoint;
                    pntcontrols[1] = newplines[i].ToPoint;
                    pntcontrols[2] = newplines[i + 1].FromPoint;
                    pntcontrols[3] = originlines[i + 1].FromPoint;
                    bezier.PutCoords(ref pntcontrols);

                    newpath.AddSegment(bezier as ISegment, ref missing, ref missing);
                }
            }
            outgeomcols.AddGeometry(newpath as IGeometry, ref missing, ref missing);
            int          index       = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
            IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;

            if (geometryDef.HasZ)
            {
                IZAware pZAware = (IZAware)outgeomcols;
                pZAware.ZAware = true;
            }
            fea.Shape = outgeomcols as IPolyline;
            fea.set_Value(kindpos, 1);
            fea.set_Value(bidpos, BID);
            fea.Store();
            //外围曲线绘制
            ITopologicalOperator2 top = outgeomcols as ITopologicalOperator2;

            if (!top.IsSimple)
            {
                top.Simplify();
            }
            IConstructCurve curve = new PolylineClass();

            curve.ConstructOffset(outgeomcols as IPolyline, -3, ref missing, ref missing);
            IPolyline plinnew = curve as IPolyline;

            plinnew.SpatialReference = Global.spatialref;
            plinnew.FromPoint        = newplines[0].FromPoint;
            plinnew.ToPoint          = newplines[newplines.Count - 1].ToPoint;

            IFeature outcurve = Featureclass.CreateFeature();

            outcurve.set_Value(kindpos, 2);
            outcurve.set_Value(bidpos, BID);
            outcurve.Shape = plinnew;
            outcurve.Store();
            //结束编辑
            workspace.StopEditOperation();
            workspace.StopEditing(true);
            //定位跳转
            Global.commonclss.JumpToGeometry(plinnew);
        }
Exemplo n.º 26
0
        public static IPolyline CreatePolyline(object[] paths)
        {
            IPolyline           result   = null;
            IGeometryCollection pGeomCol = new PolylineClass();
            object objMissing            = Type.Missing;

            foreach (object o in paths)//part
            {
                object[] ringpoints = o as object[];
                if (ringpoints != null)
                {
                    ISegmentCollection pSegCol = new PathClass();
                    ISegment           pSeg    = new LineClass();
                    IPoint             pFromPt = new PointClass();
                    IPoint             pToPt   = new PointClass();
                    IPoint             pEndPt  = new PointClass();

                    List <PointObject> poList = new List <PointObject>();
                    foreach (object po in ringpoints)
                    {
                        PointObject pObj  = new PointObject();
                        object[]    ptxya = po as object[];
                        if (ptxya != null)
                        {
                            if (ptxya.Length == 3)
                            {
                                pObj.X = double.Parse(ptxya[0].ToString());
                                pObj.Y = double.Parse(ptxya[1].ToString());
                                pObj.A = int.Parse(ptxya[2].ToString());
                            }
                            else if (ptxya.Length == 2)
                            {
                                pObj.X = double.Parse(ptxya[0].ToString());
                                pObj.Y = double.Parse(ptxya[1].ToString());
                                pObj.A = 0;
                            }
                            else
                            {
                                throw new Exception("坐标串输入错误!");
                            }
                            poList.Add(pObj);
                        }
                    }

                    if (poList.Count < 2)
                    {
                        throw new Exception("至少保证两个点来确定一条线!");
                    }

                    for (int i = 0; i < poList.Count - 1; i++)
                    {
                        if (poList[i].A.Equals(1))//处理狐段
                        {
                            PointObject poF = null;
                            PointObject poT = null;
                            PointObject poE = null;
                            if (i - 1 < 0)
                            {
                                poF = poList[poList.Count - 2];
                            }
                            else
                            {
                                poF = poList[i - 1];
                            }
                            poT = poList[i];
                            poE = poList[i + 1];

                            pFromPt.PutCoords(poF.X, poF.Y);
                            pToPt.PutCoords(poT.X, poT.Y);
                            pEndPt.PutCoords(poE.X, poE.Y);

                            //圆弧
                            ICircularArc          cirularArc           = new CircularArcClass();
                            IConstructCircularArc constructCircularArc = cirularArc as IConstructCircularArc;
                            constructCircularArc.ConstructThreePoints(pFromPt, pToPt, pEndPt, true);
                            pSeg = cirularArc as ISegment;
                            pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing);
                        }
                        else
                        {
                            if (poList[i + 1].A.Equals(0))//处理直线,否则不处理
                            {
                                pFromPt.PutCoords(poList[i].X, poList[i].Y);
                                pToPt.PutCoords(poList[i + 1].X, poList[i + 1].Y);

                                pSeg           = new LineClass();
                                pSeg.FromPoint = pFromPt;
                                pSeg.ToPoint   = pToPt;
                                //一根线段
                                pSegCol.AddSegment(pSeg, ref objMissing, ref objMissing);
                            }
                        }
                    }

                    //一个part
                    pGeomCol.AddGeometry(pSegCol as IGeometry, ref objMissing, ref objMissing);
                }
            }

            result = pGeomCol as IPolyline;

            return(result);
        }
Exemplo n.º 27
0
        public bool HasTangentCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
  double AngleToleranceTangentCompareInDegrees, double StraightLinesBreakLessThanInDegrees, double MaximumDeltaInDegrees, double ExcludeTangentsShorterThan, 
      out int outFoundTangentCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundTangentCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pTangentLineAtEnd = new Line(); //new
              ILine pTangentLineAtStart = new Line(); //new
              object objMissing = Type.Missing;

              for (int i = 0; i < 2; i++)
              {
            ILine pThisLine = null;
            if (i == 0)
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 0.2, pTangentLineAtEnd);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtEnd.FromPoint, pTangentLineAtEnd.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            else
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 0.2, pTangentLineAtStart);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtStart.FromPoint, pTangentLineAtStart.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            //Create a new path for each line.

            ISegmentCollection newPath = new PathClass();
            newPath.AddSegment((ISegment)pThisLine, ref objMissing, ref objMissing);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref objMissing, ref objMissing);
              }

              //now buffer the lines
              IGeometryCollection outBufferedGeometryCol = new GeometryBagClass();
              for (int jj = 0; jj < geometryCollection2.GeometryCount; jj++)
              {
            IPath pPath = geometryCollection2.get_Geometry(jj) as IPath;
            IGeometryCollection pPolyL = new PolylineClass();
            pPolyL.AddGeometry((IGeometry)pPath);

            ITopologicalOperator topologicalOperator = (ITopologicalOperator)pPolyL;
            IPolygon pBuffer = topologicalOperator.Buffer(0.1) as IPolygon;
            outBufferedGeometryCol.AddGeometry(pBuffer, ref objMissing, ref objMissing);
              }
              ITopologicalOperator pUnionedBuffers = null;
              pUnionedBuffers = new PolygonClass() as ITopologicalOperator;
              pUnionedBuffers.ConstructUnion((IEnumGeometry)outBufferedGeometryCol);

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = (IGeometry)pUnionedBuffers;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }
              IVector3D vecFoundGeom = new Vector3DClass();
              IFeature pFeat = pFeatCursLines.NextFeature();
              bool bHasTangentStraightLineAtJunction = false;
              List<int> lstLargeBreak = new List<int>();

              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;
            IPolycurve pFoundLineAsPolyCurve = pFoundLineGeom as IPolycurve;
            int iRelativeOrientation = GetRelativeOrientation(pFoundLineAsPolyCurve, inPolycurve);
            //iRelativeOrientation == 1 --> closest points are original TO and found TO
            //iRelativeOrientation == 2 --> closest points are original TO and found FROM
            //iRelativeOrientation == 3 --> closest points are original FROM and found TO
            //iRelativeOrientation == 4 --> closest points are original FROM and found FROM

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            val = pFeat.get_Value(idxCenterPointID);

            IPolycurve pPolyCurve = pFoundLineGeom as IPolycurve;

            ILine pFoundChordCandidate = new LineClass();
            pFoundChordCandidate.PutCoords(pPolyCurve.FromPoint, pPolyCurve.ToPoint);
            //first check for liklihood that subject line is supposed to stay straight, by
            //geometry chord bearing angle break test
            vecFoundGeom.PolarSet(pFoundChordCandidate.Angle, 0, 1);
            double dDotProd = vecFoundGeom.DotProduct(vecOriginalSelected);
            double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            double dLargeAngleBreakInDegrees = 3;
            if (dAngleCheck > dLargeAngleBreakInDegrees && dAngleCheck < (180 - dLargeAngleBreakInDegrees)) //large angle break non-tangent, greater than 3 degrees
            {
              if (!lstLargeBreak.Contains(iRelativeOrientation))
            lstLargeBreak.Add(iRelativeOrientation);
            }

            if ((dAngleCheck <= StraightLinesBreakLessThanInDegrees || (180 - dAngleCheck) < StraightLinesBreakLessThanInDegrees)
            && val == DBNull.Value && dRadius == 0 && !(pPolyCurve.Length< ExcludeTangentsShorterThan))
            {
              if (lstLargeBreak.Contains(iRelativeOrientation))
            bHasTangentStraightLineAtJunction = true;
            }

            if (val == DBNull.Value || dRadius == 0 || pPolyCurve.Length< ExcludeTangentsShorterThan)
            {//if the feature has a null centrpointID then skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            if (Math.Abs(inPolycurve.Length / dRadius * 180 / Math.PI) > MaximumDeltaInDegrees)
            {
              //if the resulting curve would have a central angle more than MaximumDeltaInDegrees degrees then skip
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            //if geometry of curve neighbour curves have been cracked then there can be more than one segment
            //however since all segments would be circular arcs, just need to test the first segment
            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            ISegment pSeg = pFoundLineGeomSegs.get_Segment(0);
            if (!(pSeg is ICircularArc))
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            dRadius = (double)pFeat.get_Value(idxRadius);

            IVector3D vect1 = new Vector3DClass();
            IVector3D vect2 = new Vector3DClass();
            ILine tang = new Line();
            double dUnitSignChange = 1;
            if (iRelativeOrientation == 1) //closest points are original TO and found TO
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 2)//closest points are original TO and found FROM
            {
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 3)//closest points are original FROM and found TO
            {
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 4)//closest points are original FROM and found FROM
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }

            dDotProd = vect1.DotProduct(vect2);
            dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            if (dAngleCheck < AngleToleranceTangentCompareInDegrees || (180 - dAngleCheck) < AngleToleranceTangentCompareInDegrees)
            {

              double dDerivedRadius = dRadius * dUnitSignChange;

              string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
            iCtrPoint.ToString() + "," + "t";
              CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);

              outFoundTangentCurvesCount++;
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              if (bHasTangentStraightLineAtJunction)
            return false; //open to logic change to be less conservative

              bool bHasParallelCurveFeaturesNearby = (outFoundTangentCurvesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }