找传奇、传世资源到传世资源站!

TCP文件合并

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

无人机影像处理TCP合并TCP文件合并 C#语言基础-第1张 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace Tpc文件合并{ public static class MergeTools { public static List<TpcDataStruct> ReadTpcFiles(string tpcPath) { List<TpcDataStruct> tpcData = new List<TpcDataStruct>(); StreamReader sr = new StreamReader(tpcPath); List<ImgPoints> ips = new List<ImgPoints>(); TpcDataStruct tpc = new TpcDataStruct(); while (!sr.EndOfStream) { string[] data = sr.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); switch (data.Length) { case 1: tpc.PointsNum = int.Parse(data[0]); //tpcData.Add(tpc); if (data[0] == "0") { continue; } break; case 2: if (tpc.AirLineIndex != 0) { tpc.ImagesPoints = ips; tpcData.Add(tpc); } tpc = new TpcDataStruct(); ips = new List<ImgPoints>(); tpc.AirLineIndex = int.Parse(data[0]); tpc.ImageIndex = int.Parse(data[1]); break; case 6: ImgPoints ip = new ImgPoints(int.Parse(data[0]), double.Parse(data[1]), double.Parse(data[2]), double.Parse(data[3]), double.Parse(data[4])); ips.Add(ip); break; default: break; } } tpc.ImagesPoints = ips; tpcData.Add(tpc); sr.Close(); return tpcData; } public static List<TpcDataStruct> MergeTpc(List<TpcDataStruct> tpc1, List<TpcDataStruct> tpc2) { List<TpcDataStruct> mergeTpc = new List<TpcDataStruct>(); tpc1.ForEach(tpc => { TpcDataStruct singleTpc = new TpcDataStruct(); singleTpc.AirLineIndex = tpc.AirLineIndex; singleTpc.ImageIndex = tpc.ImageIndex; singleTpc.ImagesPoints.AddRange(tpc.ImagesPoints); foreach (var t in tpc2) { if (tpc.AirLineIndex == t.AirLineIndex && tpc.ImageIndex == t.ImageIndex) { singleTpc.ImagesPoints.AddRange(t.ImagesPoints); singleTpc.PointsNum = singleTpc.ImagesPoints.Count; } } mergeTpc.Add(singleTpc); }); //tpc2.ForEach(tpc => // { // bool isExist = false; // foreach (var t in tpc1) // { // if (tpc.AirLineIndex == t.AirLineIndex && tpc.ImageIndex == t.ImageIndex) // isExist = true; // } // if (!isExist) // { // mergeTpc.Add(tpc); // } // }); return mergeTpc; } public static void WriteTpc(List<TpcDataStruct> tpcs,string tpcPath) { StreamWriter sw = new StreamWriter(tpcPath, false, Encoding.Default); tpcs.ForEach(tpc => { sw.WriteLine(" " tpc.AirLineIndex.ToString() " \t\t\t" tpc.ImageIndex.ToString()); sw.WriteLine(" " tpc.PointsNum.ToString()); tpc.ImagesPoints.ForEach(p=> { sw.WriteLine(" " p.PointsID.ToString().ToFormat() " \t\t" p.ParaA.ToString("f5").ToFormat() " \t\t" p.ParaB.ToString("f5").ToFormat()" \t\t" p.ParaC.ToString("f4").ToFormat() " \t\t" p.ParaD.ToString("f4").ToFormat() " \t\t" p.Flag.ToString()); }); }); sw.Close(); } public static string ToFormat(this string str) { string s = string.Format("{0,11}", str); return s; } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复