資源簡介
Douglas一Peukcer算法是目前公認的線狀要素化簡經典算法。C#編寫,使用很方便
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Collections;
using?System.Drawing;
namespace?MapControlApplication2
{
????class?Douglasclass
????{
????????///?
????????///?使用“道格拉斯—普克”算法減少點的數量
????????///?
????????///?需要減少的點
????????///?偏差
????????///?得到減少過后的結果點
????????public?List?DouglasPeuckerReduction(List?Points?Double?Tolerance)
????????{
????????????//if?(Tolerance?==?0)?return?Points;
????????????if?(Points?==?null?||?Points.Count?3)//如果點的數量小于3個則返回
????????????????return?Points;
????????????Int32?firstPoint?=?0;
????????????Int32?lastPoint?=?Points.Count?-?1;
????????????List?pointIndexsToKeep?=?new?List();
????????????//把第一個點和最后一個點的序號加入要保存的序號?對于數據中第一個和最后一個點重合的情況不壓縮
????????????pointIndexsToKeep.Add(firstPoint);
????????????pointIndexsToKeep.Add(lastPoint);
????????????//第一個點和最后一個點不能為同一個點
????????????while?(Points[firstPoint].Equals(Points[lastPoint]))
????????????{
????????????????lastPoint--;
????????????}
????????????DouglasPeuckerReduction(Points?firstPoint?lastPoint?Tolerance?ref?pointIndexsToKeep);//道格拉斯-普克壓縮
????????????List?returnPoints?=?new?List();
????????????pointIndexsToKeep.Sort();//對保留下來的序號進行排序
????????????foreach?(Int32?index?in?pointIndexsToKeep)
????????????{
????????????????returnPoints.Add(Points[index]);//將對應序號的點加入
????????????}
????????????return?returnPoints;//返回壓縮后的點
????????}
????????
????????///?
????????///?道格拉斯-普克壓縮
????????///?
????????///?要處理的點
????????///?第一個點
????????///?最后一個點
????????///?偏差
????????///?要保留點的索引號
????????private?static?void?DouglasPeuckerReduction(List?points?Int32?firstPoint?Int32?lastPoint?Double?tolerance?ref?List?pointIndexsToKeep)
????????{
????????????Double?maxDistance?=?0;
????????????Int32?indexFarthest?=?0;
????????????for?(Int32?inde
- 上一篇:佳博打印機.net平臺下的開發API
- 下一篇:Emgucv3.0(c#)簡單入門
評論
共有 條評論