r-lidar / rlas

R package to read and write las and laz files used to store LiDAR data
https://cran.r-project.org/package=rlas
GNU General Public License v3.0
34 stars 14 forks source link

Extra bytes with NAs are not written #16

Closed Jean-Romain closed 6 years ago

Jean-Romain commented 6 years ago

@floriandeboissieu

See testthat test-header tools line 41.

Index out of bounds: [index='no_data'].

This come from writeLAS.cpp line 137. I do not support properly no_data because I do not understand what is the expected information.

floriandeboissieu commented 6 years ago

no_data is the value that should replace NA value when writing file. Example, let say that you have an Extra Byte with integer values that can never reach value -999, well you can set no_data=-999. Before sending the data to laswriter, all NA should be replaced by -999 and when reading the written file, all values at -999 should be replaced by NA before sending it back to user.

Another example: let say that you have an Extra Byte with float values, that you want store in integer after scaling with scale=0.01 and offset=50.2. Let's say 0.0 is a value never reached by the Extra Byte, i.e. no_data=0.0. All NA values should be replaced by 50.2 before calling laswriter, the no_data value will be scaled in the cpp writer and stored in the file as int((0.0 - 50.2)/0.01)=-5020. At reading, the opposit should happen, i.e. -50.2 values should be replaced by NA values before sending them to user.

Does it answer the question?

floriandeboissieu commented 6 years ago

I just look into the code, no_data should be part of header_add_extrabytes_manual signature. If has_na=1 a no_data value should be set in list in the same function. By default, it could be the maximum of the data type, e.g. .Machine$integer.max for integers, .Machine$double.xmax for doubles.

Jean-Romain commented 6 years ago

I got it!