国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Autocad C#二次開發(fā)煤礦數(shù)據(jù)處理

這篇具有很好參考價值的文章主要介紹了Autocad C#二次開發(fā)煤礦數(shù)據(jù)處理。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System.Text.RegularExpressions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;



public class Point
{
    public Point() { }
    public Point(double xx, double yy, double zz)
    {
        X = xx;
        Y = yy;
        Z = zz;
    }
    bool euqal(Point other) {
        bool isEqual = false;
        if (Math.Sqrt(Math.Pow(other.X-X,2) + Math.Pow(other.Y-Y,2) + Math.Pow(other.Z-Z,2))<1.0)
        {
            isEqual = true;
        }

        return isEqual;
    }
    public double X { get; set; }
    public double Y { get; set; }
    public double Z { get; set; }
}


//去除粗差
public class RemoveOutlier
{
    //static void Main(string[] args)
    //{
    //    List<double> values = new List<double>
    //    {
    //        10.5, 12.3, 9.8, 53.5, 8.6, 11.2, 8.9, 12.1, 10.2, 11.6, 10.7, 9.5
    //    };

    //    List<double> cleanValues = RemoveOutliers(values);

    //    Console.WriteLine("Original values: " + string.Join(",", values));
    //    Console.WriteLine("Clean values: " + string.Join(",", cleanValues));

    //    Console.ReadLine();
    //}

    public static List<Point3d> RemoveOutliers(List<Point3d> datas,double score)
    {
        List<Point3d> cleanData = new List<Point3d>();
        List<double> data = new List<double>();
        foreach (Point3d ii in datas) {
            data.Add(ii.Z);
        }
        double mean = data.Average();
        double stdev = CalculateStandardDeviation(data, mean);

        for (int i=0;i<data.Count();++i)
        {
            double value = data[i];
            // Calculate the z-score
            double zScore = (value - mean) / stdev;

            // If the z-score is within -3 and 3 standard deviations, add it to the clean data
            if (Math.Abs(zScore) < score)
            {
                cleanData.Add(datas[i]);
            }
        }

        return cleanData;
    }

    static double CalculateStandardDeviation(List<double> data, double mean)
    {
        double sumOfSquaredDifferences = 0;

        foreach (double value in data)
        {
            sumOfSquaredDifferences += Math.Pow(value - mean, 2);
        }

        double variance = sumOfSquaredDifferences / (data.Count - 1);
        double stdev = Math.Sqrt(variance);

        return stdev;
    }
}




public class Interpolate
{
    //static void Main(string[] args)
    //{
    //    //已知點
    //    // Known points with x, y, and z values
    //    List<Point> points = new List<Point>
    //    {
    //        new Point { X = 0, Y = 0, Z = 0 },
    //        new Point { X = 1, Y = 1, Z = 1 },
    //        new Point { X = 2, Y = 2, Z = 4 },
    //        new Point { X = 3, Y = 3, Z = 9 }
    //    };

    //    //查找點
    //    double x = 1.5; // X coordinate of the point
    //    double y = 1.5; // Y coordinate of the point

    //    // Perform quadratic interpolation
    //    //二次插值函數(shù)
    //    double zQuadratic = QuadraticInterpolation(points, x, y);
    //    Console.WriteLine("Z value of point ({0}, {1}) using quadratic interpolation: {2}", x, y, zQuadratic);

    //    //三次插值函數(shù)
    //    // Perform cubic interpolation
    //    double zCubic = CubicInterpolation(points, x, y);
    //    Console.WriteLine("Z value of point ({0}, {1}) using cubic interpolation: {2}", x, y, zCubic);

    //    Console.ReadLine();
    //}

    public Interpolate() { }

    public static double QuadraticInterpolation(List<Point> points, double x, double y)
    {
        double z = 0;

        // Find the three nearest points
        Point[] closestPoints = GetClosestPoints(points, x, y, 3);
        if (points[0].Equals(points[1]) || points[0].Equals(points[2]) || points[1].Equals(points[2]))
        {
            z = (points[0].Z + points[1].Z + points[2].Z) / 3;
            return z;
        }
        // Calculate coefficients for the quadratic polynomial
        double[,] a = new double[3, 3];
        double[] b = new double[3];
        for (int i = 0; i < 3; i++)
        {
            a[i, 0] = 1;
            a[i, 1] = closestPoints[i].X;
            a[i, 2] = closestPoints[i].Y;
            b[i] = closestPoints[i].Z;
        }
        double[,] aInverse = InverseMatrix(a);
        double[] c = MultiplyMatrixVector(aInverse, b);

        // Calculate the z value of the point using the quadratic polynomial
        z = c[0] + c[1] * x + c[2] * y;

        return z;
    }

