www.pudn.com > ArcgisMapOperation.rar > UserGeometryGenerate.cs


using System; 
using System.Collections.Generic; 
using System.Text; 
 
using ESRI.ArcGIS.Geometry; 
using ESRI.ArcGIS.Carto; 
using ESRI.ArcGIS.Display; 
using ESRI.ArcGIS.Geodatabase; 
 
namespace ArcgisMapOperation.EsriLib 
{ 
    public class UserGeometryGenerate 
    { 
        ///  
        /// 生成曲线 
        ///  
        ///  
        ///  
        ///  
        public static IPolyline CreatePolyline(IPoint pntStart, IPoint pntEnd) 
        { 
            IPolyline polyline = new PolylineClass(); 
 
            polyline.FromPoint = pntStart; 
            polyline.ToPoint = pntEnd; 
 
            return polyline; 
        } 
 
        ///  
        /// 生成多边形 
        ///  
        ///  
        ///  
        ///  
        public static IPolygon CreatePolygon(IPoint pntStart, IPoint pntEnd) 
        { 
            IPolygon polygon = new PolygonClass(); 
 
            polygon.FromPoint = pntStart; 
            polygon.ToPoint = pntEnd; 
 
            return polygon; 
        } 
 
        ///  
        /// 生成直线 
        ///  
        ///  
        ///  
        ///  
        public static ILine CreateLine(IPoint pntStart, IPoint pntEnd) 
        { 
            ILine line = new LineClass(); 
 
            line.FromPoint = pntStart; 
            line.ToPoint = pntEnd; 
 
            return line; 
        } 
 
        ///  
        /// 设置画图的前提,橡皮条跟踪 
        ///  
        ///  
        ///  
        ///  
        public static IScreenDisplay InitSceenDisplay(IActiveView pActiveView, IGeometry pGeometry) 
        { 
            IScreenDisplay pScreenDisplay;//屏幕显示 
            IRubberBand pRubberPolygon;//橡皮条跟踪 
            ISimpleFillSymbol pFillSymbol;//设置样式 
            IRgbColor pRgbColor;//颜色 
 
            //Draw Polygon  
            pScreenDisplay = pActiveView.ScreenDisplay; 
 
            pFillSymbol = new SimpleFillSymbol(); 
            pRgbColor = new RgbColor(); 
            pRgbColor.NullColor = true; 
            pFillSymbol.Color = pRgbColor; 
             
            pRubberPolygon = new RubberPolygon(); 
            pRubberPolygon.TrackExisting(pScreenDisplay, pFillSymbol as ISymbol,pGeometry); 
             
            return pScreenDisplay; 
        } 
 
        ///  
        /// 屏幕画图 
        ///  
        ///  
        ///  
        public static void DrawGeometry(IScreenDisplay pScreenDisplay,IGeometry pGeometry) 
        { 
            ISimpleFillSymbol pFillSymbol;//设置样式 
            IRgbColor pRgbColor;//颜色 
 
            //Draw Polygon  
            pFillSymbol = new SimpleFillSymbol(); 
            pRgbColor = new RgbColor(); 
            pRgbColor.NullColor = true; 
            pFillSymbol.Color = pRgbColor; 
 
            pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0); 
            pScreenDisplay.SetSymbol(pFillSymbol as ISymbol); 
            pScreenDisplay.DrawPolygon(pGeometry); 
            pScreenDisplay.FinishDrawing(); 
        } 
 
        ///  
        /// 生成GEOMETRY 
        ///  
        ///  
        ///  
        public static IGeometry GetGeomtry(IActiveView pActiveView,IPoint pntStart) 
        { 
            IScreenDisplay pScreenDisplay;//屏幕显示 
            IRubberBand pRubberPolygon;//橡皮条跟踪 
            ISimpleFillSymbol pFillSymbol;//设置样式 
            IRgbColor pRgbColor;//颜色 
 
            //Draw Polygon  
            pScreenDisplay = pActiveView.ScreenDisplay; 
            pRubberPolygon = new RubberPolygon(); 
            pFillSymbol = new SimpleFillSymbol(); 
            pRgbColor = new RgbColor(); 
            pRgbColor.NullColor = true; 
 
            pFillSymbol.Color = pRgbColor; 
 
            pScreenDisplay.PanMoveTo(pntStart); 
            IGeometry pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, pFillSymbol as ISymbol); 
 
            pScreenDisplay.StartDrawing(pScreenDisplay.hDC, 0); 
            pScreenDisplay.SetSymbol(pFillSymbol as ISymbol); 
            pScreenDisplay.DrawPolygon(pPolygon); 
            pScreenDisplay.FinishDrawing(); 
 
            return pPolygon; 
        } 
    } 
}