using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using GrxCAD.Geometry; using GrxCAD.DatabaseServices; using GrxCAD.ApplicationServices; using GrxCAD.EditorInput; namespace HCTools { public struct Contourpoint { public double x; public double y; public double z; public ObjectId objID; } /// /// 记录闭合等高线高程和距高程点距离 /// 包含高程和距离 /// public struct closecontour { public double elevation; public double interval; } /// /// 判断点线是否有矛盾 /// class ChPLContradiction { public static int blc;//比例尺 public static string sqx;//首曲线 public static string jqx;//计曲线 public const int looptimes = 5;//循环查找次数 public static string elevationLayer;//高程点图层名 public int leng;//查找距离 int temp; public int windowwidth;//当前可视范围 public int windowheight; //存放所有高程点数组 public List pointarrlist = new List(); //存放有问题的高程点数组 public List errorpointarrlist = new List(); //存放无法识别点数组 public List unrecognize = new List(); //存放搜索到的等高线用于判断是否重复 public List plltemp = new List(); public List pll2dtemp = new List(); /// /// 检测点线矛盾,并画圆标记出错误点 /// public void contourch() { Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; //清空各数组 pointarrlist.Clear(); errorpointarrlist.Clear(); double flagradius = 4.0 * blc / 1000;//画圆标记半径 leng = Convert.ToInt32(flagradius + 8);//确定搜索距离 temp = leng; windowwidth = 30 * 4 * blc / 1000;//确定可视范围 windowheight = 30 * 4 * blc / 1000; selectcontourpoint(elevationLayer);//选出高程点 if (pointarrlist.Count == 0) { return; } //开始计时 Stopwatch watch = new Stopwatch(); watch.Start(); LayerControl layerscontrol = new LayerControl(); string layname = "点线矛盾标记图层"; if (layerscontrol.haslayername(layname) == false) { colorgb col = new colorgb(255, 0, 0); layerscontrol.creatlayer(layname, col); } layname = "点线矛盾高程点图层"; if (layerscontrol.haslayername(layname) == false) { colorgb col = new colorgb(255, 255, 0); layerscontrol.creatlayer(layname, col); layerscontrol.movelayertofront(layname); } layname = "无法识别"; if (layerscontrol.haslayername(layname) == false) { colorgb colo = new colorgb(0, 255, 0); layerscontrol.creatlayer(layname, colo); } //遍历各高程点,检测是否高程值有错误 for (int i = 0; i < pointarrlist.Count; i++) { Contourpoint p = pointarrlist[i]; check(p); } Database database = HostApplicationServices.WorkingDatabase; //遍历各错误高程点,画圆标记出 for (int i = 0; i < errorpointarrlist.Count; i++) { Contourpoint p = errorpointarrlist[i]; double x = p.x; double y = p.y; double z = p.z; ObjectId id = p.objID; using (Transaction acTrans = database.TransactionManager.StartTransaction()) { ViewTableRecord currview = editor.GetCurrentView(); currview.CenterPoint = new Point2d(x, y); currview.ViewDirection = new Vector3d(0, 0, 1); currview.Width = windowwidth; currview.Height = windowheight; editor.SetCurrentView(currview); acTrans.Commit(); } Transaction traction = database.TransactionManager.StartTransaction(); DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable; makeflag(errorpointarrlist[i].x, errorpointarrlist[i].y, 0, flagradius, 1); Entity entity = (Entity)traction.GetObject(id, OpenMode.ForWrite); entity.Layer = "点线矛盾高程点图层"; //ViewTableRecord currview = editor.GetCurrentView(); //currview.CenterPoint = new Point2d(x, y); //currview.ViewDirection = new Vector3d(0, 0, 1); //currview.Width = windowwidth; //currview.Height = windowheight; //editor.SetCurrentView(currview); Point3d p1 = new Point3d(p.x - 4 * blc / 2000, p.y - 4 * blc / 2000, 0); Point3d p2 = new Point3d(p.x + 4 * blc / 2000, p.y + 4 * blc / 2000, 0); TypedValue[] typedvalue = new TypedValue[2]; typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0); typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, elevationLayer), 1); SelectionFilter filter = new SelectionFilter(typedvalue); PromptSelectionResult psr = editor.SelectCrossingWindow(p1, p2, filter); if (psr.Status == PromptStatus.OK) { SelectionSet set = psr.Value; ObjectId[] objs = new ObjectId[set.Count]; objs = set.GetObjectIds(); for (int ii = 0; ii < objs.Length; ii++) { Entity Text = (Entity)traction.GetObject(objs[ii], OpenMode.ForWrite); DBText T = (DBText)Text; double T_Value = Convert.ToDouble(T.TextString); if (T_Value == z) { T.Layer = "点线矛盾高程点图层"; } } } traction.Commit(); documentlock.Dispose(); } for (int i = 0; i < unrecognize.Count; i++) { makeflag(unrecognize[i].x, unrecognize[i].y, 0, flagradius, 2); } //耗时 watch.Stop(); long times = watch.ElapsedMilliseconds; //editor.Regen(); //editor.UpdateScreen(); editor.WriteMessage("\n" + "耗时:" + times.ToString() + "毫秒"); editor.WriteMessage("\n" + "检测到错误高程点" + errorpointarrlist.Count.ToString()); editor.WriteMessage("\n" + "检测到无法识别点" + unrecognize.Count.ToString()); editor.WriteMessage("\n"); } /// /// 在错误高程点处画圆标记 /// /// 圆的半径 public void makeflag(double x, double y, double z, double radius, int type) { Database database = HostApplicationServices.WorkingDatabase; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); Transaction traction = database.TransactionManager.StartTransaction(); try { BlockTable blocktable; blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord; blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Circle circ = new Circle(); if (type == 1) { circ.Layer = "点线矛盾标记图层"; } else if (type == 2) { circ.Layer = "无法识别"; } circ.Center = new Point3d(x, y, z); circ.Radius = radius; circ.Normal = new Vector3d(0, 0, 1); circ.SetDatabaseDefaults(); blocktablerecord.AppendEntity(circ); traction.AddNewlyCreatedDBObject(circ, true); traction.Commit(); } catch (GrxCAD.Runtime.Exception) { traction.Abort(); } finally { doclock.Dispose(); traction.Dispose(); } } /// /// 选出所有高程点,并取出其x,y,z坐标 /// /// 高程点图层名 public void selectcontourpoint(string layername) { Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database database = HostApplicationServices.WorkingDatabase; // 获得当前文档的编辑器 Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; // 创建一个 TypedValue 数组,用于定义过滤条件 TypedValue[] typedvalue = new TypedValue[1]; typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, layername), 0); // 赋值过滤条件给 SelectionFilter 对象 SelectionFilter selectionfilter = new SelectionFilter(typedvalue); // 要求在图形区域中手动选择对象 PromptSelectionResult psr = editor.GetSelection(selectionfilter); //自动选择图像区域全部对象 //PromptSelectionResult psr = editor.SelectAll(selectionfilter); if (psr.Status == PromptStatus.OK) { SelectionSet selectionset = psr.Value; ObjectId[] obj = new ObjectId[selectionset.Count]; obj = selectionset.GetObjectIds(); for (int i = 0; i < obj.Length; i++) { using (Transaction traction = database.TransactionManager.StartTransaction()) { ObjectId objid = obj[i]; //找到实体,取出高程点的x,y,z Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead); if (entity is BlockReference) { BlockReference blockreference = (BlockReference)entity; Contourpoint cp = new Contourpoint(); cp.x = Math.Round(blockreference.Position.X, 4, MidpointRounding.AwayFromZero); cp.y = Math.Round(blockreference.Position.Y, 4, MidpointRounding.AwayFromZero); cp.z = Math.Round(blockreference.Position.Z, 4, MidpointRounding.AwayFromZero); cp.objID = objid; pointarrlist.Add(cp); } traction.Commit(); } } editor.WriteMessage("\n" + "选中高程点数量:" + pointarrlist.Count.ToString()); } } /// /// 检查是否错误 /// public void check(Contourpoint p) { double x = Math.Round(p.x, 4, MidpointRounding.AwayFromZero); double y = Math.Round(p.y, 4, MidpointRounding.AwayFromZero); double z = Math.Round(p.z, 4, MidpointRounding.AwayFromZero); List toplist = calculatevalue(x, y, z, 1); List belowlist = calculatevalue(x, y, z, 3); //点在上下两条等高线中间情况 if ((toplist.Count > 0) && (belowlist.Count > 0)) { //1.一般情况 #region 一般情况 if (toplist[0] > belowlist[belowlist.Count - 1]) { //高程值上大小小 if (z >= toplist[0] || z <= belowlist[belowlist.Count - 1]) { errorpointarrlist.Add(p); return; } else return; } //高程值上小下大 if (toplist[toplist.Count - 1] < belowlist[0]) { if (z >= belowlist[0] || z <= toplist[toplist.Count - 1]) { errorpointarrlist.Add(p); return; } else return; } #endregion //点在左右半包围情况,上下高程相等,要么是最大,要么是最小,进行左右搜索比较 //2.半包围一般情况 #region 半包围一般情况 if ((toplist[0] == belowlist[0]) || (toplist[toplist.Count - 1] == belowlist[belowlist.Count - 1])) { List rightlist = calculatevalue(x, y, z, 4); List leftlist = calculatevalue(x, y, z, 2); if ((rightlist.Count > 0) && (leftlist.Count > 0)) { //高程值右大左小 if (rightlist[0] > leftlist[leftlist.Count - 1]) { if ((z >= rightlist[0]) || (z <= leftlist[leftlist.Count - 1])) { errorpointarrlist.Add(p); return; } else return; } //高程值右小左大 if (leftlist[0] > rightlist[rightlist.Count - 1]) { if ((z >= leftlist[0]) || (z <= rightlist[rightlist.Count - 1])) { errorpointarrlist.Add(p); return; } else return; } #endregion //3.大半包围或闭合情况,即上下左右高程值相等 #region 四面闭合 if ((rightlist[0] == leftlist[0]) || (rightlist[rightlist.Count - 1] == leftlist[leftlist.Count - 1])) { //ArrayList closecontourlist = new ArrayList(); List closecontourlist = new List(); closecontourlist = closecontourcheck(p, 1); if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 3); if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 2); if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 4); if (closecontourlist.Count < 2) { unrecognize.Add(p); return; } } } } //存储高程值计算等高距 List ele = new List(); if (closecontourlist.Count >= 2) { double minidistance = closecontourlist[0].interval; double contour = closecontourlist[0].elevation; ele.Add(contour); for (int i = 1; i < closecontourlist.Count; i++) { if (closecontourlist[i].interval < minidistance) { minidistance = closecontourlist[i].interval; contour = closecontourlist[i].elevation; } ele.Add(closecontourlist[i].elevation); } //从小到大排序 ele.Sort(); //等高距 double contourinterval = ele[1] - ele[0]; //中间高程最小 if (contour == ele[0]) { if ((z - ele[0] >= 0) || ((ele[0] - contourinterval) - z >= 0)) //if ((z > ele[0]) || z < (ele[0] - contourinterval)) { errorpointarrlist.Add(p); return; } else return; } //中间高程最大 if (contour == ele[ele.Count - 1]) { if ((z - (ele[ele.Count - 1] + contourinterval) >= 0) || ele[ele.Count - 1] - z >= 0) //if (z > (ele[ele.Count - 1] + contourinterval) || z < ele[ele.Count - 1]) { errorpointarrlist.Add(p); return; } else return; } } } #endregion } //4.上下左、上下右三方闭合 #region 上下左、上下右三方闭合 else { List closecontourlist = new List(); //找出等高线条数大于2的方向进行搜索 if (toplist.Count >= 2) { closecontourlist = closecontourcheck(p, 1); } else if (belowlist.Count >= 2) { closecontourlist = closecontourcheck(p, 3); } else if (leftlist.Count >= 2) { closecontourlist = closecontourcheck(p, 4); } else closecontourlist = closecontourcheck(p, 2); if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 3); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 1); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 4); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 2); } if (closecontourlist.Count >= 2) { compareelevation(p, closecontourlist); return; } else { unrecognize.Add(p); } } #endregion } } //上下方向没有搜索两条等高线,则向左右方向搜索 if (toplist.Count == 0 || belowlist.Count == 0) { checkleftright(p); } } /// /// 比较高程点值和该高程点左右等高线高程 /// public void checkleftright(Contourpoint p) { double x = Math.Round(p.x, 4, MidpointRounding.AwayFromZero); double y = Math.Round(p.y, 4, MidpointRounding.AwayFromZero); double z = Math.Round(p.z, 4, MidpointRounding.AwayFromZero); List rightlist = calculatevalue(x, y, z, 4); List leftlist = calculatevalue(x, y, z, 2); // if (rightlist.Count > 0 && leftlist.Count > 0) { //右大左小 if (rightlist[0] > leftlist[leftlist.Count - 1]) { if (z > rightlist[0] || z < leftlist[leftlist.Count - 1]) { errorpointarrlist.Add(p); return; } } //右小左大 if (leftlist[0] > rightlist[rightlist.Count - 1]) { if (z > leftlist[0] || z < rightlist[rightlist.Count - 1]) { errorpointarrlist.Add(p); return; } } //左右相等,左右上、或者左右下三方闭合 if ((leftlist[0] == rightlist[0]) || (leftlist[leftlist.Count - 1] == rightlist[rightlist.Count - 1])) { List toplist = calculatevalue(x, y, z, 1); List belowlist = calculatevalue(x, y, z, 3); #region //ArrayList closecontourlist = new ArrayList(); List closecontourlist = new List(); //找出等高线条数大于2的方向进行搜索 if (leftlist.Count >= 2) { closecontourlist = closecontourcheck(p, 2); } else if (rightlist.Count >= 2) { closecontourlist = closecontourcheck(p, 4); } else if (toplist.Count >= 2) { closecontourlist = closecontourcheck(p, 1); } else closecontourlist = closecontourcheck(p, 3); if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 2); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 4); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 1); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 3); } if (closecontourlist.Count >= 2) { compareelevation(p, closecontourlist); return; } else { unrecognize.Add(p); return; } #endregion } } //边缘情况 else { List toplist = calculatevalue(x, y, z, 1); List belowlist = calculatevalue(x, y, z, 3); //ArrayList closecontourlist = new ArrayList(); List closecontourlist = new List(); //找出等高线条数大于1的方向进行搜索 if (leftlist.Count >= 1) { closecontourlist = closecontourcheck(p, 2); } else if (rightlist.Count >= 1) { closecontourlist = closecontourcheck(p, 4); } else if (toplist.Count >= 1) { closecontourlist = closecontourcheck(p, 1); } else closecontourlist = closecontourcheck(p, 3); if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 2); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 4); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 1); } if (closecontourlist.Count < 2) { closecontourlist = closecontourcheck(p, 3); } if (closecontourlist.Count >= 2) { compareelevation(p, closecontourlist); return; } else { unrecognize.Add(p); return; } } } /// /// 从高程点向上搜索,找到上的等高线,并取得其高程值 /// /// 搜索方向,上、下、左、右分别为1、3、2、4 /// 以数组List(double)形式从小到大排序之后返回搜索到的各等高线高程 public List calculatevalue(double x, double y, double z, int direction) { Database database = HostApplicationServices.WorkingDatabase; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Point3dCollection ptcoll = new Point3dCollection(); List elevation = new List(); try { //ViewTableRecord currview = editor.GetCurrentView(); //currview.CenterPoint = new Point2d(x, y); //currview.ViewDirection = new Vector3d(0, 0, 1); //currview.Width = windowwidth; //currview.Height = windowheight; //editor.SetCurrentView(currview); double high = y; double width = x; bool flag = true; int times = 0; PromptSelectionResult pselectresult; Point3d p1, p2; while (flag) { times++; if (times > looptimes) { leng = temp; break; } leng = leng * times; if (direction == 1) { high += leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(x, high, 0); } else if (direction == 3) { high -= leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(x, high, 0); } else if (direction == 2) { width -= leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(width, y, 0); } else { width += leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(width, y, 0); } ptcoll.Add(p1); ptcoll.Add(p2); string filttext = sqx + "," + jqx; TypedValue[] filterlist = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName,filttext) }; //filterelist.SetValue(new TypedValue((int)DxfCode.LayerName, "8110,8120"),0); // 赋值过滤条件给 SelectionFilter 对象 SelectionFilter filter = new SelectionFilter(filterlist); dynamic acadApp = Application.AcadApplication; acadApp.ZoomExtents(); pselectresult = editor.SelectFence(ptcoll, filter); acadApp.ZoomPrevious(); if (pselectresult.Status == PromptStatus.OK) { SelectionSet selectionset = pselectresult.Value; ObjectId[] obj = new ObjectId[selectionset.Count]; obj = selectionset.GetObjectIds(); DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); for (int i = 0; i < obj.Length; i++) { Transaction traction = database.TransactionManager.StartTransaction(); BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ObjectId objid = obj[i]; Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead); if (entity is Polyline) { Polyline pline = (Polyline)entity; double ele = pline.Elevation; elevation.Add(ele); plltemp.Add(pline); } if (entity is Polyline2d) { Polyline2d pline2d = (Polyline2d)entity; double ele = pline2d.Elevation; elevation.Add(ele); pll2dtemp.Add(pline2d); } traction.Commit(); traction.Dispose(); } doclock.Dispose(); } ptcoll.Clear(); if (elevation.Count > 0) { leng = temp; flag = false; //Line line = new Line(p1, p2); //line.SetDatabaseDefaults(); //blocktablerecord.AppendEntity(line); //traction.AddNewlyCreatedDBObject(line, true); } } elevation.Sort(); return elevation; } catch (GrxCAD.Runtime.Exception ex) { string str = ex.ToString(); Application.ShowAlertDialog(str); return elevation; } //finally //{ //} } /// /// 上下方向搜索距离高程点距离最近的等高线的高程和距离 /// /// 搜索方向,1、2、3、4分别代表上、下、左、右 /// 以list返回闭合等高线结构体数组 public List closecontourcheck(Contourpoint p, int direction) { double x = p.x; double y = p.y; double z = p.z; Database database = HostApplicationServices.WorkingDatabase; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; List arrlist = new List(); double high = y; double width = x; bool flag = true; int times = 0; PromptSelectionResult pselectresult; Point3d p1, p2; while (flag) { //清空上一次选中的不足两个的对象 arrlist.Clear(); times++; if (times > looptimes) { leng = temp; break; } leng = leng * times; //向上搜索 if (direction == 1) { high += leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(x + 0.001, high, 0); } //向下搜索 else if (direction == 3) { high -= leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(x + 0.001, high, 0); } //向左搜索 else if (direction == 2) { width -= leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(width, y + 0.001, 0); } //向右搜索 else { width += leng; p1 = new Point3d(x, y, 0); p2 = new Point3d(width, y + 0.001, 0); } string filttext = sqx + "," + jqx; TypedValue[] filterlist = new TypedValue[1] { new TypedValue((int)DxfCode.LayerName,filttext) }; SelectionFilter filter = new SelectionFilter(filterlist); dynamic acadApp = Application.AcadApplication; acadApp.ZoomExtents(); pselectresult = editor.SelectCrossingWindow(p1, p2, filter); acadApp.ZoomPrevious(); if (pselectresult.Status == PromptStatus.OK) { SelectionSet selectionset = pselectresult.Value; ObjectId[] obj = new ObjectId[selectionset.Count]; obj = selectionset.GetObjectIds(); for (int i = 0; i < obj.Length; i++) { if (obj.Length < 2) break; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); using (Transaction traction = database.TransactionManager.StartTransaction()) { BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; //else //{ // Line line = new Line(p1, p2); // line.SetDatabaseDefaults(); // blocktablerecord.AppendEntity(line); // traction.AddNewlyCreatedDBObject(line, true); //} ObjectId objid = obj[i]; Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead); if (entity is Polyline) { Polyline pline = (Polyline)entity; Point3d pt = pline.GetClosestPointTo(new Point3d(x, y, z), new Vector3d(0, 0, 1), false); double distance = System.Math.Sqrt((pt.X - x) * (pt.X - x) + (pt.Y - y) * (pt.Y - y)); double elev = pline.Elevation; closecontour cc = new closecontour(); cc.elevation = elev; cc.interval = distance; arrlist.Add(cc); //Line line = new Line(new Point3d(x, y, z), new Point3d(p.X, p.Y, p.Z)); //line.SetDatabaseDefaults(); //blocktablerecord.AppendEntity(line); //traction.AddNewlyCreatedDBObject(line, true); } if (entity is Polyline2d) { Polyline2d pline2d = (Polyline2d)entity; Point3d pt = pline2d.GetClosestPointTo(new Point3d(x, y, z), new Vector3d(0, 0, 1), false); double distance = System.Math.Sqrt((pt.X - x) * (pt.X - x) + (pt.Y - y) * (pt.Y - y)); double elev = pline2d.Elevation; closecontour cc = new closecontour(); cc.elevation = elev; cc.interval = distance; arrlist.Add(cc); //Line line = new Line(new Point3d(x, y, z), new Point3d(p.X, p.Y, p.Z)); //line.SetDatabaseDefaults(); //blocktablerecord.AppendEntity(line); //traction.AddNewlyCreatedDBObject(line, true); } traction.Commit(); } doclock.Dispose(); } if (arrlist.Count >= 2) { flag = false; } } } return arrlist; } /// /// 在闭合等高线处,根据高程点周围等高线高程变化趋势。判断高程点的高程范围 /// /// 高程点周围等高线高程 public void compareelevation(Contourpoint p, List arrlist) { double x = p.x; double y = p.y; double z = p.z; //存储高程值计算等高距 List ele = new List(); if (arrlist.Count >= 2) { double minidistance = arrlist[0].interval; double contour = arrlist[0].elevation; ele.Add(contour); for (int i = 1; i < arrlist.Count; i++) { if (arrlist[i].interval < minidistance) { minidistance = arrlist[i].interval; contour = arrlist[i].elevation; } ele.Add(arrlist[i].elevation); } //从小到大排序 ele.Sort(); //等高距 double contourinterval = ele[1] - ele[0]; //中间高程最小 if (contour == ele[0]) { if (z > ele[0] || z < (ele[0] - contourinterval)) { errorpointarrlist.Add(p); return; } else return; } //中间高程最大 if (contour == ele[ele.Count - 1]) { if (z > (ele[ele.Count - 1] + contourinterval) || z < ele[ele.Count - 1]) { errorpointarrlist.Add(p); return; } else return; } } } } }