Skip to content

add a constructor that just needs the pointcloud #48

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

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LASDatasets"
uuid = "cc498e2a-d443-4943-8f26-2a8a0f3c7cdb"
authors = ["BenCurran98 <b.curran@fugro.com>"]
version = "0.3.2"
version = "0.3.3"

[deps]
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md

This package started as a fork off of [LasIO.jl](https://github.com/visr/LasIO.jl), with modifications being made to add *LAS* v1.4 support and some *API*/functionality changes.

* Thanks to [@visr](https://github.com/visr) as the authour of the *LasIO.jl* package
* Thanks to [@visr](https://github.com/visr) as the author of the *LasIO.jl* package
* Thanks to all developers in *LasIO.jl* and [*LazIO.jl*](https://github.com/evetion/LazIO.jl), including [@evetion](https://github.com/evetion)
2 changes: 1 addition & 1 deletion src/LASDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export scan_direction, user_data

# header interface
export LasHeader, is_standard_gps, is_wkt, file_source_id, global_encoding, las_version, system_id, software_id, creation_day_of_year, creation_year
export header_size, point_data_offset, point_record_length, record_format, point_format, number_of_points, number_of_vlrs, number_of_evlrs, evlr_start, spatial_info, num_return_channels
export header_size, point_data_offset, point_record_length, record_format, point_format, number_of_points, number_of_vlrs, number_of_evlrs, evlr_start, spatial_info, scale, num_return_channels
export set_las_version!, set_spatial_info!, set_point_data_offset!, set_point_format!, set_point_record_length!, set_point_record_count!, set_num_vlr!, set_num_evlr!, set_gps_week_time_bit!
export set_gps_standard_time_bit!, is_internal_waveform, is_external_waveform, unset_wkt_bit!
export set_waveform_external_bit!, set_waveform_internal_bit!, set_synthetic_return_numbers_bit!, unset_synthetic_return_numbers_bit!
Expand Down
26 changes: 26 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ mutable struct LASDataset
end
end

"""
$(TYPEDSIGNATURES)

Create a LASDataset from a pointcloud and optionally vlrs/evlrs/user_defined_bytes,
NO header required.
"""
function LASDataset(pointcloud::Table;
vlrs::Vector{<:LasVariableLengthRecord} = LasVariableLengthRecord[],
evlrs::Vector{<:LasVariableLengthRecord} = LasVariableLengthRecord[],
user_defined_bytes::Vector{UInt8} = UInt8[],
scale::Real = POINT_SCALE)

point_format = get_point_format(pointcloud)
spatial_info = get_spatial_info(pointcloud; scale = scale)

header = LasHeader(;
las_version = lasversion_for_point(point_format),
data_format_id = UInt8(get_point_format_id(point_format)),
data_record_length = UInt16(byte_size(point_format)),
spatial_info = spatial_info,
)

make_consistent_header!(header, pointcloud, vlrs, evlrs, user_defined_bytes)

return LASDataset(header, pointcloud, vlrs, evlrs, user_defined_bytes)
end

"""
$(TYPEDSIGNATURES)
Expand Down
13 changes: 13 additions & 0 deletions src/header.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,18 @@ Get the spatial information for point positions in a LAS file from a header `h`.
"""
spatial_info(h::LasHeader) = h.spatial_info

"""
$(TYPEDSIGNATURES)

Get the scale for point positions in a LAS file from a header `h`. Checks consistent scale for ALL axis.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Axis is singular, if you mean plural it should be axes.

"""
function scale(h::LasHeader)

@assert (h.spatial_info.scale.x == h.spatial_info.scale.y) && (h.spatial_info.scale.y == h.spatial_info.scale.z) "We expect all axis to be scale similarly"
Copy link
Collaborator

@i-kieu i-kieu Jan 6, 2025

Choose a reason for hiding this comment

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

Same here and "scaled" for past tense


return h.spatial_info.scale.x
end

"""
$(TYPEDSIGNATURES)

Expand Down Expand Up @@ -792,6 +804,7 @@ function make_consistent_header!(header::LasHeader,
point_data_offset = header_size + vlr_size + length(user_defined_bytes)

set_point_data_offset!(header, point_data_offset)
set_spatial_info!(header, get_spatial_info(pointcloud; scale = scale(header)))

set_point_record_count!(header, length(pointcloud))
returns = (:returnnumber ∈ columnnames(pointcloud)) ? pointcloud.returnnumber : ones(Int, length(pointcloud))
Expand Down
6 changes: 6 additions & 0 deletions test/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
# check equality if we create two of the same dataset
other_las = LASDataset(deepcopy(header), deepcopy(pc), LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
@test other_las == las

# test constructor with pc Only
h = LasHeader(; las_version = v"1.1", data_format_id = UInt8(1), data_record_length = UInt16(28))
LASDatasets.make_consistent_header!(h, pc, LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
las = LASDataset(h, pc, LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
@test las == LASDataset(deepcopy(pc))

# now try incorporating some user fields
spicy_pc = Table(pc, thing = rand(num_points), other_thing = rand(Int16, num_points))
Expand Down
Loading