1

I am trying to change the classification of all points in my las file above a certain height (z value) from 2 (ground) to 1 (unclassified). I wrote the following code to do this:

las = laspy.read("filtered plots/plot_37.las")
height_threshold = 333  # Replace with your desired Z value threshold

# Loop through the points, check their classification and height, and modify as needed
for point in las:
    if point.classification == 2 and point.z > height_threshold:
        point.classification = 1
        
las.write('plot_37.las')

However, upon reaching the line "point.classification = 1", I get the following error:

TypeError: object of type 'int' has no len()

I do not understand why the code is trying to check length instead of simply reassigning the value of the classification field. How can I find a solution?

1 Answer 1

0

You need to use the numpy index syntax to this, not a loop :

import laspy
las = laspy.read("filtered plots/plot_37.las") 
height_threshold = 333

# Classification set to "1" if the Z coord > height_threshold and classification = 2
las.classification[(las.z > height_threshold) & (las.classification == 2)] = 1

las.write('plot_37.las')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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