    public static double CubicInterpolation(List<Point> points, double x, double y)
        {
            double z = 0;

            // Find the four nearest points
            Point[] closestPoints = GetClosestPoints(points, x, y, 4);

            // Calculate coefficients for the cubic polynomial
            double[,] a = new double[4, 4];
            double[] b = new double[4];
            for (int i = 0; i < 4; i++)
            {
                a[i, 0] = 1;
                a[i, 1] = closestPoints[i].X;
                a[i, 2] = closestPoints[i].Y;
                a[i, 3] = closestPoints[i].X * closestPoints[i].Y;
                b[i] = closestPoints[i].Z;
            }
            double[,] aInverse = InverseMatrix(a);
            double[] c = MultiplyMatrixVector(aInverse, b);

            // Calculate the z value of the point using the cubic polynomial
            z = c[0] + c[1] * x + c[2] * y + c[3] * x * y;

            return z;
        }

    static Point[] GetClosestPoints(List<Point> points, double x, double y, int numberOfPoints)
    {
        // Sort the points by distance
        //Point[] sortedPoints = points.OrderBy(p => Math.Sqrt(Math.Pow(p.X - x, 2) + Math.Pow(p.Y - y, 2))).ToArray();

        SortedDictionary<double, Point> dict = new SortedDictionary<double, Point>();
        for (int i = 0; i < points.Count(); ++i)
        {
            Point p = points[i];
            double dist = Math.Sqrt(Math.Pow(p.X - x, 2) + Math.Pow(p.Y - y, 2));
            dict.Add(dist, p);
        }
        Point[] pts = new Point[numberOfPoints];
        int index = 0;
        foreach (KeyValuePair<double, Point> kvp in dict)
        {
            //Console.WriteLine("Key: {0}, Value: {1}", kvp.Key, kvp.Value);
            pts[index] = kvp.Value;
            index++;
            if (index >= numberOfPoints) break;
        }
        return pts;
    }

    static double[,] InverseMatrix(double[,] a)
        {
            int n = Convert.ToInt32(Math.Sqrt(a.Length));
            double[,] inv = new double[n, n];
            double det = Determinant(a);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double[,] minor = Minor(a, i, j);
                    inv[j, i] = Math.Pow(-1, i + j) * Determinant(minor) / det;
                }
            }

            return inv;
        }

    static double Determinant(double[,] a)
        {
            int n = Convert.ToInt32(Math.Sqrt(a.Length));
            double det = 0;

            if (n == 1)
            {
                det = a[0, 0];
            }
            else if (n == 2)
            {
                det = a[0, 0] * a[1, 1] - a[0, 1] * a[1, 0];
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    double[,] minor = Minor(a, 0, i);
                    det += Math.Pow(-1, i) * a[0, i] * Determinant(minor);
                }
            }

            return det;
        }

    static double[,] Minor(double[,] a, int i, int j)
        {
            int n = Convert.ToInt32(Math.Sqrt(a.Length));
            double[,] minor = new double[n - 1, n - 1];

            for (int k = 0; k < n; k++)
            {
                for (int l = 0; l < n; l++)
                {
                    if (k != i && l != j)
                    {
                        int p = k < i ? k : k - 1;
                        int q = l < j ? l : l - 1;
                        minor[p, q] = a[k, l];
                    }
                }
            }

            return minor;
        }

    static double[] MultiplyMatrixVector(double[,] a, double[] b)
        {
            int m = a.GetLength(0);
            int n = a.GetLength(1);

            double[] c = new double[m];

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    c[i] += a[i, j] * b[j];
                }
            }

            return c;
        }
}


class KdTreeNode
{
    public Point3d Point { get; set; }
    public KdTreeNode Left { get; set; }
    public KdTreeNode Right { get; set; }

    public KdTreeNode(Point3d point)
    {
        Point = point;
        Left = null;
        Right = null;
    }
}

// kd樹類
class KdTree
{
    private KdTreeNode root;
    private List<Point3d> m_points;
    public KdTree(List<Point3d> points)
    {
        root = BuildKdTree(points, 0);
        m_points = points;
    }

