• 大小: 22KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-06
  • 语言: C#
  • 标签: 道格拉斯  演示  代码  

资源简介

使用C#编写的道格拉斯算法,经由弹出的窗口用鼠标绘制任意曲线来演示道格拉斯的算法

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GIS
{
    public partial class Form1 : Form
    {
        private Boolean _calculateDouglasPeuckerReduction = false;
        private List _amerenPoints = new List();

        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            List drawingPoints = new List();
            foreach (GIS.Point point in _amerenPoints)
            {
                drawingPoints.Add(new System.Drawing.Point(Convert.ToInt32(point.X) Convert.ToInt32(point.Y)));
            }
            if (drawingPoints.Count > 2)
            {
                e.Graphics.DrawLines(new Pen(Brushes.Black 2) drawingPoints.ToArray());
                lblOriginal.Text = drawingPoints.Count.ToString();

                if (_calculateDouglasPeuckerReduction)
                {
                    List points = Utility.DouglasPeuckerReduction(_amerenPoints Convert.ToDouble(nudTolerance.Value));

                    drawingPoints = new List();
                    foreach (GIS.Point point in points)
                    {
                        drawingPoints.Add(new System.Drawing.Point(Convert.ToInt32(point.X) Convert.ToInt32(point.Y)));
                    }

                    e.Graphics.DrawLines(new Pen(Brushes.Red 2) drawingPoints.ToArray());
                    lblSimplified.Text = drawingPoints.Count.ToString();
                }
            }

            base.OnPaint(e);

        }

        private void Form1_MouseMove(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _amerenPoints.Add(new GIS.Point(e.X e.Y));
                this.Invalidate();
            }
        }

        private void Form1_MouseUp(object sender MouseEventArgs e)
        {
            //DO the calculation
            _calculateDouglasPeuckerReduction = true;
            this.Invalidate();
        }

        private void Form1_MouseDown(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _amerenPoints.Clear();
                _calculateDouglasPeuckerReduction = false;
            }
        }

        private void nudTolerance_ValueChanged(object sender EventArgs e)
        {
            this.Invalidate();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2007-06-06 13:25  GIS\bin\
     目录           0  2007-06-06 13:35  GIS\bin\Debug\
     文件       24576  2007-05-25 07:06  GIS\bin\Debug\GIS.exe
     文件        5632  2005-09-23 07:56  GIS\bin\Debug\GIS.vshost.exe
     文件        2692  2007-05-25 07:10  GIS\Form1.cs
     文件        5381  2007-05-25 07:06  GIS\Form1.Designer.cs
     文件        5814  2007-05-25 07:06  GIS\Form1.resx
     文件        3324  2007-05-25 07:03  GIS\GIS.csproj
     文件         894  2007-05-25 07:10  GIS\GIS.sln
     文件       13824  2007-05-25 07:10  GIS\GIS.suo
     文件        2060  2007-05-25 07:03  GIS\Point.cs
     文件         470  2007-05-25 06:59  GIS\Program.cs
     目录           0  2007-06-06 13:35  GIS\Properties\
     文件        1266  2007-05-25 06:59  GIS\Properties\AssemblyInfo.cs
     文件        2831  2007-05-25 07:03  GIS\Properties\Resources.Designer.cs
     文件        5612  2007-05-25 06:59  GIS\Properties\Resources.resx
     文件        1082  2007-05-25 07:03  GIS\Properties\Settings.Designer.cs
     文件         249  2007-05-25 06:59  GIS\Properties\Settings.settings
     文件        9932  2007-06-06 13:35  GIS\Utility.cs
     目录           0  2007-06-06 13:35  GIS\

评论

共有 条评论