//----------------------------------------------------------------------------- private void ClsToLas <T>(TcClsReader prmReader, String prmOutput) where T : TiLasPoint { m_Progress = 0; ReportMessage(String.Format("Processing {0}", Path.GetFileName(prmOutput))); using (TcLasWriter writer = new TcLasWriter(prmOutput)) { writer.WriteHeader(prmReader.Header, prmReader.OffsetBytes); Int64 numberOfPointRecords = prmReader.Header.GetNumberOfPoints(); Int64 noOfPointsLoaded = 0; Int64 noOfPointsToRead = 0; TiLasPoint[] lasPoints = new TiLasPoint[TcConstants.MaxLasPointsToProcessAtOnce]; TsClsLasPoint[] clsPoints; Double pointIndex = 1; while (noOfPointsLoaded < numberOfPointRecords) { noOfPointsToRead = Math.Min(TcConstants.MaxLasPointsToProcessAtOnce, numberOfPointRecords - noOfPointsLoaded); clsPoints = prmReader.ReadPoints(noOfPointsToRead); for (int i = 0; i < noOfPointsToRead; i++) { lasPoints[i] = ClsToLasByPDRF(clsPoints[i], prmReader.Header.PointDataFormatID, pointIndex++); } writer.WritePoints(lasPoints, noOfPointsToRead); noOfPointsLoaded += noOfPointsToRead; ReportProgress(noOfPointsLoaded, numberOfPointRecords); } } ReportMessage(String.Format("Finished {0}", Path.GetFileName(prmOutput))); }
//----------------------------------------------------------------------------- private void ClsToLas <T>(TcLasReader prmReader, String prmAclFile, String prmAcbFile, String prmOutputLas) where T : TiLasGPS { using (BinaryReader acbReader = new BinaryReader(new FileStream(prmAcbFile, FileMode.Open))) { Int64 totalPoints = acbReader.ReadInt64(); // When the binary file doesn't have enough points. if (totalPoints != (acbReader.BaseStream.Length - acbReader.BaseStream.Position)) { throw new InvalidDataException(String.Format("Length of data mismatched in {0} file", Path.GetFileName(prmAcbFile))); } // Check against the number of points in the original LAS files. if (totalPoints != prmReader.TotalPoints) { throw new InvalidDataException(String.Format("{0} file doesn't have save number of points as LAS", Path.GetFileName(prmAcbFile))); } using (TcLasWriter lasWriter = new TcLasWriter(prmOutputLas)) { Int64 noOfPointsToProcess = 0; Int64 noOfPointsProcessed = 0; T[] points = new T[TcConstants.MaxLasPointsToProcessAtOnce]; Byte[] clsData = acbReader.ReadBytes((Int32)totalPoints); // Write the header. lasWriter.WriteHeader(prmReader.Header, prmReader.OffsetBytes); while (noOfPointsProcessed < prmReader.TotalPoints) { // Calculate how many points to read. noOfPointsToProcess = Math.Min(TcConstants.MaxLasPointsToProcessAtOnce, prmReader.TotalPoints - noOfPointsProcessed); // Read a block of points from the LAS file. points = prmReader.ReadPoints <T>(noOfPointsToProcess); // Update the classification flag. for (int i = 0; i < noOfPointsToProcess; i++) { points[i].Classification = clsData[noOfPointsProcessed + i]; } lasWriter.WritePoints <T>(points); // Notify the progress to the caller thread. ReportProgress(noOfPointsProcessed, totalPoints); noOfPointsProcessed += noOfPointsToProcess; } // Process the extra points if there is any. if (!String.IsNullOrWhiteSpace(prmAclFile) && File.Exists(prmAclFile)) { using (TcClsReader clsReader = new TcClsReader(prmAclFile)) { TsClsLasPoint[] extraPoints = clsReader.ReadPoints(clsReader.TotalPoints); TiLasGPS[] extraLasPoints = new TiLasGPS[clsReader.TotalPoints]; for (int i = 0; i < clsReader.TotalPoints; i++) { extraLasPoints[i] = ClsToLasPoint(extraPoints[i], clsReader.Header.PointDataFormatID); // Point transformation as the offset and/or scaling factor might be changed in different software. extraLasPoints[i].X = (Int32)(((clsReader.Header.XOffset + extraLasPoints[i].X * clsReader.Header.XScaleFactor) - prmReader.Header.XOffset) / prmReader.Header.XScaleFactor); extraLasPoints[i].Y = (Int32)(((clsReader.Header.YOffset + extraLasPoints[i].Y * clsReader.Header.YScaleFactor) - prmReader.Header.YOffset) / prmReader.Header.YScaleFactor); extraLasPoints[i].Z = (Int32)(((clsReader.Header.ZOffset + extraLasPoints[i].Z * clsReader.Header.ZScaleFactor) - prmReader.Header.ZOffset) / prmReader.Header.ZScaleFactor); } lasWriter.WritePoints(extraLasPoints); // Write the updated header. lasWriter.WriteHeader(GetHeaderForMergedLas(prmReader.Header, clsReader.TotalPoints)); } } } } }