Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to forward laz header info #149

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions bu/CopcSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 43 additions & 3 deletions epf/Epf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -420,6 +427,39 @@ PointCount Epf::createFileInfo(const StringList& input, StringList dimNames,
if (m.valid())
zOffsets.push_back(m.value<double>());

if (m_b.preserveHeaderFields())
{
m = root.findChild("global_encoding");
if (m.valid())
m_b.globalEncoding = m.value<int>();
m = root.findChild("creation_doy");
if (m.valid())
m_b.creationDoy = m.value<int>();
m = root.findChild("creation_year");
if (m.valid())
m_b.creationYear = m.value<int>();
m = root.findChild("filesource_id");
if (m.valid())
m_b.fileSourceId = m.value<int>();
m = root.findChild("software_id");
if (m.valid())
m_b.generatingSoftware = m.value<std::string>();
m = root.findChild("system_id");
if (m.valid())
m_b.systemId = m.value<std::string>();
}
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;
Expand Down
13 changes: 12 additions & 1 deletion untwine/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stdint.h>
#include <array>
#include <limits>
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -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;
Expand All @@ -63,10 +66,18 @@ struct BaseInfo
DimInfoList dimInfo;
pdal::SpatialReference srs;
int pointFormatId;
uint16_t globalEncoding {0};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given what we're doing here, would it make sense just to include an entire lazperf::header, rather than all these separate fields? I think that would make it more clear what this data is all about, rather than just have it be random stuff sitting in the BaseInfo block. We can merge this and I can take care of that change if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that too when I kept adding members there, but wasn't too sure, as there will be unused lazperf::header(14?) variables there that might be confusing.

uint16_t creationYear {1};
uint16_t creationDoy {1};
uint16_t fileSourceId {0};
std::string systemId;
std::string generatingSoftware { "Untwine" };

using d3 = std::array<double, 3>;
d3 scale { -1.0, -1.0, -1.0 };
d3 offset {};
d3 offset { std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN()};
};

// We make a special dimension to store the bits (class flags, scanner channel, scan dir, eofl).
Expand Down
Loading