141 lines
5.9 KiB
C#
141 lines
5.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using LASFormat;
|
|
using LASRead;
|
|
using LASRead.LASFormat;
|
|
using Microsoft.CSharp.RuntimeBinder;
|
|
|
|
namespace LasInteractor
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("LAS Interactor. Provides methods to interact with .las files.");
|
|
Console.WriteLine("(c) 2020 Brychan Dempsey.\n.las Format (c) 2002-2019 American Society for Photogrammetry and Remote Sensing (ASPRS)\n");
|
|
Console.WriteLine("This software is intended for testing purposes only.");
|
|
Console.WriteLine("Currently, it is only compatible with processors that work in Little-Endian byte orders. Your system is {0} LE.\n", BitConverter.IsLittleEndian ? "" : "not");
|
|
Console.WriteLine("Enter a mode:");
|
|
Console.WriteLine("r - read a .las file");
|
|
Console.WriteLine("g - generate a .las file");
|
|
Console.WriteLine("c - collects the points into xyz format");
|
|
Console.WriteLine("z - compress via 7zip (experimental)");
|
|
ConsoleKeyInfo c = Console.ReadKey();
|
|
while(c.Key != ConsoleKey.Q)
|
|
{
|
|
if (c.Key == ConsoleKey.R)
|
|
{
|
|
Console.WriteLine("Read a file mode selected.\nPrint full data to console? (Y/n)");
|
|
c = Console.ReadKey();
|
|
while (c.Key != ConsoleKey.Y && c.Key != ConsoleKey.N)
|
|
{
|
|
Console.WriteLine("Please enter Y/n");
|
|
c = Console.ReadKey();
|
|
}
|
|
Console.WriteLine("Enter the full file path:");
|
|
string path = Console.ReadLine();
|
|
ReadFile(path, c.Key == ConsoleKey.Y);
|
|
}
|
|
|
|
c = Console.ReadKey();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private static void ReadFile(string source, bool printAll)
|
|
{
|
|
Console.WriteLine("Reading {0}", source);
|
|
FileStream fs = File.OpenRead(source);
|
|
Console.WriteLine("File is {0} bytes", fs.Length);
|
|
LASFile lasFile = new LASFile(fs);
|
|
/*FileStream os = File.OpenWrite("tdata.dat");
|
|
RawPoints rp = new RawPoints(lasFile, os);
|
|
rp.Run(); */
|
|
Console.WriteLine(new string('/', 20));
|
|
Console.Write(new string('/', 6));
|
|
Console.Write(" Header ");
|
|
Console.WriteLine(new string('/', 6));
|
|
Console.WriteLine(new string('/', 20));
|
|
Console.Write(lasFile.Header.ToString());
|
|
Console.WriteLine(new string('/', 20));
|
|
if (printAll)
|
|
{
|
|
Console.WriteLine("VLRs:");
|
|
Console.WriteLine("press enter to continue (q breaks the loop)");
|
|
Console.ReadLine();
|
|
foreach (Record record in lasFile.vlrCollection)
|
|
{
|
|
Console.WriteLine(record.ToString());
|
|
string s = Console.ReadLine();
|
|
if (s.Equals("q")) break;
|
|
}
|
|
Console.WriteLine("PDRs:");
|
|
Console.WriteLine("press enter to continue (q breaks the loop)");
|
|
Console.ReadLine();
|
|
byte lastClass = 0;
|
|
foreach (IPointDataRecord pdr in lasFile.points)
|
|
{
|
|
if (pdr.Classification == lastClass)
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine(pdr.ToString());
|
|
lastClass = pdr.Classification;
|
|
// Generics abuse
|
|
// Searches points for the method GetEnumerator() (of PDRCollection<T>), then searches the returned PDREnumerator<T> for EstimateRemainder()
|
|
dynamic underlyingeEnumerator = lasFile.points.GetType().GetMethod("GetEnumerator").Invoke(lasFile.points, null);
|
|
string estimation = ((int)underlyingeEnumerator.GetType().GetMethod("EstimateRemainder").Invoke(underlyingeEnumerator, null)).ToString();
|
|
|
|
Console.WriteLine(estimation); //.GetEnumerator().EstimateRemainder());
|
|
string s = Console.ReadLine();
|
|
if (s.Equals("q")) break;
|
|
}
|
|
|
|
|
|
}
|
|
Console.WriteLine("EVLRs:");
|
|
Console.WriteLine("press enter to continue (q breaks the loop)");
|
|
Console.ReadLine();
|
|
foreach (Record record in lasFile.evlrCollection)
|
|
{
|
|
Console.WriteLine(record.ToString());
|
|
string s = Console.ReadLine();
|
|
if (s.Equals("q")) break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Number of VLRs:");
|
|
Console.WriteLine(lasFile.Header.NumberVLRs);
|
|
Console.WriteLine("Number of PDRs:");
|
|
Console.WriteLine(Math.Max(lasFile.Header.LegacyNumberOfPointRecords, lasFile.Header.NumberPointRecords));
|
|
if (lasFile.Header.VersionMajor >= 1 && lasFile.Header.VersionMinor >= 4)
|
|
{
|
|
Console.WriteLine("Number of Extended VLRs:");
|
|
Console.WriteLine(lasFile.Header.NumberOfExtendedVLRs);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("File Version is < v1.4. No additional data");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void GenerateLAS()
|
|
{
|
|
Stream s = new MemoryStream(); // Use a memory stream to save the enumerables. Copy the stream if needed
|
|
// Create a 163.84 * 163.84 * 163.84 grid
|
|
LASFile lasFile = new LASFile(s);
|
|
}
|
|
}
|
|
}
|