[Liblas-commits] hg: support setting the raw data via python #237

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Jun 23 16:52:30 EDT 2011


details:   http://hg.liblas.orghg/rev/193fe2fc0028
changeset: 3012:193fe2fc0028
user:      Howard Butler <hobu.inc at gmail.com>
date:      Thu Jun 23 15:52:24 2011 -0500
description:
support setting the raw data via python #237

diffstat:

 python/liblas/core.py  |  20 ++++++-------
 python/liblas/point.py |  72 +++++++++++--------------------------------------
 2 files changed, 25 insertions(+), 67 deletions(-)

diffs (110 lines):

diff -r 4c54e0703399 -r 193fe2fc0028 python/liblas/core.py
--- a/python/liblas/core.py	Thu Jun 23 15:30:31 2011 -0500
+++ b/python/liblas/core.py	Thu Jun 23 15:52:24 2011 -0500
@@ -341,17 +341,15 @@
 las.LASPoint_GetXML.argtypes = [ctypes.c_void_p]
 las.LASPoint_GetXML.errcheck = free_returned_char_p
 
-# las.LASPoint_GetExtraData.argtypes = [ctypes.c_void_p,
-#                             ctypes.POINTER(ctypes.POINTER(ctypes.c_ubyte)),
-#                             ctypes.POINTER(ctypes.c_int)]
-# las.LASPoint_GetExtraData.errcheck = check_value
-# las.LASPoint_GetExtraData.restype = ctypes.c_int
-# 
-# las.LASPoint_SetExtraData.argtypes = [ctypes.c_void_p,
-#                                         ctypes.POINTER(ctypes.c_ubyte),
-#                                         ctypes.c_int]
-# las.LASPoint_SetExtraData.errcheck = check_value
-# las.LASPoint_SetExtraData.restype = ctypes.c_int
+las.LASPoint_GetData.argtypes = [ctypes.c_void_p,
+                            ctypes.POINTER(ctypes.c_ubyte)]
+las.LASPoint_GetData.errcheck = check_value
+las.LASPoint_GetData.restype = ctypes.c_int
+
+las.LASPoint_SetData.argtypes = [ctypes.c_void_p,
+                                        ctypes.POINTER(ctypes.c_ubyte)]
+las.LASPoint_SetData.errcheck = check_value
+las.LASPoint_SetData.restype = ctypes.c_int
 
 las.LASPoint_Create.restype = ctypes.c_void_p
 las.LASPoint_Create.errcheck = check_void
diff -r 4c54e0703399 -r 193fe2fc0028 python/liblas/point.py
--- a/python/liblas/point.py	Thu Jun 23 15:30:31 2011 -0500
+++ b/python/liblas/point.py	Thu Jun 23 15:52:24 2011 -0500
@@ -554,60 +554,20 @@
         return core.las.LASPoint_GetXML(self.handle)
         
     xml = property(get_xml, None, None, None)
+
+
+    def get_data(self):
+        length = self.header.data_record_length
+        d = (ctypes.c_ubyte*length)()
+        d2 = ctypes.cast(d, ctypes.POINTER(ctypes.c_ubyte))
+        core.las.LASPoint_GetData(self.handle, d2)
+        return d
     
-    # def descale(self, header):
-    #     """Descales the point with a given :obj:`liblas.header.Header` instance
-    # 
-    #     :param header: A header with :obj:`liblas.header.Header.offset` and \
-    #                    :obj:`liblas.header.Header.scale` values set"""
-    #     self.x = (self.x - header.offset[0]) / header.scale[0]
-    #     self.y = (self.y - header.offset[1]) / header.scale[1]
-    #     self.z = (self.z - header.offset[2]) / header.scale[2]
-    # 
-    # def scale(self, header):
-    #     """Scales the point with a given :obj:`liblas.header.Header` instance
-    # 
-    #     :param header: A header with :obj:`liblas.header.Header.offset` and \
-    #                    :obj:`liblas.header.Header.scale` values set"""
-    #     self.x = (self.x * header.scale[0]) + header.offset[0]
-    #     self.y = (self.y * header.scale[1]) + header.offset[1]
-    #     self.z = (self.z * header.scale[2]) + header.offset[2]
-
-    # def get_data(self):
-    #     l = ctypes.pointer(ctypes.c_int())
-    #     d = ctypes.pointer(ctypes.c_ubyte())
-    #     core.las.LASPoint_GetExtraData(self.handle, ctypes.byref(d), l)
-    # 
-    #     d2 = ctypes.cast(d, ctypes.POINTER(ctypes.c_ubyte * l.contents.value))
-    #     s = (ctypes.c_ubyte * l.contents.value)()
-    #     for i in range(l.contents.value):
-    #         s[i] = d2.contents[i]
-    #     p_d = ctypes.cast(d, ctypes.POINTER(ctypes.c_char_p))
-    #     core.las.LASString_Free(p_d)
-    # 
-    #     return s
-    # 
-    # def set_data(self, data):
-    #     d = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte))
-    # 
-    #     core.las.LASPoint_SetExtraData(self.handle, d, len(data))
-    # 
-    # doc = """Extra byte data for the point. You can attach a variable amount
-    # of extra data to each individual point by setting the
-    # :obj:`liblas.header.Header.dataformat_id` to a valid value, and then
-    # setting the :obj:`liblas.header.Header.data_record_length` to a value that
-    # is larger than the nominal length for that format as noted in the
-    # specification_.
-    # 
-    # Interpreting the data is up to the user, however. Because these are raw
-    # bytes, you can store any additional data that you wish.
-    # 
-    # .. note::
-    #     The data will be clipped to exactly the
-    #     :obj:`liblas.header.Header.data_record_length` when they are actually
-    #     written to the file. If you set data on the point that is larger than
-    #     the difference between the nominal point format data record length and
-    #     the data record length you set in the header, it will be thrown away.
-    # 
-    # """
-    # data = property(get_data, set_data, None, doc)
+    def set_data(self, data):
+        d = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte))
+    
+        core.las.LASPoint_SetData(self.handle, d, len(data))
+    
+    doc = """Raw data for the point. Shoot yourself in the foot if you must!
+    """
+    data = property(get_data, set_data, None, doc)


More information about the Liblas-commits mailing list