diff --git a/Project.toml b/Project.toml index 1ae4615..e5b2323 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/dataset.jl b/src/dataset.jl index 2a55679..ecdca2f 100644 --- a/src/dataset.jl +++ b/src/dataset.jl @@ -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 diff --git a/src/point.jl b/src/point.jl index e56ee59..0790867 100644 --- a/src/point.jl +++ b/src/point.jl @@ -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 @@ -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 @@ -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 @@ -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) ) @@ -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 @@ -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]), @@ -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 @@ -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]), diff --git a/test/testio.jl b/test/testio.jl index 30a4252..32287d6 100644 --- a/test/testio.jl +++ b/test/testio.jl @@ -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 @@ -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