    // 構(gòu)建kd樹
    private KdTreeNode BuildKdTree(List<Point3d> points, int depth)
    {
        if (points.Count == 0)
        {
            return null;
        }

        int axis = depth % 2;
        points.Sort((a, b) => axis == 0 ? a.X.CompareTo(b.X) : a.Y.CompareTo(b.Y));

        int medianIndex = points.Count / 2;
        Point3d medianPoint = points[medianIndex];

        KdTreeNode node = new KdTreeNode(medianPoint);
        node.Left = BuildKdTree(points.GetRange(0, medianIndex), depth + 1);
        node.Right = BuildKdTree(points.GetRange(medianIndex + 1, points.Count - medianIndex - 1), depth + 1);

        return node;
    }

    // 最近鄰搜索
    public Point3d FindNearestNeighbor(Point3d target)
    {
        Point3d pt = new Point3d(0.0, 0.0, 0.0);
        if (0 == m_points.Count()) return pt;
        pt = m_points[0];
        if (1 == m_points.Count()) return pt;
        for (int i = 1; i < m_points.Count(); ++i)
        {
            Point3d ptF = m_points[i];
            double dist = Distance(target, ptF);
            double distOld = Distance(target, pt);
            if (dist < distOld) pt = ptF;
        }
        return pt;
        //KdTreeNode nearestNode = FindNearestNeighbor(root, target, 0);
        //return nearestNode.Point;
    }
    private KdTreeNode FindNearestNeighbor(KdTreeNode node, Point3d target, int depth)
    {
        if (node == null)
            return null;

        int k = 3;
        int axis = depth % k;

        KdTreeNode nearestNode;
        KdTreeNode branchNode;

        if (target[axis] < node.Point[axis])
        {
            nearestNode = FindNearestNeighbor(node.Left, target, depth + 1);
            branchNode = node.Right;
        }
        else
        {
            nearestNode = FindNearestNeighbor(node.Right, target, depth + 1);
            branchNode = node.Left;
        }

        if (nearestNode == null || Distance(target, nearestNode.Point) > Distance(target, node.Point))
            nearestNode = node;

        if (Distance(target, nearestNode.Point) > Math.Abs(target[axis] - node.Point[axis]))
        {
            KdTreeNode otherBranchNode = (branchNode == node.Left) ? node.Right : node.Left;
            KdTreeNode potentialNode = FindNearestNeighbor(otherBranchNode, target, depth + 1);
            if (potentialNode != null && Distance(target, nearestNode.Point) > Distance(target, potentialNode.Point))
                nearestNode = potentialNode;
        }

        return nearestNode;
    }
    // 計算兩個點之間的歐幾里得距離
    public double Distance(Point3d p1, Point3d p2)
    {
        double dx = p1.X - p2.X;
        double dy = p1.Y - p2.Y;
        return Math.Sqrt(dx * dx + dy * dy);
    }
}

public class ReadFile
{
    public static List<Point3d> readFilePts(string path)
    {
        List<Point3d> points = new List<Point3d>();
        string filePath = path;

        try
        {
            using (StreamReader reader = new StreamReader(filePath))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                    string[] parts = line.Split(',');
                    double x = 0.0, y = 0.0, z = 0.0;
                    if (double.TryParse(parts[0], out x))
                    {
                        Console.WriteLine("轉(zhuǎn)換成功,值為:" + x);
                    }
                    else
                    {
                        Console.WriteLine("轉(zhuǎn)換失敗");
                    }
                    if (double.TryParse(parts[1], out y))
                    {
                        Console.WriteLine("轉(zhuǎn)換成功,值為:" + y);
                    }
                    else
                    {
                        Console.WriteLine("轉(zhuǎn)換失敗");
                    }
                    if (double.TryParse(parts[2], out z))
                    {
                        Console.WriteLine("轉(zhuǎn)換成功,值為:" + z);
                    }
                    else
                    {
                        Console.WriteLine("轉(zhuǎn)換失敗");
                    }
                    points.Add(new Point3d(x,y,z));
                }
            }
        }
        catch (FileNotFoundException)
        {
            Console.WriteLine("File not found: {0}", filePath);
        }
        catch (IOException e)
        {
            Console.WriteLine("Error reading file: {0}", e.Message);
        }
        return points;
    }
}

