Two ways to extract transformations in the coordinate format C #, Excel

Source: Internet
Author: User

First, Introduction

by friends, processing a point cloud data, Format: "X[m] y[m] z[m] r[db] g[db] b[db]", a total of 63w points, the format is : "roll name, X[m], y[m], z[m]". If you frequently have coordinate file conversions , use the code method, and use Excel if you use it occasionally . In Excel, the suffix is changed directly to. xlsx, and the next step is to insert, change, and so on for the whole column, and finally save it in txt format or DAT format.

Second, knowledge Preparation

1. file reading and writing

2. String processing

Three, the need to pay attention to the place

1, 60 tens of thousands of points, the amount of data is also OK, so the idea and data structure to pay extra attention, can save the province. I took a detour yesterday, take 190,000 points test time spent 0.75 seconds a little complacent, today to go back to see, write what things, the code re-modified a bit, test shows, 190,000 points 0.45 seconds or so, 630,000 points 1.15 seconds or so.

2, file read and write to pay attention to the file stream open and close.

Four, the code

usingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacePoint Cloud Turn pt{classProgram {Static voidMain (string[] args) {            //Measuring TimeStopwatch st =NewStopwatch (); St.            Start (); stringWjming ="coordinates"+"("+ DateTime.Now.ToString ("YYYYMMDDHHMMSS") +")"; stringPath =@"e:\c#\ Point Cloud to Pt2\ Point Cloud turn Pt2\bin\debug"; File.writealltext (Path+"\\"+ wjming +". txt",NULL); List< coordinates > result = Diaoqu (@"C:\Users\Ouy_\Desktop\all-Octree (0.1). txt"); using(StreamWriter SW =NewStreamWriter (wjming +". txt"))            {                foreach(varItem1inchresult) {SW. WriteLine (item1. Name+",,"+ item1. X +","+ item1. Y +","+item1.                H); }} St.            Stop (); Console.WriteLine ("ok! Time:"+St.        Elapsed); }        Staticlist< coordinates > Diaoqu (stringa) {FileStream fs=NewFileStream (A, FileMode.Open, FileAccess.Read, fileshare.readwrite); StreamReader M_streamreader=NewStreamReader (FS); M_streamReader.BaseStream.Seek (0, Seekorigin.begin); intindex =0; stringStrLine =M_streamreader.readline (); List< coordinates > result =Newlist< coordinates >(); //reads each row from the data stream until the last line of the file             while(StrLine! =NULL)            {                string[] s = strline.split (' ');//TXT file format delimiter                Try{Coordinate pt=NewCoordinates ((++index). ToString (), s[0], s[1], s[2]); Result.                    Add (PT); StrLine=M_streamreader.readline (); }                Catch(Exception ex) {Console.Write (ex).                ToString ()); }} fs.            Close ();            M_streamreader.close (); returnresult; }    }    classcoordinates { Public stringName {Get;Set; }  Public stringXGet;Set; }  Public stringYGet;Set; }  Public stringHGet;Set; }  PublicCoordinatesstringNamestringXstringYstringh) {Name=name; X=x; Y=y; H=h; }    }}

Two ways to extract transformations in the coordinate format C #, Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.