Exemplo n.º 1
0
        //-----------------------------------------------------------------------------

        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)));
        }
Exemplo n.º 2
0
        //-----------------------------------------------------------------------------

        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));
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        //-----------------------------------------------------------------------------

        public void Tile(String prmInput, String prmOutput)
        {
            // Variables to be used inside the big loop.
            LasPoint2 point;
            // Int32 east, north, col, row;
            Int32 tileOffset      = 0;
            Int32 index           = -1;
            Int32 pointsProcessed = 0;

            using (TcLasReader reader = new TcLasReader(prmInput))
            {
                LasHeader header = reader.GetHeaderOld();
                UpdateTileCounts(header, m_TileSize);

                String blockFile = String.Format(@"{0}\{1}.xml", Path.GetDirectoryName(prmOutput), Path.GetFileNameWithoutExtension(prmOutput));
                if (File.Exists(blockFile))
                {
                    File.Delete(blockFile);
                }

                using (TcLasWriter writer = new TcLasWriter(prmOutput))
                {
                    header.MinX = m_RevisedEast;
                    header.MaxY = m_RevisedNorth;

                    writer.WriteHeader(header);
                    Int32 onePercent = header.NumberOfPointRecords / 100;

                    for (int i = 0; i < header.NumberOfPointRecords; i++)
                    {
                        point = reader.ReadPoint(header);
                        if (point.X <= 0 || point.Y <= 0)
                        {
                            continue;
                        }

                        // Calculate the tile index for the point.
                        tileOffset = m_TileSize * m_Factor;

/*
 *                      east = Convert.ToInt32(point.X - (point.X % tileOffset));
 *                      north = Convert.ToInt32(point.Y - (point.Y % tileOffset)) + tileOffset;
 *                      col = (east - m_RevisedEast) / tileOffset;
 *                      row = (m_RevisedNorth - north) / tileOffset;
 */
                        Int32[] rowCol = TcMathUtil.GetRowCol(point.X, point.Y, m_RevisedEast, m_RevisedNorth, tileOffset, tileOffset);
                        index = rowCol[1] * m_TileRows + rowCol[0];

                        // Add that into the intermediate tile block.
                        if (!m_TileBlocks.ContainsKey(index))
                        {
                            m_TileBlocks[index]      = new LasPoint2[m_TileBlockSize];
                            m_BlockPointCount[index] = 0;
                        }

                        m_TileBlocks[index][m_BlockPointCount[index]] = point;
                        m_BlockPointCount[index]++;

                        // When a tile block is full, write into file and remove the points.
                        if (m_BlockPointCount[index] == m_TileBlockSize)
                        {
                            writer.WritePoints(m_TileBlocks[index], header, m_TileBlockSize);
                            ProcessTileBlock(rowCol[0], rowCol[1], index, pointsProcessed);
                            pointsProcessed += m_TileBlockSize;
                        }

                        if (i % onePercent == 0)
                        {
                            NotifyTileProgress(prmInput, prmOutput, rowCol[0], rowCol[1], pointsProcessed, i / onePercent);
                        }
                    }

                    // Process the remaining blocks with incomplete size.
                    int row, col;
                    foreach (Int32 idx in m_TileBlocks.Keys.ToList())
                    {
                        row = idx % m_TileRows;
                        col = (idx - row) / m_TileRows;

                        writer.WritePoints(m_TileBlocks[idx], header, m_BlockPointCount[idx]);
                        ProcessTileBlock(row, col, idx, pointsProcessed);
                        pointsProcessed += m_BlockPointCount[idx];
                    }

                    TcTileUtils.SaveTileBlocks(m_TileBlockInfoCollection, blockFile);
                }
            }
        }