//修改線段的高程
public class ChangeElevate
{
    [CommandMethod("ChangeElevation")]
    public void ChangeElevation()
    {
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Editor ed = doc.Editor;
        Database db = doc.Database;
        // 獲取當前文檔編輯器
        // 定義文件選擇器
        PromptOpenFileOptions fileOpts = new PromptOpenFileOptions("選擇文件");
        fileOpts.Filter = "所有文件 (*.*)|*.*";

        // 提示用戶選擇文件
        PromptFileNameResult fileRes = ed.GetFileNameForOpen(fileOpts);
        if (fileRes.Status == PromptStatus.OK)
        {
            // 用戶選擇了文件
            string filePath = fileRes.StringResult;
            ed.WriteMessage("\n已選擇文件:" + filePath);
            List<Point3d> points = ReadFile.readFilePts(filePath);

            List<Point> pointts = new List<Point>();
            foreach (var pt in points) {
                Point pp=new Point(pt.X,pt.Y,pt.Z);
                pointts.Add(pp);
            }

           // GPSHeightFit heightfit=new GPSHeightFit(points);
            //f.GPSHeightFitting gpsFit(points);

             詢問新的高程值
            //PromptDoubleResult pdr = ed.GetDouble("\nEnter new elevation: ");
            //if (pdr.Status != PromptStatus.OK) return;
            //double newElevation = pdr.Value;

            // 選擇要更改的線段
            PromptSelectionResult psr = ed.GetSelection();
            if (psr.Status != PromptStatus.OK) return;
            SelectionSet ss = psr.Value;
            string path = "C:/Users/Administrator/Desktop/CadTmp/";
            string rmControlPath = string.Format("{0}/heightControl.csv", path);
            // 開始事務處理
            List<Point3d> startpts = new List<Point3d>();
            List<Point3d> newstartpts = new List<Point3d>();
            List<Point3d> endpts = new List<Point3d>();
            List<Point3d> newendpts = new List<Point3d>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (SelectedObject so in ss)
                {
                    Entity ent = (Entity)tr.GetObject(so.ObjectId, OpenMode.ForWrite);

                    if (ent is Line)
                    {
                        Line line = (Line)ent;
                        startpts.Add(line.StartPoint);
                        endpts.Add(line.EndPoint);
                        // 修改線段的起始和結(jié)束點高程
                        double newStartZ = Interpolate.QuadraticInterpolation(pointts,line.StartPoint.X, line.StartPoint.Y);
                        line.StartPoint = new Point3d(line.StartPoint.X, line.StartPoint.Y, newStartZ);
                        double neweNDZ = Interpolate.QuadraticInterpolation(pointts,line.EndPoint.X, line.EndPoint.Y);
                        line.EndPoint = new Point3d(line.EndPoint.X, line.EndPoint.Y, neweNDZ);
                        newstartpts.Add(line.StartPoint);
                        newendpts.Add(line.EndPoint);
                         修改線段的起始和結(jié)束點高程
                        //double newStartZ3 = Interpolate.CubicInterpolation(pointts, line.StartPoint.X, line.StartPoint.Y);
                        //line.StartPoint = new Point3d(line.StartPoint.X, line.StartPoint.Y, newStartZ3);
                        //double neweNDZ3 = Interpolate.CubicInterpolation(pointts, line.EndPoint.X, line.EndPoint.Y);
                        //line.EndPoint = new Point3d(line.EndPoint.X, line.EndPoint.Y, neweNDZ3);
                        //int CCC = 0;
                    }
                    else if (ent is Polyline || ent is Polyline2d || ent is Polyline3d)
                    {
                        // 將實體轉(zhuǎn)換為多段線
                        Polyline pline = (Polyline)ent;

                        // 遍歷多段線的所有頂點
                        for (int i = 0; i < pline.NumberOfVertices; i++)
                        {
                            Point3d vertex = pline.GetPoint3dAt(i);
                            //double newStartZ = Interpolation.Interpolate(points, vertex.X, vertex.Y);
                            //pline.SetPointAt(i, new Point2d(vertex.X, vertex.Y));
                            //pline.SetBulgeAt(i,newStartZ);
                        }

                        // 更新多段線
                        //pline.Update();
                    }
                }

                // 提交更改
                tr.Commit();


                // 寫新控制點文件
                // 寫入CSV文件
                using (StreamWriter writer = new StreamWriter(rmControlPath))
                {
                    for (int i=0;i<startpts.Count();++i)
                    {
                        Point3d startPt = startpts[i];
                        Point3d newStartpt = newstartpts[i];
                        Point3d endpt = endpts[i];
                        Point3d newEndPt = newendpts[i];
                        string row = string.Format("{0:F6},{1:F6},{2:F6},{3:F6},{4:F6},{5:F6},{6:F6},{7:F6},{8:F6},{9:F6},{10:F6},{11:F6}", startPt.X, startPt.Y, startPt.Z
                            , newStartpt.X, newStartpt.Y, newStartpt.Z, endpt.X, endpt.Y, endpt.Z, newEndPt.X, newEndPt.Y, newEndPt.Z);
                        writer.WriteLine(row);
                    }
                }
            }

            ed.WriteMessage("\nLine elevation changed.");

        }
        else
        {
            // 用戶取消了選擇
            ed.WriteMessage("\n未選擇文件");
        }
    }
}

