How to use the laspy.header.VLR function in laspy

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 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)
github laempy / pyoints / pyoints / storage / LasHandler.py View on Github external
if 'liblas' in sys.modules:
        # use liblas to create spatial reference
        srs = liblas.srs.SRS()
        srs.set_wkt(str.encode(geoRecords.proj.wkt))
        for i in range(srs.vlr_count()):
            vlr = laspy.header.VLR(
                user_id="LASF_Projection",
                record_id=srs.GetVLR(i).recordid,
                VLR_body=srs.GetVLR(i).data,
                description="OGC Coordinate System GeoTIFF"
            )
            vlr.parse_data()
            vlrs.append(vlr)
    else:
        # create wkt record only
        vlr = laspy.header.VLR(
            user_id="LASF_Projection",
            record_id=2112,
            VLR_body=str.encode(geoRecords.proj.wkt),
            description="OGC Coordinate System WKT"
        )
        vlrs.append(vlr)

    # set VLRs
    lasFile.header.set_vlrs(vlrs)

    if point_format > 5:
        lasFile.header.wkt = 1

    dim = min(geoRecords.dim, 3)

    # find optimal offset and scale scale to achieve highest precision
github icesat-2UT / PhoREAL / source_code / icesatIO.py View on Github external
def writeLas(xx,yy,zz,proj,output_file,classification,intensity,signalConf=None,hemi=None,zone=None):
    wkt = selectwkt(proj,hemi,zone)
    
    #Create new VLR
    new_vlr = laspy.header.VLR(user_id = "LASF_Projection",
                           record_id = 2112,
                           VLR_body = wkt,
                           description = "OGC Coordinate System WKT")
    inVLRs = []
    inVLRs.append(new_vlr)

    #Create new Header
    hdr = laspy.header.Header(file_versoin=1.4 )
    hdr.file_sig = 'LASF'
    
    #Create new las file with Header and VLR  
    outfile = laspy.file.File(output_file, mode="w", header=hdr)
    outfile.header.vlrs = inVLRs
    outfile.header.set_wkt = 1
    
    #Establish offset
github laempy / pyoints / pyoints / storage / LasHandler.py View on Github external
# Create file header
    header = laspy.header.Header(file_version=1.3, point_format=point_format)
    header.file_sig = 'LASF'

    # Open file in write mode
    lasFile = laspy.file.File(outfile, mode='w', header=header)

    # create VLR records
    vlrs = []
    if 'liblas' in sys.modules:
        # use liblas to create spatial reference
        srs = liblas.srs.SRS()
        srs.set_wkt(str.encode(geoRecords.proj.wkt))
        for i in range(srs.vlr_count()):
            vlr = laspy.header.VLR(
                user_id="LASF_Projection",
                record_id=srs.GetVLR(i).recordid,
                VLR_body=srs.GetVLR(i).data,
                description="OGC Coordinate System GeoTIFF"
            )
            vlr.parse_data()
            vlrs.append(vlr)
    else:
        # create wkt record only
        vlr = laspy.header.VLR(
            user_id="LASF_Projection",
            record_id=2112,
            VLR_body=str.encode(geoRecords.proj.wkt),
            description="OGC Coordinate System WKT"
        )
        vlrs.append(vlr)
github laspy / laspy / laspy / base.py View on Github external
def populate_vlrs(self):
        '''Catalogue the variable length records'''
        self.vlrs = []
        self.seek(self.header.header_size, rel = False)
        for i in xrange(self.get_header_property("num_variable_len_recs")):
            new_vlr = laspy.header.VLR(None, None, None)
            new_vlr.build_from_reader(self)
            self.vlrs.append(new_vlr)
            if self.data_provider._mmap.tell() > self.header.data_offset:
                self.seek(self.header.data_offset, rel = False)
                raise laspy.util.LaspyException("Error, Calculated Header Data "
                    "Overlaps The Point Records!")
        self.vlr_stop = self.data_provider._mmap.tell()
        return