C#与ArcGIS Engine生产面状图形

本文介绍了一个使用ArcGIS进行图形绘制的示例程序。通过定义坐标点并连接这些点来创建一个多边形,并设置了多边形的填充颜色。该程序演示了如何在地图上绘制特定的多边形形状。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;

namespace 选择元素
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //定义颜色方法
        private IRgbColor GetRGB(int r, int g, int b)
        {
            IRgbColor pRgbColor = new RgbColorClass();  //利用 IRgbColor 接口,分别设置R、G、B三个值参数
            pRgbColor.Red = r;
            pRgbColor.Green = g;
            pRgbColor.Blue = b;
            return pRgbColor;   // 返回对象值
        }

        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
                IMap pMap;
                IActiveView pActiveView;
                pMap = axMapControl1.Map;
                pActiveView = pMap as IActiveView;
            
                ISegmentCollection pSegColl;
                ILine pLine;
                IRing pRing;
                pSegColl = new RingClass();
                pLine = new LineClass();
                IPoint pPt1 = new PointClass();
                pPt1.PutCoords(100, 100);
                IPoint pPt2 = new PointClass();
                pPt2.PutCoords(200, 100);
                IPoint pPt3 = new PointClass();
                pPt3.PutCoords(200, 300);
                IPoint pPt4 = new PointClass();
                pPt4.PutCoords(100, 600);
                pLine.PutCoords(pPt1, pPt2);    //点pPt1、pPt2……pPt4等的位置不一样,出来的图形效果是不一样的
                object Missing1 = Type.Missing;
                object Missing2 = Type.Missing;
                pSegColl.AddSegment(pLine as ISegment, ref Missing1, ref Missing2);
                pLine = new LineClass();
                pLine.PutCoords(pPt2, pPt3);
                pSegColl.AddSegment(pLine as ISegment, ref Missing1, ref Missing2);
                pLine = new LineClass();
                pLine.PutCoords(pPt3, pPt4);
                pSegColl.AddSegment(pLine as ISegment, ref Missing1, ref Missing2);
                pRing = pSegColl as IRing;
                pRing.Close();
                IGeometryCollection pPolygon = new PolygonClass();
                pPolygon.AddGeometry(pRing, ref Missing1, ref Missing2);
                ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbolClass();    //填充样式以及颜色
                pSimpleFillSym.Style = esriSimpleFillStyle.esriSFSSolid;
                pSimpleFillSym.Color = GetRGB(250, 50, 100);
                IFillShapeElement pPolygonEle = new PolygonElementClass();
                pPolygonEle.Symbol = pSimpleFillSym;
                IElement pEle = pPolygonEle as IElement;
                pEle.Geometry = (IGeometry)pPolygon;
                IGraphicsContainer pGraphicsContainer;
                pGraphicsContainer = pMap as IGraphicsContainer;
                pGraphicsContainer.AddElement(pEle, 0);
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
        }

     
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值