public class GetControl
{
    [CommandMethod("GetControlPts")]
    public void GetControlPts()
    {
        //獲取當前文檔對象
        Document doc = Application.DocumentManager.MdiActiveDocument;
        //鎖文檔
        //doc.LockDocument();
        //獲取當前數(shù)據(jù)庫
        Database db = doc.Database;
        //獲取編輯文檔
        Editor ed = doc.Editor;
        // 選擇要讀取的控制點信息
        //;
        ed.WriteMessage("請選擇需要提取的對象,其中圓和多段線類型實體會被認為是高程點 文本類型會被認為是高程注記");
        PromptSelectionResult psr = ed.GetSelection();
        if (psr.Status != PromptStatus.OK) return;
            SelectionSet ss = psr.Value;

        //獲取搜索的閾值 超出閾值的不要
        // 選擇要讀取的控制點信息
        //;
        ed.WriteMessage("請選擇高程注記搜索的閾值,找不到高程注記的控制點會被丟棄");
        PromptDoubleResult psrDouble = ed.GetDouble("請選擇高程注記搜索的閾值,找不到高程注記的控制點會被丟棄(50)");
        double distLimit = 0.0;
        if (psrDouble.Status != PromptStatus.OK) return;
        distLimit = psrDouble.Value;

        //獲取搜索的閾值 超出閾值的不要
        // 選擇要讀取的控制點信息
        //;
        ed.WriteMessage("正態(tài)分布剔除錯誤值");
        PromptDoubleResult psrDoubleRm = ed.GetDouble("輸入正態(tài)分布剔除錯誤值區(qū)間(一個標準差約68.2% 兩個約95.4% 三個能達到99.7%):(3) ");
        double psRm = 0.0;              //西格瑪 區(qū)間
        if (psrDoubleRm.Status != PromptStatus.OK) return;
        psRm = psrDoubleRm.Value;

        //PromptSaveFileOptions pr = new PromptSaveFileOptions("選擇保存路徑:");
        //PromptFileNameResult saveRes= ed.GetFileNameForSave(pr);
        //if (saveRes.Status != PromptStatus.OK)
        //{
        //    ed.WriteMessage("not select save!");
        //    return;
        //}
        //string path = saveRes.ToString();
        // 開始事務處理
        string path = "C:/Users/Administrator/Desktop/CadTmp/";
        


        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            List<Point3d> controlPts = new List<Point3d>();
            List<Point3d> markPts = new List<Point3d>();
            List<Point3d> newControlPts = new List<Point3d>();
            List<double> dists = new List<double>();
            List<double> textZs = new List<double>();
            //獲取所有的控制點
            foreach (SelectedObject so in ss)
            {
                //獲取當前對象用于讀取信息
                Entity ent = (Entity)tr.GetObject(so.ObjectId, OpenMode.ForRead);

                if (ent is Circle)
                {
                    Circle line = (Circle)ent;
                    // 修改線段的起始和結(jié)束點高程
                    Point3d circleCenter = line.Center;
                    controlPts.Add(circleCenter);
                }
                else if (ent is Polyline || ent is Polyline2d || ent is Polyline3d)
                {
                    // 將實體轉(zhuǎn)換為多段線
                    Polyline pline = (Polyline)ent;
                    int ccount = pline.NumberOfVertices;
                    // 遍歷多段線的所有頂點
                    double x = 0.0, y = 0.0, z = 0.0;
                    for (int i = 0; i < pline.NumberOfVertices; i++)
                    {
                        Point3d vertex = pline.GetPoint3dAt(i);
                        x += vertex.X;
                        y += vertex.Y;
                        z += vertex.Z;
                    }
                    Point3d circleCenter = new Point3d(x / ccount, y / ccount, z / ccount);
                    controlPts.Add(circleCenter);
                    // 更新多段線
                    //pline.Update();
                }
                else {

                }
            }

            //獲取所有的注記
            //獲取所有的控制點
            foreach (SelectedObject so in ss)
            {
                //獲取當前對象用于讀取信息
                Entity ent = (Entity)tr.GetObject(so.ObjectId, OpenMode.ForRead);
                if (ent is DBText)
                {
                    //如果是單行文本
                    DBText line = (DBText)ent;
                    if (line!=null) {
                        Point3d circleCenter = line.Position;
                        string value= line.TextString;
                        // 定義一個小數(shù)匹配的正則表達式
                        string pattern = @"^-?\d+(?:\.\d+)?$";

                        // 創(chuàng)建一個正則表達式實例,并進行匹配
                        Regex regex = new Regex(pattern);
                        if (regex.IsMatch(value))
                        {
                            // 匹配成功,字符串是一個小數(shù)
                            double number = double.Parse(value);
                            textZs.Add(number);
                            if (number < 500 || number > 1500)
                            {
                                int ccc = 0;
                            }
                            Point3d newCenter = new Point3d(circleCenter.X,circleCenter.Y,number);
                            markPts.Add(newCenter);
                            Console.WriteLine(number);
                        }
                        else
                        {
                            // 匹配失敗,字符串不是一個小數(shù)
                            Console.WriteLine("不是一個小數(shù)");
                        }

                        //markPts.Add(circleCenter);
                    }
                    // 修改線段的起始和結(jié)束點高程
                    //Point3d circleCenter = line.Center;
                    //controlPts.Add(circleCenter);
                }
                else if (ent is MText)
                {
                    //如果是多行文本
                    MText line = (MText)ent;
                    if (line != null)
                    {
                        Point3d circleCenter = line.Location;
                        markPts.Add(circleCenter);
                    }
                }
                else
                {

                }
            }


            //每個控制點匹配高程
            KdTree kdTree = new KdTree(markPts);
            int count = controlPts.Count();

            for (int i = 0; i < count; ++i)
            {
                Point3d target = controlPts[i];
                Point3d nearestNeighbor = kdTree.FindNearestNeighbor(target);
                double dist = kdTree.Distance(target, nearestNeighbor);
                dists.Add(dist);
                if (dist > distLimit) continue;
                Point3d newPt=new Point3d(target.X, target.Y, nearestNeighbor.Z);
                newControlPts.Add(newPt);
            }


            //處理控制點 剔除粗差
            List<Point3d> rmpts = RemoveOutlier.RemoveOutliers(newControlPts, psRm);

            List<Point3d> rmdupPts = new List<Point3d>();
            if (rmpts.Count() > 0)
            {
                rmdupPts.Add(rmpts[0]);
            }
            for (int i = 0; i < rmpts.Count(); ++i)
            {
                bool isFind = false;
                for (int j = 0; j < rmdupPts.Count(); ++j)
                {
                    double dist = kdTree.Distance(rmpts[i], rmdupPts[j]);
                    if (dist < 10) isFind = true;
                }
                if (!isFind)
                {
                    rmdupPts.Add(rmpts[i]);
                }
            }



            // 寫控制點文件
            string controlPath = string.Format("{0}/control.csv", path);                        //獲取的所有控制點
            string newcontrolPath = string.Format("{0}/newControl.csv", path);                  //獲取高程后的控制點
            string markPath = string.Format("{0}/mark.csv", path);                              //獲取的高程標注
            string distPath = string.Format("{0}/markdist.csv", path);                          //控制點和高程標準匹配距離
            string zsPath = string.Format("{0}/textzs.csv", path);                              //提取的高程注記Z值
            string rmControlPath = string.Format("{0}/rmControl.csv", path);                    //正態(tài)分布去除兩端的高程點
            string rmdupControlPath = string.Format("{0}/rmDupControl.csv", path);                 //去除重復值的高程點
            // 寫入CSV文件
            using (StreamWriter writer = new StreamWriter(controlPath))
            {
                foreach (Point3d rowData in controlPts)
                {
                    string row = string.Format("{0:F6},{1:F6},{2:F6}", rowData.X, rowData.Y, rowData.Z);
                    writer.WriteLine(row);
                }
            }

            Console.WriteLine("control CSV file has been written.");

            // 寫標記點文件
            using (StreamWriter writer = new StreamWriter(markPath))
            {
                foreach (Point3d rowData in markPts)
                {
                    string row = string.Format("{0:F6},{1:F6},{2:F6}", rowData.X, rowData.Y, rowData.Z);
                    writer.WriteLine(row);
                }
            }

            Console.WriteLine("control CSV file has been written.");

            // 寫新控制點文件
            // 寫入CSV文件
            using (StreamWriter writer = new StreamWriter(newcontrolPath))
            {
                foreach (Point3d rowData in newControlPts)
                {
                    string row = string.Format("{0:F6},{1:F6},{2:F6}", rowData.X, rowData.Y, rowData.Z);
                    writer.WriteLine(row);
                }
            }

            Console.WriteLine("control CSV file has been written.");

            // 寫新控制點文件
            // 寫入CSV文件
            using (StreamWriter writer = new StreamWriter(distPath))
            {
                foreach (double rowData in dists)
                {
                    string row = string.Format("{0:F6}", rowData);
                    writer.WriteLine(row);
                }
            }

            Console.WriteLine("control CSV file has been written.");

            // 寫新控制點文件
            // 寫入CSV文件
            using (StreamWriter writer = new StreamWriter(rmControlPath))
            {
                foreach (Point3d rowData in rmpts)
                {
                    string row = string.Format("{0:F6},{1:F6},{2:F6}", rowData.X, rowData.Y, rowData.Z);
                    writer.WriteLine(row);
                }
            }

            // 寫新控制點文件
            // 寫入CSV文件
            using (StreamWriter writer = new StreamWriter(rmdupControlPath))
            {
                foreach (Point3d rowData in rmdupPts)
                {
                    string row = string.Format("{0:F6},{1:F6},{2:F6}", rowData.X, rowData.Y, rowData.Z);
                    writer.WriteLine(row);
                }
            }

            Console.WriteLine("control CSV file has been written.");
        }

