From b751d3de45946611a0a8d20ec6f288670a9cc8b1 Mon Sep 17 00:00:00 2001 From: brycefrank Date: Sun, 12 Feb 2017 15:56:08 -0800 Subject: [PATCH 1/3] Changed struct function to check for already converted values.: --- laspy/header.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/laspy/header.py b/laspy/header.py index 34e64b1f..4c472874 100644 --- a/laspy/header.py +++ b/laspy/header.py @@ -52,7 +52,7 @@ def parse_data(self): print("WARNING: Invalid body length for GeoKeyDictionaryTag, Not parsing.") self.body_fmt = None return - for sKeyEntry in xrange(bytes_left/8): + for sKeyEntry in xrange(int(bytes_left/8)): # Added integer argument self.body_fmt.add("wKeyId_%i" % sKeyEntry, "ctypes.c_ushort", 1) self.body_fmt.add("wTIFFTagLocation_%i" % sKeyEntry, "ctypes.c_ushort", 1) self.body_fmt.add("wCount_%i" % sKeyEntry, "ctypes.c_ushort", 1) @@ -464,22 +464,24 @@ def __len__(self): '''Return the size of the vlr object in bytes''' return self.rec_len_after_header + 54 - def pack(self, name, val): - '''Pack a VLR field into bytes.''' + def pack(self, name, val): spec = self.fmt.lookup[name] + if type(val)== bytes: + return val if spec.num == 1: return(struct.pack(spec.fmt, val)) - return(struct.pack(spec.fmt[0]+spec.fmt[1]*len(val), *val)) + a = struct.pack(spec.fmt[0]+spec.fmt[1]*len(val)) + return(a) def to_byte_string(self): '''Pack the entire VLR into a byte string.''' if type(self.parsed_body) != type(None): self.pack_data() - out = (self.pack("reserved", self.reserved) + - self.pack("user_id", self.user_id) + - self.pack("record_id", self.record_id) + - self.pack("rec_len_after_header", self.rec_len_after_header) + - self.pack("description", self.description) + + out = (self.pack("reserved", self.reserved) + + self.pack("user_id", self.user_id.encode()) + + self.pack("record_id", self.record_id) + + self.pack("rec_len_after_header", self.rec_len_after_header) + + self.pack("description", self.description.encode()) + self.VLR_body) diff = (self.rec_len_after_header - len(self.VLR_body)) if diff > 0: From 07d772e170629f4d2bb5d4521617f7667b54692f Mon Sep 17 00:00:00 2001 From: brycefrank Date: Sun, 12 Feb 2017 16:04:53 -0800 Subject: [PATCH 2/3] Removed a couple of unnecessary changes. --- laspy/header.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/laspy/header.py b/laspy/header.py index 4c472874..a827fdb6 100644 --- a/laspy/header.py +++ b/laspy/header.py @@ -52,7 +52,7 @@ def parse_data(self): print("WARNING: Invalid body length for GeoKeyDictionaryTag, Not parsing.") self.body_fmt = None return - for sKeyEntry in xrange(int(bytes_left/8)): # Added integer argument + for sKeyEntry in xrange(bytes_left/8): self.body_fmt.add("wKeyId_%i" % sKeyEntry, "ctypes.c_ushort", 1) self.body_fmt.add("wTIFFTagLocation_%i" % sKeyEntry, "ctypes.c_ushort", 1) self.body_fmt.add("wCount_%i" % sKeyEntry, "ctypes.c_ushort", 1) @@ -470,18 +470,17 @@ def pack(self, name, val): return val if spec.num == 1: return(struct.pack(spec.fmt, val)) - a = struct.pack(spec.fmt[0]+spec.fmt[1]*len(val)) - return(a) + return(spec.fmt[0]+spec.fmt[1]*len(val)) def to_byte_string(self): '''Pack the entire VLR into a byte string.''' if type(self.parsed_body) != type(None): self.pack_data() out = (self.pack("reserved", self.reserved) + - self.pack("user_id", self.user_id.encode()) + + self.pack("user_id", self.user_id) + self.pack("record_id", self.record_id) + self.pack("rec_len_after_header", self.rec_len_after_header) + - self.pack("description", self.description.encode()) + + self.pack("description", self.description) + self.VLR_body) diff = (self.rec_len_after_header - len(self.VLR_body)) if diff > 0: From 0d9b7d6ec14b24db6cc07526fb5588579aa9ec3a Mon Sep 17 00:00:00 2001 From: brycefrank Date: Sun, 12 Feb 2017 16:07:15 -0800 Subject: [PATCH 3/3] Removed a couple of unnecessary changes. --- laspy/header.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laspy/header.py b/laspy/header.py index a827fdb6..d634447e 100644 --- a/laspy/header.py +++ b/laspy/header.py @@ -470,7 +470,7 @@ def pack(self, name, val): return val if spec.num == 1: return(struct.pack(spec.fmt, val)) - return(spec.fmt[0]+spec.fmt[1]*len(val)) + return(struct.pack(spec.fmt[0]+spec.fmt[1]*len(val))) def to_byte_string(self): '''Pack the entire VLR into a byte string.'''