mreutegg / laszip4j

The LASzip library ported to Java
GNU Lesser General Public License v2.1
34 stars 15 forks source link

Create a las file with the library #3

Closed jabrena closed 1 year ago

jabrena commented 7 years ago

Hi,

with this library, is it possible to create a las file from a data structure?

Many thanks in advance

Juan Antonio

mreutegg commented 7 years ago

No, this is currently not possible. This library is only a partial port of the original laszip library. So far the main focus was on reading existing .las and compressed .laz files.

jabrena commented 7 years ago

If you like, I could help in that issue. I am thinking to create .las / .laz files. If you are interested, I could do some PR.

mreutegg commented 7 years ago

Sure, feel free to give it a try and submit a PR. There are some classes like LASwriterLAS that only exist as skeletons. I didn't port them because so far I was primarily interested in reading .las and .laz files.

jabrena commented 7 years ago

Any las example to try to recreate? I have a RPLidar A1 and I could create a .las/.laz file.

mreutegg commented 7 years ago

Unfortunately the original C++ sources did not have any tests that allowed me to easily validate the ported code. You could try round-tripping existing data, e.g. referenced on laszip.org. The LAStools project also has a few example files.

jabrena commented 7 years ago

Hi @mreutegg,

It is a nice idea. Give me a time, I am debugging a ROS issue, when I finish, we will return to this conversation. We will collaborate.

Cheers

AlexandreBrown commented 1 year ago

Hello @jabrena @mreutegg , we are using the library to read las files and would like to write the las file with new classification values.
Do you think this feature could be implemented in the future?
Cheers

mreutegg commented 1 year ago

Hi Alexandre, I currently don't have plans to work on this feature. This project has a skeleton class LASwriterLAS you would have to implement or port from LAStools/laswriter_las.cpp.

jabrena commented 1 year ago

From my side, currently, I am not working in robotics.

mreutegg commented 1 year ago

@AlexandreBrown, I spent some time implementing/porting the las writer.

See PR https://github.com/mreutegg/laszip4j/pull/73

It's only a start, but reading laz and writing the data into a las file seems to work.

mreutegg commented 1 year ago

@AlexandreBrown, are you reading las files with the read-only API as mentioned in the readme or are you using one of the lower level classes? I'm wondering if the changes in the PR are sufficient for you or additions to the higher level API are necessary.

AlexandreBrown commented 1 year ago

@mreutegg Thank you so much for you work.
Here is how we read a LAS file currently:
image

For writing, our use case is that for each row, we need to write the classification field of a LAS file with a new value.
Ex:
some headers classification rest of headers
...(untouched)... NEW VALUE 1 ...(untouched)...
...(untouched)... NEW VALUE 2 ...(untouched)...
We also might need to support adding a new column/field to the LAS (to keep the existing LAS columns untouched). some headers classification new classification column rest of headers
...(untouched)... INITIAL VALUE 1 (untouched) NEW VALUE 1 ...(untouched)...
...(untouched)... INITIAL VALUE 2 (untouched) NEW VALUE 2 ...(untouched)...

Let me know if you have any questions!

mreutegg commented 1 year ago

Hi @AlexandreBrown

Please have a look at https://github.com/mreutegg/laszip4j/pull/75

For now it just allows re-classification of points, but more modifier methods could be added easily. Does this go into the right direction?

We also might need to support adding a new column/field to the LAS (to keep the existing LAS columns untouched).

Can you be more precise what you mean with column/field? AFAIK point data in LAS files have a fixed set of fields. I'm not aware that you can add more.

AlexandreBrown commented 1 year ago

@mreutegg Yes your PR seem to be exactly what we need in order to set the classification value.

Can you be more precise what you mean with column/field? AFAIK point data in LAS files have a fixed set of fields. I'm not aware that you can add more.

Do you think it would be possible to add a new dimension to the LAS?
Something similar to this (see "Adding Extra Dimensions" section).

In our case it would be used to add a new dimension that stores the new classification values while keeping the existing classification field untouched.

mreutegg commented 1 year ago

OK, I see. The extra dimension information is stored as 'extra bytes' in an extended variable length record (EVLRs). Currently laszip4j only has limited support for EVLRs. You can access them through the LASHeader, but the payload of a EVLR is simply exposed as a ByteBuffer backed by an in-memory byte array. This won't work well for large EVLRs. And then the question is how to write these.

Maybe EVLRs could be defined when a LASWriter is constructed and then populated via the transformer.

AlexandreBrown commented 1 year ago

@mreutegg I see thanks for providing this information.
On my side, we 100% for sure needed to be able to write a las file that we edit the existing classification field but if the second use case (adding a new dimension) is not trivial to add then It's not the end of the world as long as the first use case is supported.

Maybe we can close this issue since you added (very nicely) the support for creating a las file and perhaps extended EVLRs support can be added in another issue.

If it's possible good, if not then hey I understand.

mreutegg commented 1 year ago

Agreed. Though, I was wrong about the extra bytes in EVLRs. Only the metadata of the extra bytes are stored in EVLRs. The actual extra bytes are appended to the point data record. In the original laszip tool this is modeled as attributes on a LAS point. Some of that code has already been ported to laszip4j. But there's still quite some work to do to support writing of extra bytes. So, yes. Let's resolve this issue and create a new one if needed.