        ed.WriteMessage("\nLine elevation changed.");
        //解鎖文檔
       // doc.Dispose();
    }
}

文章來源地址http://www.zghlxwxcb.cn/news/detail-494722.html

到了這里,關于Autocad C#二次開發(fā)煤礦數(shù)據(jù)處理的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 使用Python編程語言處理數(shù)據(jù) (Processing data using Python programm

    作者:禪與計算機程序設計藝術 Python作為一種高級、開源、跨平臺的編程語言,已經(jīng)成為當今最流行的數(shù)據(jù)分析和機器學習工具。本文介紹了使用Python編程語言處理數(shù)據(jù)的一些基礎知識,如列表、字典、集合、迭代器等,并對pandas、numpy、matplotlib、seaborn等數(shù)據(jù)分析庫進行了

    2024年02月07日
    瀏覽(27)
  • c#處理3種json數(shù)據(jù)的實例介紹

    c#處理3種json數(shù)據(jù)的實例介紹

    這篇文章主要介紹了c#處理包含數(shù)組、對象的復雜json數(shù)據(jù)的方法,,需要的朋友可以參考下 網(wǎng)絡中數(shù)據(jù)傳輸經(jīng)常是xml或者json,現(xiàn)在做的一個項目之前調(diào)其他系統(tǒng)接口都是返回的xml格式,剛剛遇到一個返回json格式數(shù)據(jù)的接口,通過例子由易到難總結(jié)一下處理過程,希望能幫到和

    2024年02月14日
    瀏覽(26)
  • c# List集合舉例十二種數(shù)據(jù)處理用法

    Person 類: 請注意,這只是一個簡單的示例類,實際場景中可能需要更復雜的屬性和方法。 過濾List集合的對象,只保留sex為0的對象,并返回一個新的集合。 找出符合條件的第一個對象,沒有返回null。 根據(jù)性別對集合進行分組,返回Map集合,每種性別個對應一個集合。 從集

    2024年02月11日
    瀏覽(20)
  • 【C#】【System.Linq】一些便捷的數(shù)據(jù)處理方法(Range、Select)

    因為用習慣了Python中一些便捷的方法,隨即查詢C#中有沒有類似的。 ?一、Range()方法 在Python中,range(Start,End,Step)可以直接生成一個可迭代對象,便用于需要循環(huán)多次處理某些代碼塊: (注:Range方法中的End是開區(qū)間,range(1,10)實際的取值是(1 ~ 9)) ? 在C#中也

    2024年02月08日
    瀏覽(19)
  • 基于C#編程建立泛型Matrix數(shù)據(jù)類型及對應處理方法

    基于C#編程建立泛型Matrix數(shù)據(jù)類型及對應處理方法

    ????????上一篇文檔中描述了如何寫一個VectorT類,本次在上一篇文檔基礎上,撰寫本文,介紹如何書寫一個泛型Matrix,可以應用于int、double、float等C#數(shù)值型的matrix。 ????????本文所描述的MatrixT是一個泛型,具有不同數(shù)值類型Matrix矩陣構(gòu)造、新增、刪除、查詢、更改、

    2024年02月02日
    瀏覽(32)
  • 基于C#和MATLAB對手機錄音音頻數(shù)據(jù)分析處理系統(tǒng) 畢業(yè)論文+項目源碼

    基于C#和MATLAB對手機錄音音頻數(shù)據(jù)分析處理系統(tǒng) 畢業(yè)論文+項目源碼

    摘要 當今科學技術發(fā)展迅猛,知識爆炸信息量的急劇增加不僅僅豐富了我們的現(xiàn)實生活,也對我們的信息處理技術提出了新的要求。音頻信號在這信息洪流中占據(jù)著不可或缺的重要地位,諸如語音聊天,音頻取證等在我們的生活中發(fā)揮著愈來愈重要的作用,故而對于音頻的特

    2024年01月19日
    瀏覽(26)
  • 低代碼開發(fā):數(shù)據(jù)處理與可視化

    低代碼開發(fā)是一種快速、高效的應用開發(fā)方法,它通過簡化和自動化開發(fā)過程,使非專業(yè)開發(fā)人員也能快速構(gòu)建數(shù)據(jù)處理和可視化應用。本文將介紹低代碼開發(fā)的定義、優(yōu)勢,并以數(shù)據(jù)處理與可視化為例,探討低代碼開發(fā)在這一領域的應用和價值。 隨著大數(shù)據(jù)時代的到來,數(shù)

    2024年01月21日
    瀏覽(30)
  • JAVA開發(fā)(手工處理數(shù)據(jù)庫表數(shù)據(jù)的一些示例算法)

    JAVA開發(fā)(手工處理數(shù)據(jù)庫表數(shù)據(jù)的一些示例算法)

    背景: 在項目開發(fā)中,有時候需要手動處理一下數(shù)據(jù)庫表的數(shù)據(jù)。涉及到數(shù)據(jù)得到備份、恢復,清洗,計算,合并等操作。 舉例記錄一下最近對數(shù)據(jù)的一些處理過程。 1、對數(shù)據(jù)表進行數(shù)據(jù)量統(tǒng)計 2、記住數(shù)據(jù)庫表的數(shù)據(jù),然后進行備份 3、我們再對數(shù)據(jù)進行處理之前一定記

    2024年02月07日
    瀏覽(30)
  • kettle開發(fā)-Day38-超好用自定義數(shù)據(jù)處理組件

    kettle開發(fā)-Day38-超好用自定義數(shù)據(jù)處理組件

    目錄 前言: 一、半斤八兩,都不太行 ? ? ? ? 1、表輸入,速度快,但不穩(wěn)妥 ????????2、穩(wěn)的一批,但是慢的像蝸牛? 二、各訴衷腸,合作共贏 ?????????1、表輸入,高效數(shù)據(jù)插入 ? ????????2、插入更新,一個都不能少 三、表輸入的高效+插入更新的完整性 ? ?

    2024年02月09日
    瀏覽(17)
  • UG NX二次開發(fā)(C#)-PMI-獲取PMI的尺寸數(shù)據(jù)(二)

    在前面寫的一個博客中UG NX二次開發(fā)(C#)-PMI-獲取PMI尺寸數(shù)據(jù)中介紹了再NX2007中獲取尺寸數(shù)據(jù)的例子,本文以NX12為例,講述一下獲取PMI尺寸數(shù)據(jù)的過程。 打開UG NX12.0,創(chuàng)建如下圖的三維模型。注:PMI類型不全

    2024年04月17日
    瀏覽(53)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包