2

I need to add classification to create a LAS file. I used the code below but it was miss-classified. Is there any problem with the code? And what is the difference between:

out.file classification 

and

 outfile.Raw_Classification

      hdr = laspy.header.Header()
      outfile = laspy.file.File("output.las", mode="w", header=hdr)
      allx = scanne[:,0] 
      ally = scanne[:,1]
      allz = scanne[:,2]

      xmin =np.min(allx)
      ymin =np.min(ally)
      zmin =np.min(allz)

      outfile.header.offset = [xmin,ymin,zmin]
      outfile.header.scale = [0.001,0.001,0.001]
      outfile.x = allx
      outfile.y = ally
      outfile.z = allz
      outfile.Raw_Classification  = scanne[:,3]
      print(hdr)
      outfile.close()
1

LAS 1.2 has a classification byte, which is 8 bits. However 3 of those bits are used for the flags (withheld, synthetic, and keypoint).

With laspy, classification accesses the 5 bits that LAS 1.2 allows for the classification number. 2^5 is 32, meaning you can store 32 classes (0-31) in that 5-bit integer. It doesn't touch the flag bits.

raw_classification gives no special handling to the flag bits and instead accesses all 8 of the bits, treating it as an 8-bit integer. This would let you store a number above 31 in this byte field (2^8 == 256, 0-255), but it also uses those flag bits to do so. The implication is that softwares that actually follow the spec will only read the 5 bits that the spec defines when determining the classification, giving you a different number.

Read through the spec, especially page 8 to understand this better:

https://www.asprs.org/wp-content/uploads/2010/12/asprs_las_format_v12.pdf

  • H i thank you for the response. but when i try classification, I got the error Laspy Exception: Invalid Data: Packed Length is Greater than allowed. how can i fix this – user77540 Sep 5 at 20:27
  • Sounds like you might be trying to set values >31. As above, that's not allowed if you want wide compatibility with LAS 1.2 files between software packages. – mikewatt Sep 5 at 20:59
  • In fact i am dealing with 22 classes, the labels type is uint32 and the data is float32. – user77540 Sep 5 at 22:19
  • Try converting to uint8? labels.astype(np.uint8) – mikewatt Sep 5 at 22:35
  • I got the same error : LaspyException: Invalid Data: Packed Length is Greater than allowed. – user77540 Sep 7 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.