示例#1
0
        //-----------------------------------------------------------------------------

        public LasPoint2[] GetPointsByTile(String prmInput, Int32 prmRow, Int32 prmCol)
        {
            String blockFile = String.Format(@"{0}\{1}.xml", Path.GetDirectoryName(prmInput), Path.GetFileNameWithoutExtension(prmInput));
            TcTileBlockInfoCollection tileInfoCollection = TcTileUtils.GetTileBlocks(blockFile);

            IEnumerable <TcTileBlockInfo> blocks = tileInfoCollection.TileBlocks.Where(iter => iter.Row == prmRow && iter.Col == prmCol);
            Int32 numberOfPoints = blocks.Aggregate(0, (result, iter) => result += iter.NoOfPoints);

            using (TcLasReader reader = new TcLasReader(prmInput))
            {
                LasHeader   header     = reader.GetHeaderOld();
                LasPoint2[] points     = new LasPoint2[numberOfPoints];
                Int32       arrayStart = 0;
                foreach (TcTileBlockInfo info in blocks)
                {
                    if (reader.GetLasBlock(ref points, arrayStart, info.StartPoint, info.NoOfPoints, header))
                    {
                        arrayStart += info.NoOfPoints;
                    }
                    else
                    {
                        throw new Exception(String.Format("Couldn't read the las tile ({0},{1})", prmRow, prmCol));
                    }
                }
                return(points);
            }
        }
示例#2
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);
                }
            }
        }