How to use the laspy.util 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 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 / laspy / tools / lascopy.py View on Github external
## Build the new header, check if we need to do anythin special. This includes:
        ## 1. Check if there are extra dimensions defined which we need to copy.
        ## 2. Check if we need to get rid of some/all EVLRs for the output file_version
        ## 3. See if we need to re-map legacy fields for 1.4 files.
        try:
            new_header = inFile.header.copy()
            new_header.format = file_version 
            new_header.data_format_id = point_format

            old_data_rec_len = new_header.data_record_length
            old_std_rec_len = laspy.util.Format(old_point_format).rec_len
            diff =   old_data_rec_len - old_std_rec_len
            if (diff > 0):
                print("Extra Bytes Detected.")

            new_header.data_record_length = laspy.util.Format(point_format).rec_len + ((diff > 0)*diff)
            evlrs = inFile.header.evlrs
            if file_version != "1.4" and old_file_version == "1.4":
                print("Warning: input file has version 1.4, and output file does not. This may cause truncation of header data.")
                new_header.point_return_count = inFile.header.legacy_point_return_count
                new_header.point_records_count = inFile.header.legacy_point_records_count
            if not (file_version in ["1.3", "1.4"]) and old_file_version in ["1.3", "1.4"]:
                print("Stripping any EVLRs")
                evlrs = []
            if (file_version == "1.3" and len(inFile.header.evlrs) > 1):
                print("Too many EVLRs for format 1.3, keeping the first one.")
                evlrs = inFile.header.evlrs[0]
            outFile = laspy.file.File(self.args.out_file[0], header = new_header, mode = "w", vlrs = inFile.header.vlrs, evlrs = evlrs)
            if outFile.point_format.rec_len != outFile.header.data_record_length:
                pass
        except Exception as error:
            print("There was an error instantiating the output file.")
github laspy / laspy / laspy / header.py View on Github external
def __init__(self, file_version = 1.2, point_format = 0, **kwargs):
        # At least generate a default las format
        fmt = util.Format("h" + str(file_version))
        kwargs["version_major"] = str(file_version)[0]
        kwargs["version_minor"] = str(file_version)[2]
        kwargs["data_format_id"] = point_format
        self._format = fmt
        for dim in self._format.specs:
            if dim.name in kwargs.keys():
                self.__dict__[dim.name] = kwargs[dim.name]
            else:
                self.__dict__[dim.name] = dim.default
        self.file_sig = "LASF"
github laspy / laspy / laspy / file.py View on Github external
self._evlrs = evlrs

            self._writer = base.Writer(self.filename, mode = "w",
                                      header = self._header, 
                                      vlrs = self._vlrs, evlrs = self._evlrs)
            self._reader = self._writer
            ## Wire up API for any extra Dimensions
            if self._writer.extra_dimensions != []:
                for dimension in self._writer.extra_dimensions:
                    dimname = dimension.name.decode().replace("\x00", "").replace(" ", "_").lower()
                    self.addProperty(dimname) 

        elif self._mode == 'w+':
            raise NotImplementedError
        else:
            raise util.LaspyException("Mode %s not supported" % self._mode)

        if self._reader.compressed and self._mode not in ("r", "r-"):
            raise NotImplementedError("Compressed files / buffer objects can only be opened in mode 'r' for now")
github laspy / laspy / laspy / header.py View on Github external
def parse_data(self):
        '''Attempt to read VLR or EVLR body into the parsed_body attribute.'''
 
        if "LASF_Projection" in self.user_id and self.record_id == 2111:
            # OGC Math Transform WKT Record
            self.body_fmt = util.Format(None)
            self.body_fmt.add("ogc_math_transform", "ctypes.c_char", self.rec_len_after_header)

        elif "LASF_Projection" in self.user_id and self.record_id == 2112:
            # OGC Coordinate System WKT
            self.body_fmt = util.Format(None)
            self.body_fmt.add("coordinate_system_wkt", "ctypes.c_char", self.rec_len_after_header)

        elif "LASF_Projection" in self.user_id and self.record_id == 34735:
            # GeoKeyDictionaryTag Record
            self.body_fmt = util.Format(None)
            self.body_fmt.add("wKeyDirectoryVersion", "ctypes.c_ushort", 1)
            self.body_fmt.add("wKeyRevision", "ctypes.c_ushort", 1)
            self.body_fmt.add("wMinorRevision", "ctypes.c_ushort", 1)
            self.body_fmt.add("wNumberOfKeys", "ctypes.c_ushort", 1)   
            # Rest is made up of arrays of 4 unsigned shorts. 
            bytes_left = (self.rec_len_after_header - 4*2)
github laspy / laspy / laspy / base.py View on Github external
def get_overlap(self):
        if self.header.data_format_id in (6,7,8,9,10):
            return self.bit_transform(self.get_raw_classification_flags(), 3, 4)
        else:
            raise laspy.util.LaspyException("Overlap only present in point formats > 5.")
github laspy / laspy / laspy / header.py View on Github external
for i in xrange(int(self.rec_len_after_header / 257)):
                self.body_fmt.add("FileMarkerNumber_%i", "ctypes.c_ubyte", 1)
                self.body_fmt.add("Filename_%i", "ctypes.c_char", 256)

        elif "LASF_Spec" in self.user_id and self.record_id == 3:
            #Text Area Description
            self.body_fmt = util.Format(None)
            self.body_fmt.add("text_area_description", "ctypes.c_char", self.rec_len_after_header)

        elif "LASF_Spec" in self.user_id and self.record_id == 4:
            # Extra Bytes, currently handled by VLR constructor
            pass

        elif "LASF_Spec" in self.user_id and self.record_id > 99 and self.record_id < 355:
            # WAVEFORM PACKET DESCRIPTOR
            self.body_fmt = util.Format(None)
            self.body_fmt.add("bits_per_sample", "ctypes.c_ubyte",1)
            self.body_fmt.add("waveform_compression_type", "ctypes.c_ubyte",1)
            self.body_fmt.add("number_of_samples", "ctypes.c_ulong",1)
            self.body_fmt.add("temporal_time_spacing", "ctypes.c_ulong",1)
            self.body_fmt.add("digitizer_gain", "ctypes.c_double",1)
            self.body_fmt.add("digitizer_offset", "ctypes.c_double",1)

        if self.body_fmt != None:
            self.parsed_body = struct.unpack(self.body_fmt.pt_fmt_long, self.VLR_body)
        else:
            self.parsed_body = None