How to use the laspy.header.ExtraBytesStruct 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
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 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))
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])
github laspy / laspy / laspy / base.py View on Github external
def define_new_dimension(self,name, data_type,description = ""):
        old_vlrs = self.vlrs
        if self.has_point_records or not self.mode == "w":
            raise laspy.util.LaspyException("New dimensions may be defined only for write mode files which do not yet possess point records.")
        eb_vlrs = [x for x in self.vlrs if x.type == 1]
        if self.header.version == "1.4":
            eb_evlrs =  [x for x in self.evlrs if x.type == 1]
            old_evlrs = self.evlrs
        else:
            eb_evlrs = []
            old_evlrs = []

        if ("extra_bytes" in self.point_format.lookup) and (len(eb_vlrs) != 0):
            raise laspy.util.LaspyException("Adding a dimension is ambiguous when there are already extra bytes in the point records, but no VLR describing them.")
        new_dimension = laspy.header.ExtraBytesStruct(name = name, data_type = data_type, description = description)
        if len(eb_vlrs) + len(eb_evlrs) > 1:
            raise laspy.util.LaspyException("Only one ExtraBytes VLR currently allowed.")
        elif len(eb_vlrs) + len(eb_evlrs) == 1:
            if len(eb_vlrs) == 1:
                extra_dimensions = eb_vlrs[0].extra_dimensions
                extra_dimensions.append(new_dimension)
                self.extra_dimensions = extra_dimensions
                new_pt_fmt = laspy.util.Format(self.point_format.fmt, extradims
                             = extra_dimensions)
                self.point_format = new_pt_fmt
                self.set_header_property("data_record_length", self.point_format.rec_len)

                eb_vlr_index = [x for x in range(len(self.vlrs)) if self.vlrs[x].type == 1][0]
                new_vlr = copy.copy(eb_vlrs[0])
                nvlrbs = new_dimension.to_byte_string()
                new_vlr.VLR_body += nvlrbs
github laspy / laspy / laspy / header.py View on Github external
def setup_extra_bytes_spec(self, VLR_body):
        self.type = 1
        self.extra_dimensions = []
        if self.rec_len_after_header % 192 != 0:
            raise util.LaspyException("""Invalid record length for extra bytes
                                     specification, must be multiple of 192.""")
        else:
            recs = self.rec_len_after_header / 192
            for i in xrange(int(recs)):
                new_rec = ExtraBytesStruct()
                new_rec.build_from_vlr(self, i)
                self.add_extra_dim(new_rec)
github laspy / laspy / laspy / header.py View on Github external
def setup_extra_bytes_spec(self, VLR_body):
        self.type = 1
        self.extra_dimensions = []
        if self.rec_len_after_header % 192 != 0:
            raise util.LaspyException("""Invalid record length for extra bytes
                                     specification, must be multiple of 192.""")
        else:
            recs = self.rec_len_after_header / 192
            for i in xrange(recs):
                new_rec = ExtraBytesStruct()
                new_rec.build_from_vlr(self, i)
            self.add_extra_dim(new_rec)