@@ -3,6 +3,7 @@ struct Dataset{Version}
33 filehandle:: Ptr{Cvoid}
44 header:: LazHeader # this enables iterating without unsafe_load everytime
55 point:: Ptr{RawPoint}
6+ am:: CoordinateTransformations.AffineMap
67end
78
89function Base. show (io:: IO , ds:: Dataset{Version} ) where {Version}
@@ -36,20 +37,23 @@ function open(f::AbstractString)
3637 point_ptr = Ref {Ptr{RawPoint}} ()
3738 @check laszip_reader[] laszip_get_point_pointer (laszip_reader[], point_ptr)
3839
40+ # Get coordinate transformation
41+ am = CoordinateTransformations. AffineMap (Diagonal (SA_F64[header. x_scale_factor 0 0 ; 0 header. y_scale_factor 0 ; 0 0 header. z_scale_factor]), SA_F64[header. x_offset, header. y_offset, header. z_offset])
42+
3943 header. point_data_format > 3 && @warn " The LAS 1.4+ format is not fully supported yet."
40- Dataset {header.point_data_format} (f, laszip_reader[], header, point_ptr[])
44+ Dataset {header.point_data_format} (f, laszip_reader[], header, point_ptr[], am )
4145end
4246
4347function CoordinateTransformations. AffineMap (ds:: Dataset )
44- CoordinateTransformations . AffineMap ( Diagonal (SA_F64[ ds. header . x_scale_factor 0 0 ; 0 ds . header . y_scale_factor 0 ; 0 0 ds . header . z_scale_factor]), SA_F64[ds . header . x_offset, ds . header . y_offset, ds . header . z_offset])
48+ ds. am
4549end
4650
4751""" Iteration of LAZ file."""
4852function Base. iterate (ds:: Dataset , state:: Int )
4953 if state >= length (ds)
5054 return nothing
5155 else
52- laszip_read_point (ds. filehandle)
56+ @check ds . filehandle laszip_read_point (ds. filehandle)
5357 return eltype (ds)(unsafe_load (ds. point), CoordinateTransformations. AffineMap (ds)), state + 1
5458 end
5559end
@@ -59,25 +63,26 @@ function Base.iterate(ds::Dataset)
5963 if length (ds) == 0
6064 nothing
6165 else
62- laszip_seek_point (ds. filehandle, 0 )
63- laszip_read_point (ds. filehandle)
66+ @check ds . filehandle laszip_seek_point (ds. filehandle, 0 )
67+ @check ds . filehandle laszip_read_point (ds. filehandle)
6468 eltype (ds)(unsafe_load (ds. point), CoordinateTransformations. AffineMap (ds)), 1
6569 end
6670end
6771
6872function Base. getindex (ds:: Dataset , i:: Integer )
6973 (1 <= i <= length (ds)) || throw (BoundsError (ds, i))
70- laszip_seek_point (ds. filehandle, i - 1 )
71- laszip_read_point (ds. filehandle)
74+ @check ds . filehandle laszip_seek_point (ds. filehandle, i - 1 )
75+ @check ds . filehandle laszip_read_point (ds. filehandle)
7276 eltype (ds)(unsafe_load (ds. point), CoordinateTransformations. AffineMap (ds))
7377end
7478
7579function Base. getindex (ds:: Dataset , i:: UnitRange{<:Integer} )
7680 out = Vector {eltype(ds)} (undef, length (i))
81+ isempty (i) && return out
7782 (1 <= i[begin ] <= length (ds)) && (1 <= i[end ] <= length (ds)) || throw (BoundsError (ds, i))
78- laszip_seek_point (ds. filehandle, i[begin ] - 1 )
83+ @check ds . filehandle laszip_seek_point (ds. filehandle, i[begin ] - 1 )
7984 for I in eachindex (out)
80- laszip_read_point (ds. filehandle)
85+ @check ds . filehandle laszip_read_point (ds. filehandle)
8186 out[I] = eltype (ds)(unsafe_load (ds. point), CoordinateTransformations. AffineMap (ds))
8287 end
8388 out
@@ -87,8 +92,8 @@ function Base.getindex(ds::Dataset, i::StepRange{<:Integer,<:Integer})
8792 out = Vector {eltype(ds)} (undef, length (i))
8893 (1 <= i[begin ] <= length (ds)) && (1 <= i[end ] <= length (ds)) || throw (BoundsError (ds, i))
8994 for I in eachindex (out)
90- laszip_seek_point (ds. filehandle, i[I] - 1 )
91- laszip_read_point (ds. filehandle)
95+ @check ds . filehandle laszip_seek_point (ds. filehandle, i[I] - 1 )
96+ @check ds . filehandle laszip_read_point (ds. filehandle)
9297 out[I] = eltype (ds)(unsafe_load (ds. point), CoordinateTransformations. AffineMap (ds))
9398 end
9499 out
0 commit comments