3dgeo-heidelberg / pytreedb

Python package providing a file and object-based database to store tree objects.
Other
28 stars 4 forks source link

Reading the point locuds #101

Closed ArashJavan closed 1 year ago

ArashJavan commented 1 year ago

Hello, thanks for open sourcing your great work. I would like to read the point clouds from the trees. But after reading a downloaded "laz" file you provide, I get big integer values for X,Y,Z.

Example:

# read laz-file
>> print(las.points)
>> array([(1289091, 467973, -42666, 38645, 73, 4,  72, 0,  3, 545904.89286093, 1127,  -313, 6), ...

Specially I am interested to plot each tree as you have in you paper:

Screenshot_2022-11-25_13-10-16

I am thankful for any help on how to normalize the values in the laz-file XYZ-Points.

Best regards Arash

bhoefle-3dgeo commented 1 year ago

Hi Arash, this paper describes all processing steps and is the one to be cited when using the data:

Weiser, H., Schäfer, J., Winiwarter, L., Krašovec, N., Fassnacht, F.E. & Höfle, B. (2022): [Individual tree point clouds and tree measurements from multi-platform laser scanning in German forests](https://doi.org/10.5194/essd-14-2989-2022). Earth System Science Data. Vol. 14 (7), pp. 2989-3012. 

URL: https://doi.org/10.5194/essd-14-2989-2022

There you will find in Sect. 2.4.2: "In addition to field measurements, tree metrics were estimated from the laser scanning point clouds. For the computation of the metrics, the height values of each tree point cloud were height-normalized by subtracting the z coordinate of the tree position (representing the terrain height at the location of the stem) from all z coordinates in the point cloud.".

I do not know how you read the LAZ files (which library?), but when I load them into CloudCompare they look fine. Just download all LAZ files of a tree and load them to CloudCompare which will enable you to create the figure you were asking to.

Best Bernhard

bhoefle-3dgeo commented 1 year ago

Furthermore in the notbook section of this repository you will also find some useful code, incl. laspy examples: https://github.com/3dgeo-heidelberg/pytreedb/blob/889920fd3bb3cbb3619bc041ec089d3f412298cf/notebooks/08_visualize_and_analyze_data.ipynb

han16nah commented 1 year ago

Dear @ArashJavan Reading the file like in the example notebook that @bhoefle-3dgeo already linked should work well

las = laspy.read(file)
coords = np.vstack((las.x, las.y, las.z)).transpose()

Please check the laspy documentation (https://laspy.readthedocs.io/en/latest/intro.html) for your issue. Here, it states

The dimensions ‘X’, ‘Y’, ‘Z’ are signed integers without the scale and offset applied. To access the coordinates as doubles simply use ‘x’, ‘y’ , ‘z’

I.e., try using las.x, las.y and las.z instead of las.points or las.X, etc.

Furthermore, please note that you can use the coordinates in json["properties"]["measurements"][-1]["position_xyz"] (where json is the tree json file read as Python dictionary) to normalize the point cloud as in moving it to the origin (0,0,0). image

To the code above, you would then simply add:

position_xyz = json["properties"]["measurements"][-1]["position_xyz"]
coords_normalized = coords - position_xyz

We will close this issue, have fun with the data! :)

ArashJavan commented 1 year ago

Thanks a lot!