How to use laspy - 10 common examples

To help you get started, we’ve selected a few laspy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Oslandia / py3dtiles / py3dtiles / points / task / las_reader.py View on Github external
def run(_id, filename, offset_scale, portion, queue, projection, verbose):
    '''
    Reads points from a las file
    '''
    try:
        f = laspy.file.File(filename, mode='r')

        point_count = portion[1] - portion[0]

        step = min(point_count, max((point_count) // 10, 100000))

        indices = [i for i in range(math.ceil((point_count) / step))]

        color_scale = offset_scale[3]

        file_points = f.get_points()['point']
        X = file_points['X']
        Y = file_points['Y']
        Z = file_points['Z']
        # todo: attributes
        if 'red' in f.point_format.lookup:
            RED = file_points['red']
github strawlab / python-pcl / examples / external / laspy / visualization_test_rgb.py View on Github external
def main():
    # RGB : NG
    # f = file.File('28XXX10000075-18.las', mode='r')
    f = file.File('28W0608011101-1.las', mode='r')
    # f = file.File('28XXX00020001-1.las', mode='r')
    # f = file.File('simple1_4.las', mode='r')

    # check las file version
    # RGB contains
    if f._header.data_format_id in (2, 3, 5):
        red = (f.red)
        green = (f.green)
        blue = (f.blue)
        # 16bit to convert 8bit data(data Storage First 8 bits case)
        red = np.right_shift(red, 8).astype(np.uint8)
        green = np.right_shift(green, 8).astype(np.uint8)
        blue = np.right_shift(blue, 8).astype(np.uint8)
        # (data Storage After 8 bits case)
        # red = red.astype(np.uint8)
        # green = green.astype(np.uint8)
github laspy / laspy / laspytest / test_laspy.py View on Github external
def setUp(self):
        really_copyfile(self.simple, self.tempfile)
        self.File1 = File.File(self.tempfile, mode = "rw")
github chinakook / PointCNN.MX / test_seg.py View on Github external
def save_las(inFilename,outFilename):
    road_file = File.File(inFilename)    
    new_header = copy.copy(road_file.header)
    tmp_File = File.File(outFilename, mode = "w",header=new_header)
    for spec in road_file.reader.point_format:
        # print("Copying dimension: " + spec.name)
        in_spec = road_file.reader.get_dimension(spec.name)
        try:
            tmp_File.writer.set_dimension(spec.name, in_spec)
        except(util.LaspyException):
            print("Couldn't set dimension: " + spec.name +
                    " with file format " + str(tmp_File.header.version) +
                    ", and point_format " + str(tmp_File.header.data_format_id))
    road_file.close()
    return tmp_File
github laspy / laspy / laspytest / test_laspy.py View on Github external
def test_using_barebones_header(self):
        """Testing file creation using barebones header"""
        header_object = header.Header()

        File2 = File.File(self.output_tempfile, mode = "w",
                            header = header_object)
        self.assertTrue(File2.header.version == "1.2")

        X = list(self.File1.X)
        Y = list(self.File1.Y)
        Z = list(self.File1.Z)
        File2.X = X
        File2.Y = Y
        File2.Z = Z
        self.assertTrue((list(X) == list(File2.get_x())))
        self.assertTrue((list(Y) == list(File2.get_y())))
        self.assertTrue((list(Z) == list(File2.get_z())))
        File2.close(ignore_header_changes = True)
github laspy / laspy / laspytest / test_laspy.py View on Github external
def test_vlr_defined_dimensions(self):
        """Testingi multiple v1.4 VLR defined dimensions (LL API)"""
        new_header = self.File1.header.copy()
        # Test basic numeric dimension
        new_dim_record1 = header.ExtraBytesStruct(name = "test dimension 1234", data_type = 5)
        # Test string dimension (len 3)
        new_dim_record2 = header.ExtraBytesStruct(name = "test dimension 5678", data_type = 22)
        # Test integer array dimension (len 3)
        new_dim_record3 = header.ExtraBytesStruct(name = "test dimension 9", data_type =  26)
        new_VLR_rec = header.VLR(user_id = "LASF_Spec", record_id = 4,
            VLR_body = (new_dim_record1.to_byte_string() + new_dim_record2.to_byte_string() + new_dim_record3.to_byte_string()))
        new_header.data_record_length += (19)
        File2 = File.File(self.output_tempfile, mode = "w", header = new_header, 
                vlrs = [new_VLR_rec], evlrs = self.File1.header.evlrs)

        File2.X = self.File1.X

        File2._writer.set_dimension("test_dimension_1234", [4]*len(self.File1))
        File2._writer.set_dimension("test_dimension_5678", ["AAA"]*len(self.File1))
        File2._writer.set_dimension("test_dimension_9", [[1,2,3]]*len(self.File1))
        self.assertTrue(all(np.array([4]*len(self.File1)) == File2.test_dimension_1234))
        self.assertTrue(all(np.array([b"AAA"]*len(self.File1)) == File2.test_dimension_5678))
        self.assertEqual(list(File2.test_dimension_9[100]), [1,2,3])
        File2.close(ignore_header_changes = True)
github chinakook / PointCNN.MX / test_seg.py View on Github external
#      & ((af[:,0] < -1.5)  | (af[:,0] > 0.5) | (af[:,1] < -2.5) | (af[:,1] > -0.5) | (af[:,2] < -0.5) | (af[:,2] > 0.5)))

    # print af.shape[0],bound.sum()
    # keep_points = bound
    
    new_header = copy.copy(l.header)
    tmp_las = outfile
    w_las = resfle
    
    w =  File.File(w_las,mode = "w",header=new_header)
    for spec in l.reader.point_format:
    # print("Copying dimension: " + spec.name)
        in_spec = l.reader.get_dimension(spec.name)
        try:
            w.writer.set_dimension(spec.name, in_spec)
        except(util.LaspyException):
            print("Couldn't set dimension: " + spec.name +
                    " with file format " + str(w.header.version) +
                    ", and point_format " + str(w.header.data_format_id))
    w.close()
    #################################### save_rect #################################################
    if(save_rect):
        n = File.File(tmp_las,mode = "w",header=new_header)
        points_kept = l.points
        n.points = points_kept

        # n.X = af[:,0] / l.header.scale[0] + offset[0] 
        # n.Y = af[:,1] / l.header.scale[1] + offset[1] 
        # n.Z = af[:,2] / l.header.scale[2] + offset[2]
        
        n.X = af[:,0] / l.header.scale[0] 
        n.Y = af[:,1] / l.header.scale[1]
github laspy / laspy / laspytest / test_laspy.py View on Github external
def test_software_id(self):
        """"Testing Software ID"""
        s1 = self.FileObject.header.software_id
        s1 = "1234567" + s1[7:]
        self.FileObject.header.software_id = s1
        s2 = self.FileObject.header.get_softwareid()
        self.assertEqual(s1, s2)
        with self.assertRaises(laspy.util.LaspyException):
            self.FileObject.header.software_id = "123"
        with self.assertRaises(laspy.util.LaspyException):
            self.FileObject.header.software_id = "1" * 100
    def test_padding(self):
github laspy / laspy / laspytest / test_laspy.py View on Github external
from laspy.util import edim_fmt_dict, fmtLen, LEfmt,defaults,defaults_test

        for dfList in [defaults, defaults_test]:

            for i in range(1,31):
                print("...data format: "+ str(i))
                # Create a new header
                new_header = self.File1.header.copy()
                # Create new dimension
                dimname = "test_dimension_" + str(i)
                new_dimension = header.ExtraBytesStruct(
                    name = dimname, data_type = i) 
                # Collect bytes for new dimension specification 
                new_dim_raw = new_dimension.to_byte_string() 
                # Create a VLR defining our new dim
                new_VLR_rec = header.VLR(user_id = "LASF_Spec", record_id = 4,
                    description = "Testing Extra Bytes.",
                    VLR_body = (new_dim_raw))

                # Figure out how much we need to pad the point records
                new_dim_fmt = edim_fmt_dict[i]
                new_dim_num = new_dim_fmt[1]
                new_dim_bytelen = fmtLen[LEfmt[new_dim_fmt[0]]]
                new_total_bytes = new_dim_bytelen*new_dim_num 

                new_header.data_record_length += (new_total_bytes)

                File2 = File.File(self.output_tempfile, mode = "w", header = new_header, 
                    vlrs = [new_VLR_rec], evlrs = self.File1.header.evlrs)
    
                File2.X = self.File1.X
github laspy / laspy / laspytest / test_laspy.py View on Github external
def test_vlr_defined_dimensions(self):
        """Testingi multiple v1.4 VLR defined dimensions (LL API)"""
        new_header = self.File1.header.copy()
        # Test basic numeric dimension
        new_dim_record1 = header.ExtraBytesStruct(name = "test dimension 1234", data_type = 5)
        # Test string dimension (len 3)
        new_dim_record2 = header.ExtraBytesStruct(name = "test dimension 5678", data_type = 22)
        # Test integer array dimension (len 3)
        new_dim_record3 = header.ExtraBytesStruct(name = "test dimension 9", data_type =  26)
        new_VLR_rec = header.VLR(user_id = "LASF_Spec", record_id = 4,
            VLR_body = (new_dim_record1.to_byte_string() + new_dim_record2.to_byte_string() + new_dim_record3.to_byte_string()))
        new_header.data_record_length += (19)
        File2 = File.File(self.output_tempfile, mode = "w", header = new_header, 
                vlrs = [new_VLR_rec], evlrs = self.File1.header.evlrs)

        File2.X = self.File1.X

        File2._writer.set_dimension("test_dimension_1234", [4]*len(self.File1))
        File2._writer.set_dimension("test_dimension_5678", ["AAA"]*len(self.File1))
        File2._writer.set_dimension("test_dimension_9", [[1,2,3]]*len(self.File1))
        self.assertTrue(all(np.array([4]*len(self.File1)) == File2.test_dimension_1234))
        self.assertTrue(all(np.array([b"AAA"]*len(self.File1)) == File2.test_dimension_5678))
        self.assertEqual(list(File2.test_dimension_9[100]), [1,2,3])
        File2.close(ignore_header_changes = True)