| 165 | |
| 166 | |
| 167 | void Processor::writeCompressed(VoxelKey k, PointViewPtr v) |
| 168 | { |
| 169 | if (v->size() == 0) |
| 170 | { |
| 171 | m_manager.newChunk(k, 0, 0); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | PointLayoutPtr layout = v->layout(); |
| 176 | |
| 177 | std::vector<char> buf(lazperf::baseCount(b.pointFormatId) + b.numExtraBytes); |
| 178 | lazperf::writer::chunk_compressor compressor(b.pointFormatId, b.numExtraBytes); |
| 179 | |
| 180 | // Sort by GPS time - no-op if there's no GPS time. |
| 181 | v->sort(Dimension::Id::GpsTime); |
| 182 | |
| 183 | for (PointId idx = 0; idx < v->size(); ++idx) |
| 184 | { |
| 185 | PointRef point(*v, idx); |
| 186 | m_loader.pack(point, buf.data(), buf.size()); |
| 187 | compressor.compress(buf.data()); |
| 188 | } |
| 189 | std::vector<unsigned char> chunk = compressor.done(); |
| 190 | uint64_t location = m_manager.newChunk(k, (uint32_t)chunk.size(), (uint32_t)v->size()); |
| 191 | |
| 192 | std::ofstream out(b.filename, std::ios::out | std::ios::in | std::ios::binary); |
| 193 | out.seekp(std::ofstream::pos_type(location)); |
| 194 | out.write(reinterpret_cast<const char *>(chunk.data()), chunk.size()); |
| 195 | out.close(); |
| 196 | if (!out) |
| 197 | throw pdal_error("Failure writing to '" + b.filename + "'."); |
| 198 | } |
| 199 | |
| 200 | } // namespace copcwriter |
| 201 | } // namespace pdal |