Arcgis---画线

画线

List<ESRI.ArcGIS.Geometry.IPoint> linePoints = new List<ESRI.ArcGIS.Geometry.IPoint>();
for (int i = 0; i < rayList.Count; i++)
{
    // GeometryUtilities定义见下文
    p = GeometryUtilities.ConstructPoint3D(list[i].X, list[i].Y, list[i].Z);  // list里存自己定义的类
    linePoints.Add(p);                      
}

// GISMapApplication定义见下文
IGraphicsLayer pGraphicsLayer = (GISMapApplication.Instance.Scene as IBasicMap).BasicGraphicsLayer;
// DrawUtilities定义见下文
DrawUtilities.DrawLine(pGraphicsLayer as IGraphicsContainer3D, linePoints);

GeometryUtilities部分代码

    public static class GeometryUtilities
    {
         private static object _missing = Type.Missing;

        public static void MakeZAware(IGeometry geometry)
        {
            IZAware zAware = geometry as IZAware;
            zAware.ZAware = true;
        }

        public static IPoint ConstructPoint3D(double x, double y, double z)
        {
            IPoint point = ConstructPoint2D(x, y);
            point.Z = z;

            MakeZAware(point as IGeometry);

            return point;
        }

        public static IPoint ConstructPoint2D(double x, double y)
        {
            IPoint point = new PointClass();
            point.X = x;
            point.Y = y;
            return point;
        }
    }

GISMapApplication部分代码

    public class GISMapApplication
    {
        #region 私有字段
        private static GISMapApplication instance = null; //当前对象的实例
        private AxSceneControl m_axSceneControl = null;

        public AxSceneControl AxSceneControl
        {
            get { return m_axSceneControl; }
            set { m_axSceneControl = value; }
        }
        private ISceneControl m_sceneControl = null;
        private ISceneGraph m_SceneGraph = null;
        private static System.Object m_syncObject = new System.Object();   // 同步对象
        #endregion 私有字段

        /// <summary>
        /// 地图控件的引用
        /// </summary>
        public ISceneControl SceneControl
        {
            get { return m_sceneControl; }
            set { m_sceneControl = value; }
        }
        /// <summary>
        /// 图形接口
        /// </summary>
        public ISceneGraph SceneGraph
        {
            get { return m_SceneGraph; }
        }
        private IScene m_Scene = null;

        /// <summary>
        /// 场景
        /// </summary>
        public IScene Scene
        {
            get { return m_Scene; }
            set { m_Scene = value; }
        }

        /// <summary>
        /// 当前实例对象(单例模式)
        /// </summary>
        public static GISMapApplication Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (m_syncObject)
                    {
                        if (instance == null)
                        {
                            instance = new GISMapApplication();
                        }
                    }

                }
                return instance;
            }
        }


        /// <summary>
        /// 初始化的一些方法
        /// </summary>
        public void Init(AxSceneControl axSceneControl)
        {
            if (axSceneControl != null)
            {
                this.m_axSceneControl = axSceneControl;
                m_sceneControl = axSceneControl.Object as ISceneControl;
                m_SceneGraph = m_sceneControl.SceneGraph;
                m_Scene = m_sceneControl.Scene;
            }
        }
    }

DrawUtilities部分代码

    public static class DrawUtilities
    {
        private static object _missing = Type.Missing;

        public static void DrawLine(IGraphicsContainer3D lineGraphicsContainer3D, List<IPoint> listPoints)
        {
            IPointCollection linePointColl = new PolylineClass();
            foreach (var point in listPoints)
            {
                linePointColl.AddPoint(point, ref _missing, ref _missing);
            }
            DrawUtilities.DrawLine(lineGraphicsContainer3D, linePointColl);
        }

        public static void DrawLine(IGraphicsContainer3D lineGraphicsContainer3D, IPointCollection linePointCollection)
        {
            const esriSimple3DLineStyle lineStyle = esriSimple3DLineStyle.esriS3DLSTube;
            const double lineWidth = 1;
            IColor lineColor = ColorUtilities.GetColor(255, 0, 0);
            GeometryUtilities.MakeZAware(linePointCollection as IGeometry);

// GraphicsLayer3DUtilities定义见下文
 GraphicsLayer3DUtilities.AddLineToGraphicsLayer3D(lineGraphicsContainer3D, linePointCollection as IGeometry, lineColor, lineStyle, lineWidth);
        }
   }

GraphicsLayer3DUtilities部分代码

    public static class GraphicsLayer3DUtilities
    {
        public static void AddLineToGraphicsLayer3D(IGraphicsContainer3D graphicsContainer3D, IGeometry geometry, IColor color, esriSimple3DLineStyle style, double width)
        {
           //ElementUtilities定义见下文
           graphicsContainer3D.AddElement(ElementUtilities.ConstructPolylineElement(geometry, color, style, width));
        }
    }

ElementUtilities部分代码

     public static class ElementUtilities
    {
        private const double HighResolution = 1;
        private const esriUnits Units = esriUnits.esriUnknownUnits;

        public static IElement ConstructPolylineElement(IGeometry geometry, IColor color, esriSimple3DLineStyle style, double width)
        {
            ISimpleLine3DSymbol simpleLine3DSymbol = new SimpleLine3DSymbolClass();
            simpleLine3DSymbol.Style = style;
            simpleLine3DSymbol.ResolutionQuality = HighResolution;

            ILineSymbol lineSymbol = simpleLine3DSymbol as ILineSymbol;
            lineSymbol.Color = color;
            lineSymbol.Width = width;

            ILine3DPlacement line3DPlacement = lineSymbol as ILine3DPlacement;
            line3DPlacement.Units = Units;

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

            IElement element = lineElement as IElement;
            element.Geometry = geometry;

            return element;
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值