Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reclassification of a COPC file #277

Open
fabiopicchi opened this issue Jun 15, 2023 · 5 comments
Open

Reclassification of a COPC file #277

fabiopicchi opened this issue Jun 15, 2023 · 5 comments

Comments

@fabiopicchi
Copy link
Contributor

We currently have a process that classifies points and we're using laspy to read the unclassified input and write the classified output. However, if the input has the COPC vlr an exception is raised when trying to write the output because laspy doesn't support COPC writing as of now.

I was wondering if there would be a laspy workaround in this case or if we'll have to read the header bytes and write the output bytes without using the library. As we're not touching the file geometry or the pointformat, the COPC blob should still be valid.

@hobu
Copy link
Contributor

hobu commented Jun 15, 2023

As we're not touching the file geometry or the pointformat, the COPC blob should still be valid.

COPC is both

  • The COPC VLR
  • AND the LAZ chunks being written in accordance with the COPC VLR

You will need to strip off the COPC VLR, write a new LAS file, and then use PDAL or Untwine or something to convert that back to COPC. There's no clean in-place editing software that speaks COPC as far as I know.

@fabiopicchi
Copy link
Contributor Author

Ahhh, thanks @hobu, I wasn't aware of that 👍

@fabiopicchi
Copy link
Contributor Author

fabiopicchi commented Jun 15, 2023

I guess I'll leave it open just for @tmontaigu to take a look. Maybe we could plan COPC in-place editing for laspy.

@hobu
Copy link
Contributor

hobu commented Jun 15, 2023

Maybe we could plan COPC in-place editing for laspy.

It would be tough to do correctly. The problem is any change to any attribute of a point has the potential to ultimately change the compressed size of the chunk that point belongs to. That means updating the chunk, the chunk table, and the COPC vlr that points into both of those.

For editing, it is much better to use an uncompressed data structure you can simply mmap onto disk. Then make all of your edits as you need, and then roll it up into COPC or EPT or LAS whatever after you know you're done.

@tmontaigu
Copy link
Member

tmontaigu commented Jun 18, 2023

As hobu said, in place editing is tough to do correctly and would propably end up less efficient than some could expect

Imagine you do a query on a COPC, you change some values (other than x,y,z) and want to write them back, now the points have to be matched back to the original file (not so hard)

However, the writer will have to rewrite the chunks in which the modified points belongs, the compressed LAZ chunk size in bytes is likely not going to be the same it was originally.
If its smaller maybe we can afford to zero out the left over bytes and be good, howerver, it the chunk size if bigger it will trigger the need 'move' (so read + write bytes) all of the succeeding chunks.

Worst case scenario is that one (or more) of your modified points were in the first chunk and they make the new compressed size bigger -> all chunks in the file will need to be moved.

For unmodified chunk they can be moved by readin byte then redumping them (ie no need to decompress+recompress) its still
additional work, for modified chunks a full decompress + recompress is needed.
Also correct bookkeeping of the COPC VLR will need to be made.

So while its theorically not impossible to achieve, the 'update' is still a certain amount of work (certainly more work than one could think, if he does not know/forgets that COPC is 'just' a LAZ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants