//----------------------------------------------------------------------------- /// <summary> /// Open function to produce a list of grid files. /// </summary> /// <param name="prmInput">Input las file</param> /// <param name="prmGridTypes">List of grid types</param> /// <param name="prmGridSizes">List of grid sizes</param> public void Grid(String prmInput, IEnumerable <TeGriddingType> prmGridTypes, IEnumerable <Int32> prmGridSizes) { List <TcGridObject> gridObjects = new List <TcGridObject>(prmGridTypes.Count() + prmGridSizes.Count()); String xmlFile = String.Format(@"{0}\{1}.xml", Path.GetDirectoryName(prmInput), Path.GetFileNameWithoutExtension(prmInput)); m_Info = TcTileUtils.GetTileBlocks(xmlFile); // Type defined las tiling. foreach (TeGriddingType type in prmGridTypes) { String outputFile = String.Format(@"{0}\{1}_{2}.tor" , m_OutputDirectory , Path.GetFileNameWithoutExtension(prmInput) , TcEnums.ShortName(type)); gridObjects.Add(new TcGridObject(outputFile, type, m_Info)); } // Type defined las tiling. foreach (Int32 size in prmGridSizes.Distinct()) { String outputFile = String.Format(@"{0}\{1}_m{2}.tor" , m_OutputDirectory , Path.GetFileNameWithoutExtension(prmInput) , size); gridObjects.Add(new TcGridObject(outputFile, size, m_Info)); } Grid(prmInput, gridObjects); }
//----------------------------------------------------------------------------- /// <summary> /// This function reads the LAS file and arrange points into the specific grid. /// It also applies filtering for some given pre-defined gridding types. /// </summary> /// <typeparam name="T">Type of the LAS points</typeparam> /// <param name="prmReader">Tile LAS reader which reads LAS points by tile</param> /// <param name="prmObjects">A collection of grid data objects (1 per gridding type)</param> private void Grid <T>(TcTileLasReader prmReader, IEnumerable <TcGridObject> prmObjects) where T : TiLasPoint { TcLasPointBase[] points; TcTileBlockInfo info; for (int row = 0; row < m_Info.TileInfo.Row; row++) { for (int col = 0; col < m_Info.TileInfo.Col; col++) { if ((info = m_Info.TileBlocks.FirstOrDefault(iter => iter.Row == row && iter.Col == col)) != null) { points = prmReader.GetPointObjectsByTile <T>(row, col, m_LasHeader); foreach (TcGridObject gridObject in prmObjects) { // Report the message. ReportMessage(String.Format("Processing Tile({0},{1}) of {2} ({3}m)", row, col, TcEnums.ShortName(gridObject.Type), gridObject.GridSize)); // Filter points that are not required by 1M grid. if (gridObject.Type == TeGriddingType.M1FirstEcho || gridObject.Type == TeGriddingType.M1LastEcho) { FilterOutOfInterestPoints(points); } UpdateGrid(gridObject, info, points); } } } } foreach (TcGridObject gridObject in prmObjects) { // Write the tor file. TcTolObject objDiff = new TcTolObject(gridObject.OutputFile) { Rows = m_Info.TileInfo.Row * gridObject.GridCount, Columns = m_Info.TileInfo.Col * gridObject.GridCount, UpperLeftEast = m_LasHeader.MinX, UpperLeftNorth = m_LasHeader.MaxY, LowerRightEast = m_LasHeader.MaxX, LowerRightNorth = m_LasHeader.MinY, MinHeight = (Single)gridObject.MinZ, MaxHeight = (Single)gridObject.MaxZ, ScalingX = gridObject.GridSize, ScalingY = gridObject.GridSize, Model = m_CoordinateSystem, BitSize = 32 }; // Report the message. ReportMessage(String.Format("Writing {0}", Path.GetFileName(gridObject.OutputFile))); TcTorObject objTor = new TcTorObject(objDiff) { Blocks = gridObject.TorBlocks }; using (TcTorWriter writer = new TcTorWriter(objDiff)) { writer.WriteTol(); writer.Write(objTor); } } ReportFinished(); }
//----------------------------------------------------------------------------- public void LasToCls(IEnumerable <String> prmInputFiles, String prmOutputDirectory) { foreach (String file in prmInputFiles) { LasToCls(file, String.Format(@"{0}\{1}.{2}", prmOutputDirectory, Path.GetFileNameWithoutExtension(file), TcEnums.ShortName(m_Type))); } }
//----------------------------------------------------------------------------- public void ClsToLas(String prmInput, String prmOutput) { try { if (!File.Exists(prmInput)) { throw new FileNotFoundException("CLS file not found"); } if (!Path.GetExtension(prmInput).Contains(TcEnums.ShortName(m_Type))) { throw new InvalidDataException("Invalid input file format"); } if (!Path.GetExtension(prmOutput).Contains("las")) { throw new InvalidDataException("Invalid output file format"); } using (TcClsReader reader = new TcClsReader(prmInput)) { switch (reader.Header.PointDataFormatID) { case 0: ClsToLas <TsLasPoint0>(reader, prmOutput); break; case 1: ClsToLas <TsLasPoint1>(reader, prmOutput); break; case 2: ClsToLas <TsLasPoint2>(reader, prmOutput); break; case 3: ClsToLas <TsLasPoint3>(reader, prmOutput); break; case 4: ClsToLas <TsLasPoint4>(reader, prmOutput); break; case 5: ClsToLas <TsLasPoint5>(reader, prmOutput); break; case 6: ClsToLas <TsLasPoint6>(reader, prmOutput); break; case 7: ClsToLas <TsLasPoint7>(reader, prmOutput); break; case 8: ClsToLas <TsLasPoint8>(reader, prmOutput); break; case 9: ClsToLas <TsLasPoint9>(reader, prmOutput); break; case 10: ClsToLas <TsLasPoint10>(reader, prmOutput); break; default: throw new FormatException("Couldn't produce the file. LAS format not supported"); } } } catch (Exception ex) { ReportError("Failed to convert Acl file to LAS", ex); } }
//----------------------------------------------------------------------------- public void LasToCls(String prmInput) { LasToCls(prmInput, String.Format(@"{0}\{1}.{2}", Path.GetDirectoryName(prmInput), Path.GetFileNameWithoutExtension(prmInput), TcEnums.ShortName(m_Type))); }