diff --git a/bu/CopcSupport.cpp b/bu/CopcSupport.cpp index ff34d0b..46d7d61 100644 --- a/bu/CopcSupport.cpp +++ b/bu/CopcSupport.cpp @@ -41,12 +41,14 @@ CopcSupport::CopcSupport(const BaseInfo& b) : m_b(b), m_f.open(toNative(b.opts.outputName), std::ios::out | std::ios::binary); - //ABELL - m_header.file_source_id = 0; - m_header.global_encoding = (1 << 4); // Set for WKT - //ABELL - m_header.creation.day = 1; - m_header.creation.year = 1; + m_header.global_encoding = m_b.globalEncoding; + m_header.global_encoding |= (1 << 4); // Set for WKT + m_header.file_source_id = m_b.fileSourceId; + m_header.creation.day = m_b.creationDoy; + m_header.creation.year = m_b.creationYear; + m_b.systemId.copy(m_header.system_identifier, 32); + m_b.generatingSoftware.copy(m_header.generating_software, 32); + m_header.header_size = lazperf::header14::Size; m_header.point_format_id = m_b.pointFormatId; m_header.point_format_id |= (1 << 7); // Bit for laszip diff --git a/epf/Epf.cpp b/epf/Epf.cpp index 738e014..5dd9da9 100644 --- a/epf/Epf.cpp +++ b/epf/Epf.cpp @@ -336,9 +336,16 @@ void Epf::fillMetadata(const pdal::PointLayoutPtr layout) return std::round(minval + offset); // Add the base (min) value and round to an integer. }; - m_b.offset[0] = calcOffset(m_b.trueBounds.minx, m_b.trueBounds.maxx, m_b.scale[0]); - m_b.offset[1] = calcOffset(m_b.trueBounds.miny, m_b.trueBounds.maxy, m_b.scale[1]); - m_b.offset[2] = calcOffset(m_b.trueBounds.minz, m_b.trueBounds.maxz, m_b.scale[2]); + // Preserve offsets if we have them and --single_file with single input is used + if (!m_b.preserveHeaderFields() || + std::isnan(m_b.offset[0]) || + std::isnan(m_b.offset[1]) || + std::isnan(m_b.offset[2])) + { + m_b.offset[0] = calcOffset(m_b.trueBounds.minx, m_b.trueBounds.maxx, m_b.scale[0]); + m_b.offset[1] = calcOffset(m_b.trueBounds.miny, m_b.trueBounds.maxy, m_b.scale[1]); + m_b.offset[2] = calcOffset(m_b.trueBounds.minz, m_b.trueBounds.maxz, m_b.scale[2]); + } } PointCount Epf::createFileInfo(const StringList& input, StringList dimNames, @@ -420,6 +427,39 @@ PointCount Epf::createFileInfo(const StringList& input, StringList dimNames, if (m.valid()) zOffsets.push_back(m.value()); + if (m_b.preserveHeaderFields()) + { + m = root.findChild("global_encoding"); + if (m.valid()) + m_b.globalEncoding = m.value(); + m = root.findChild("creation_doy"); + if (m.valid()) + m_b.creationDoy = m.value(); + m = root.findChild("creation_year"); + if (m.valid()) + m_b.creationYear = m.value(); + m = root.findChild("filesource_id"); + if (m.valid()) + m_b.fileSourceId = m.value(); + m = root.findChild("software_id"); + if (m.valid()) + m_b.generatingSoftware = m.value(); + m = root.findChild("system_id"); + if (m.valid()) + m_b.systemId = m.value(); + } + else + { + std::time_t now; + std::time(&now); + std::tm* ptm = std::gmtime(&now); + if (ptm) + { + m_b.creationDoy = ptm->tm_yday + 1; + m_b.creationYear = ptm->tm_year + 1900; + } + } + FileInfo fi; fi.bounds = qi.m_bounds; fi.numPoints = qi.m_pointCount; diff --git a/untwine/Common.hpp b/untwine/Common.hpp index 79ee710..d118a37 100644 --- a/untwine/Common.hpp +++ b/untwine/Common.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -55,6 +56,8 @@ struct BaseInfo BaseInfo() {}; + bool preserveHeaderFields() const {return opts.singleFile && opts.inputFiles.size() == 1;} + Options opts; pdal::BOX3D bounds; pdal::BOX3D trueBounds; @@ -63,10 +66,18 @@ struct BaseInfo DimInfoList dimInfo; pdal::SpatialReference srs; int pointFormatId; + uint16_t globalEncoding {0}; + uint16_t creationYear {1}; + uint16_t creationDoy {1}; + uint16_t fileSourceId {0}; + std::string systemId; + std::string generatingSoftware { "Untwine" }; using d3 = std::array; d3 scale { -1.0, -1.0, -1.0 }; - d3 offset {}; + d3 offset { std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()}; }; // We make a special dimension to store the bits (class flags, scanner channel, scan dir, eofl).