Skip to content

Commit

Permalink
Add scan angle back. Add indexing methods to dataset. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion authored Jul 22, 2023
1 parent 72af373 commit 9c1c7fc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ GeoInterface = "1"
GeoInterfaceRecipes = "1"
LasIO = "0.3"
StaticArrays = "1"
Tables = "0.2, 1.0"
julia = "1.3"
Tables = "1.0"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
22 changes: 22 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ function Base.getindex(ds::Dataset, i::Integer)
eltype(ds)(unsafe_load(ds.point), CoordinateTransformations.AffineMap(ds))
end

function Base.getindex(ds::Dataset, i::UnitRange{<:Integer})
out = Vector{eltype(ds)}(undef, length(i))
(1 <= i[begin] <= length(ds)) && (1 <= i[end] <= length(ds)) || throw(BoundsError(ds, i))
laszip_seek_point(ds.filehandle, i[begin] - 1)
for I in eachindex(out)
laszip_read_point(ds.filehandle)
out[I] = eltype(ds)(unsafe_load(ds.point), CoordinateTransformations.AffineMap(ds))
end
out
end

function Base.getindex(ds::Dataset, i::StepRange{<:Integer,<:Integer})
out = Vector{eltype(ds)}(undef, length(i))
(1 <= i[begin] <= length(ds)) && (1 <= i[end] <= length(ds)) || throw(BoundsError(ds, i))
for I in eachindex(out)
laszip_seek_point(ds.filehandle, i[I] - 1)
laszip_read_point(ds.filehandle)
out[I] = eltype(ds)(unsafe_load(ds.point), CoordinateTransformations.AffineMap(ds))
end
out
end

Base.eltype(::Dataset{0x00}) = Point0
Base.eltype(::Dataset{0x01}) = Point1
Base.eltype(::Dataset{0x02}) = Point2
Expand Down
8 changes: 8 additions & 0 deletions src/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct Point0 <: Point
synthetic::Bool
key_point::Bool
withheld::Bool
scan_angle_rank::Int8
user_data::UInt8
point_source_id::UInt16
end
Expand All @@ -25,6 +26,7 @@ function Point0(rp, am)
synthetic(rp),
key_point(rp),
withheld(rp),
rp.scan_angle_rank,
rp.user_data, rp.point_source_ID
)
end
Expand All @@ -40,6 +42,7 @@ struct Point1 <: Point
synthetic::Bool
key_point::Bool
withheld::Bool
scan_angle_rank::Int8
user_data::UInt8
point_source_id::UInt16
gps_time::Dates.DateTime
Expand All @@ -56,6 +59,7 @@ function Point1(rp, am)
synthetic(rp),
key_point(rp),
withheld(rp),
rp.scan_angle_rank,
rp.user_data, rp.point_source_ID,
Dates.DateTime(rp)
)
Expand All @@ -72,6 +76,7 @@ struct Point2 <: Point
synthetic::Bool
key_point::Bool
withheld::Bool
scan_angle_rank::Int8
user_data::UInt8
point_source_id::UInt16
r::N0f16
Expand All @@ -90,6 +95,7 @@ function Point2(rp, am)
synthetic(rp),
key_point(rp),
withheld(rp),
rp.scan_angle_rank,
rp.user_data, rp.point_source_ID,
reinterpret(N0f16, rp.rgb[1]),
reinterpret(N0f16, rp.rgb[2]),
Expand All @@ -109,6 +115,7 @@ struct Point3 <: Point
synthetic::Bool
key_point::Bool
withheld::Bool
scan_angle_rank::Int8
user_data::UInt8
point_source_id::UInt16
gps_time::Dates.DateTime
Expand All @@ -128,6 +135,7 @@ function Point3(rp, am)
synthetic(rp),
key_point(rp),
withheld(rp),
rp.scan_angle_rank,
rp.user_data, rp.point_source_ID,
Dates.DateTime(rp),
reinterpret(N0f16, rp.rgb[1]),
Expand Down
18 changes: 18 additions & 0 deletions test/testio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ end
@test first(ds) isa LazIO.Point0
@inferred first(ds)
@inferred ds[1]
@inferred ds[1:2]
@inferred ds[1:2:5]
@inferred collect(ds)
@test LazIO.boundingbox(ds) == (xmin=1.44e6, ymin=375000.03, zmin=832.1800000000001, xmax=1.44499996e6, ymax=379999.99, zmax=972.6700000000001)
@test first(ds).return_number == 0x00
Expand Down Expand Up @@ -218,3 +220,19 @@ end

@test GeoInterface.z(GeoInterface.getpoint(collect(ds)[1:2], 1)) == 846.66
end

@testset "Indexing" begin
ds = LazIO.open(testfile_str)

p = ds[3]

r = 1:3
range = ds[r]
@test length(range) == length(r)
@test range[end] == p

s = 1:2:5
step = ds[s]
@test length(step) == length(s)
@test step[2] == p
end

0 comments on commit 9c1c7fc

Please sign in to comment.