Permalink
Browse files

incomplete: fix complex extra dimension formats

  • Loading branch information...
grantbrown committed Jul 9, 2012
1 parent d9aea60 commit 308670836b502c8df59dce548dfe7d0713d95a0a
Showing with 29 additions and 4 deletions.
  1. +11 −4 laspy/util.py
  2. +18 −0 laspytest/test_laspy.py
View
@@ -17,7 +17,7 @@ class LaspyException(Exception):
LEfmt = {"ctypes.c_long":"<l","ctypes.c_ulong":"<L", "ctypes.c_ushort":"<H", "ctypes.c_ubyte":"<B"
,"ctypes.c_float":"<f", "ctypes.c_char":"<s", "ctypes.c_double":"<d", "ctypes.c_ulonglong":"<Q",
"ctypes.c_short":"<h"}
-npFmt = {"<l":"i4", "<L":"u4", "<h":"i2","<H":"u2", "<B":"u1", "<f":"f4", "<s":"s1", "<d":"f8", "<Q":"u8"}
+npFmt = {"<l":"i4", "<L":"u4", "<h":"i2","<H":"u2", "<B":"u1", "<f":"f4", "<s":"S1", "<d":"f8", "<Q":"u8"}
defaults = {"<L":0,"<l":0, "<H":0, "<h":0, "<B": "0", "<f":0.0, "<s":" ", "<d":0.0, "<Q":0}
@@ -70,9 +70,16 @@ def __init__(self,name,offs, fmt, num, pack = False,ltl_endian = True, overwrita
self.length = fmtLen[self.fmt]
self.pack = pack
self.np_fmt = npFmt[self.fmt]
- if self.fmt == "<B" and num > 1:
- self.np_fmt = "V" + str(num)
-
+ # Check if we need to do anything special to the numpy format
+ if self.num > 1:
+ if self.fmt == "<s":
+ self.np_fmt = "S"+str(self.num)
+ elif self.fmt == "<B":
+ self.np_fmt = "V" + str(num)
+
+ else:
+ ## We need a sub-array
+ self.np_fmt = str(self.num) + npFmt[self.fmt]
if self.num == 1 or type(defaults[self.fmt])== str:
self.default = defaults[self.fmt]*self.num
else:
View
@@ -666,6 +666,24 @@ def tearDown(self):
self.File1.close()
os.remove(self.tempfile)
+ def test_vlr_defined_dimensions(self):
+ new_header = self.File1.header.copy()
+ new_dim_record1 = header.ExtraBytesStruct(name = "Test Dimension 1234", data_type = 5)
+ new_dim_record2 = header.ExtraBytesStruct(name = "Test Dimension 5678", data_type = 22)
+ 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_header.data_record_length += 7
+ 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
+ import pdb; pdb.set_trace()
+
+ File2._writer.set_dimension("test_dimension_1234", [4]*len(self.File1))
+ File2._writer.set_dimension("test_dimension_5678", ["AAA"]*len(self.File1))
+ self.assertTrue(all(np.array(["AAA"]*len(self.File1)) == File2.test_dimension_5678))
+ self.assertTrue(all(np.array([4]*len(self.File1)) == File2.test_dimension_1234))
+
+ File2.close(ignore_header_changes = True)
def test_laspy():

0 comments on commit 3086708

Please sign in to comment.