Skip to content

Commit 9c1c7fc

Browse files
authored
Add scan angle back. Add indexing methods to dataset. (#33)
1 parent 72af373 commit 9c1c7fc

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ GeoInterface = "1"
2929
GeoInterfaceRecipes = "1"
3030
LasIO = "0.3"
3131
StaticArrays = "1"
32-
Tables = "0.2, 1.0"
33-
julia = "1.3"
32+
Tables = "1.0"
33+
julia = "1.6"
3434

3535
[extras]
3636
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/dataset.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ function Base.getindex(ds::Dataset, i::Integer)
6969
eltype(ds)(unsafe_load(ds.point), CoordinateTransformations.AffineMap(ds))
7070
end
7171

72+
function Base.getindex(ds::Dataset, i::UnitRange{<:Integer})
73+
out = Vector{eltype(ds)}(undef, length(i))
74+
(1 <= i[begin] <= length(ds)) && (1 <= i[end] <= length(ds)) || throw(BoundsError(ds, i))
75+
laszip_seek_point(ds.filehandle, i[begin] - 1)
76+
for I in eachindex(out)
77+
laszip_read_point(ds.filehandle)
78+
out[I] = eltype(ds)(unsafe_load(ds.point), CoordinateTransformations.AffineMap(ds))
79+
end
80+
out
81+
end
82+
83+
function Base.getindex(ds::Dataset, i::StepRange{<:Integer,<:Integer})
84+
out = Vector{eltype(ds)}(undef, length(i))
85+
(1 <= i[begin] <= length(ds)) && (1 <= i[end] <= length(ds)) || throw(BoundsError(ds, i))
86+
for I in eachindex(out)
87+
laszip_seek_point(ds.filehandle, i[I] - 1)
88+
laszip_read_point(ds.filehandle)
89+
out[I] = eltype(ds)(unsafe_load(ds.point), CoordinateTransformations.AffineMap(ds))
90+
end
91+
out
92+
end
93+
7294
Base.eltype(::Dataset{0x00}) = Point0
7395
Base.eltype(::Dataset{0x01}) = Point1
7496
Base.eltype(::Dataset{0x02}) = Point2

src/point.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct Point0 <: Point
1010
synthetic::Bool
1111
key_point::Bool
1212
withheld::Bool
13+
scan_angle_rank::Int8
1314
user_data::UInt8
1415
point_source_id::UInt16
1516
end
@@ -25,6 +26,7 @@ function Point0(rp, am)
2526
synthetic(rp),
2627
key_point(rp),
2728
withheld(rp),
29+
rp.scan_angle_rank,
2830
rp.user_data, rp.point_source_ID
2931
)
3032
end
@@ -40,6 +42,7 @@ struct Point1 <: Point
4042
synthetic::Bool
4143
key_point::Bool
4244
withheld::Bool
45+
scan_angle_rank::Int8
4346
user_data::UInt8
4447
point_source_id::UInt16
4548
gps_time::Dates.DateTime
@@ -56,6 +59,7 @@ function Point1(rp, am)
5659
synthetic(rp),
5760
key_point(rp),
5861
withheld(rp),
62+
rp.scan_angle_rank,
5963
rp.user_data, rp.point_source_ID,
6064
Dates.DateTime(rp)
6165
)
@@ -72,6 +76,7 @@ struct Point2 <: Point
7276
synthetic::Bool
7377
key_point::Bool
7478
withheld::Bool
79+
scan_angle_rank::Int8
7580
user_data::UInt8
7681
point_source_id::UInt16
7782
r::N0f16
@@ -90,6 +95,7 @@ function Point2(rp, am)
9095
synthetic(rp),
9196
key_point(rp),
9297
withheld(rp),
98+
rp.scan_angle_rank,
9399
rp.user_data, rp.point_source_ID,
94100
reinterpret(N0f16, rp.rgb[1]),
95101
reinterpret(N0f16, rp.rgb[2]),
@@ -109,6 +115,7 @@ struct Point3 <: Point
109115
synthetic::Bool
110116
key_point::Bool
111117
withheld::Bool
118+
scan_angle_rank::Int8
112119
user_data::UInt8
113120
point_source_id::UInt16
114121
gps_time::Dates.DateTime
@@ -128,6 +135,7 @@ function Point3(rp, am)
128135
synthetic(rp),
129136
key_point(rp),
130137
withheld(rp),
138+
rp.scan_angle_rank,
131139
rp.user_data, rp.point_source_ID,
132140
Dates.DateTime(rp),
133141
reinterpret(N0f16, rp.rgb[1]),

test/testio.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ end
4343
@test first(ds) isa LazIO.Point0
4444
@inferred first(ds)
4545
@inferred ds[1]
46+
@inferred ds[1:2]
47+
@inferred ds[1:2:5]
4648
@inferred collect(ds)
4749
@test LazIO.boundingbox(ds) == (xmin=1.44e6, ymin=375000.03, zmin=832.1800000000001, xmax=1.44499996e6, ymax=379999.99, zmax=972.6700000000001)
4850
@test first(ds).return_number == 0x00
@@ -218,3 +220,19 @@ end
218220

219221
@test GeoInterface.z(GeoInterface.getpoint(collect(ds)[1:2], 1)) == 846.66
220222
end
223+
224+
@testset "Indexing" begin
225+
ds = LazIO.open(testfile_str)
226+
227+
p = ds[3]
228+
229+
r = 1:3
230+
range = ds[r]
231+
@test length(range) == length(r)
232+
@test range[end] == p
233+
234+
s = 1:2:5
235+
step = ds[s]
236+
@test length(step) == length(s)
237+
@test step[2] == p
238+
end

0 commit comments

Comments
 (0)